From 4b87d37e90b6d2d9562a192540833b599bda5a35 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 3 Aug 2007 13:28:35 -0600 Subject: framebuffer object functions --- src/mesa/state_tracker/st_cb_fbo.c | 343 +++++++++++++++++++++++++++++++++++++ 1 file changed, 343 insertions(+) create mode 100644 src/mesa/state_tracker/st_cb_fbo.c (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c new file mode 100644 index 0000000000..6b9ae88dbe --- /dev/null +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -0,0 +1,343 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +/** + * Framebuffer/renderbuffer functions. + * + * \author Brian Paul + */ + + +#include "main/imports.h" +#include "main/context.h" +#include "main/fbobject.h" +#include "main/framebuffer.h" +#include "main/renderbuffer.h" + +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "st_context.h" +#include "st_cb_fbo.h" +#include "st_cb_teximage.h" + + +/** + * Derived renderbuffer class. Just need to add a pointer to the + * pipe surface. + */ +struct st_renderbuffer +{ + struct gl_renderbuffer Base; + struct pipe_surface *surface; +}; + + +/** + * Cast wrapper. + */ +static INLINE struct st_renderbuffer * +st_renderbuffer(struct gl_renderbuffer *rb) +{ + return (struct st_renderbuffer *) rb; +} + + +struct pipe_format_info +{ + GLuint format; + GLenum base_format; + GLubyte red_bits; + GLubyte green_bits; + GLubyte blue_bits; + GLubyte alpha_bits; + GLubyte luminance_bits; + GLubyte intensity_bits; + GLubyte depth_bits; + GLubyte stencil_bits; + GLubyte size; /**< in bytes */ +}; + + +/* + * XXX temporary here + */ +static const struct pipe_format_info * +pipe_get_format_info(GLuint format) +{ + static const struct pipe_format_info info[] = { + { + PIPE_FORMAT_U_R8_G8_B8_A8, /* format */ + GL_RGBA, /* base_format */ + 4, 4, 4, 4, 0, 0, /* color bits */ + 0, 0, /* depth, stencil */ + 4 /* size in bytes */ + }, + { + PIPE_FORMAT_U_A8_R8_G8_B8, + GL_RGBA, /* base_format */ + 4, 4, 4, 4, 0, 0, /* color bits */ + 0, 0, /* depth, stencil */ + 4 /* size in bytes */ + }, + { + PIPE_FORMAT_U_A1_R5_G5_B5, + GL_RGBA, /* base_format */ + 5, 5, 5, 1, 0, 0, /* color bits */ + 0, 0, /* depth, stencil */ + 2 /* size in bytes */ + }, + { + PIPE_FORMAT_U_R5_G6_B5, + GL_RGBA, /* base_format */ + 5, 6, 5, 0, 0, 0, /* color bits */ + 0, 0, /* depth, stencil */ + 2 /* size in bytes */ + }, + /* XXX lots more */ + { + PIPE_FORMAT_S8_Z24, + GL_DEPTH_STENCIL_EXT, /* base_format */ + 0, 0, 0, 0, 0, 0, /* color bits */ + 24, 8, /* depth, stencil */ + 4 /* size in bytes */ + } + }; + GLuint i; + + for (i = 0; i < sizeof(info) / sizeof(info[0]); i++) { + if (info[i].format == format) + return info + i; + } + return NULL; +} + + +/** + * gl_renderbuffer::AllocStorage() + */ +static GLboolean +st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, + GLenum internalFormat, + GLuint width, GLuint height) +{ + struct pipe_context *pipe = ctx->st->pipe; + struct st_renderbuffer *strb = st_renderbuffer(rb); + const GLuint pipeFormat + = st_choose_pipe_format(pipe, internalFormat, GL_NONE, GL_NONE); + const struct pipe_format_info *info = pipe_get_format_info(pipeFormat); + GLuint cpp, pitch; + + if (!info) + return GL_FALSE; + + strb->Base._ActualFormat = info->base_format; + strb->Base.DataType = GL_UNSIGNED_BYTE; /* XXX fix */ + strb->Base.RedBits = info->red_bits; + strb->Base.GreenBits = info->green_bits; + strb->Base.BlueBits = info->blue_bits; + strb->Base.AlphaBits = info->alpha_bits; + strb->Base.DepthBits = info->depth_bits; + strb->Base.StencilBits = info->stencil_bits; + + cpp = info->size; + + if (!strb->surface) { + strb->surface = pipe->surface_alloc(pipe, pipeFormat); + if (!strb->surface) + return GL_FALSE; + } + + /* free old region */ + if (strb->surface->region) { + pipe->region_release(pipe, &strb->surface->region); + } + + /* Choose a pitch to match hardware requirements: + */ + pitch = ((cpp * width + 63) & ~63) / cpp; /* XXX fix: device-specific */ + + strb->surface->region = pipe->region_alloc(pipe, cpp, pitch, height); + if (!strb->surface->region) + return GL_FALSE; /* out of memory, try s/w buffer? */ + + ASSERT(strb->surface->region->buffer); + + strb->Base.Width = strb->surface->width = width; + strb->Base.Height = strb->surface->height = height; + + return GL_TRUE; +} + + +/** + * gl_renderbuffer::Delete() + */ +static void +st_renderbuffer_delete(struct gl_renderbuffer *rb) +{ + GET_CURRENT_CONTEXT(ctx); + struct pipe_context *pipe = ctx->st->pipe; + struct st_renderbuffer *strb = st_renderbuffer(rb); + ASSERT(strb); + if (strb && strb->surface) { + if (rb->surface->region) { + pipe->region_release(pipe, &strb->surface->region); + } + free(strb->surface); + } + free(strb); +} + + +/** + * gl_renderbuffer::GetPointer() + */ +static void * +null_get_pointer(GLcontext * ctx, struct gl_renderbuffer *rb, + GLint x, GLint y) +{ + /* By returning NULL we force all software rendering to go through + * the span routines. + */ + assert(0); /* Should never get called with softpipe */ + return NULL; +} + + +/** + * Called via ctx->Driver.NewFramebuffer() + */ +static struct gl_framebuffer * +st_new_framebuffer(GLcontext *ctx, GLuint name) +{ + /* XXX not sure we need to subclass gl_framebuffer for pipe */ + return _mesa_new_framebuffer(ctx, name); +} + + +/** + * Called via ctx->Driver.NewRenderbuffer() + */ +static struct gl_renderbuffer * +st_new_renderbuffer(GLcontext *ctx, GLuint name) +{ + struct st_renderbuffer *strb = CALLOC_STRUCT(st_renderbuffer); + if (strb) { + _mesa_init_renderbuffer(&strb->Base, name); + strb->Base.Delete = st_renderbuffer_delete; + strb->Base.AllocStorage = st_renderbuffer_alloc_storage; + strb->Base.GetPointer = null_get_pointer; + return &strb->Base; + } + return NULL; +} + +/** + * Called via ctx->Driver.BindFramebufferEXT(). + */ +static void +st_bind_framebuffer(GLcontext *ctx, GLenum target, + struct gl_framebuffer *fb, struct gl_framebuffer *fbread) +{ + +} + +/** + * Called by ctx->Driver.FramebufferRenderbuffer + */ +static void +st_framebuffer_renderbuffer(GLcontext *ctx, + struct gl_framebuffer *fb, + GLenum attachment, + struct gl_renderbuffer *rb) +{ + /* XXX no need for derivation? */ + _mesa_framebuffer_renderbuffer(ctx, fb, attachment, rb); +} + + +/** + * Called by ctx->Driver.RenderTexture + */ +static void +st_render_texture(GLcontext *ctx, + struct gl_framebuffer *fb, + struct gl_renderbuffer_attachment *att) +{ + struct st_context *st = ctx->st; + struct pipe_framebuffer_state framebuffer; + struct pipe_surface *texsurface; + + texsurface = NULL; /* find the mipmap level, cube face, etc */ + + /* + * XXX basically like this... set the current color (or depth) + * drawing surface to be the given texture renderbuffer. + */ + memset(&framebuffer, 0, sizeof(framebuffer)); + framebuffer.num_cbufs = 1; + framebuffer.cbufs[0] = texsurface; + + if (memcmp(&framebuffer, &st->state.framebuffer, sizeof(framebuffer)) != 0) { + st->state.framebuffer = framebuffer; + st->pipe->set_framebuffer_state( st->pipe, &framebuffer ); + } +} + + +/** + * Called via ctx->Driver.FinishRenderTexture. + */ +static void +st_finish_render_texture(GLcontext *ctx, + struct gl_renderbuffer_attachment *att) +{ + /* restore drawing to normal framebuffer. may be a no-op */ +} + + + +void st_init_cb_fbo( struct st_context *st ) +{ + struct dd_function_table *functions = &st->ctx->Driver; + + functions->NewFramebuffer = st_new_framebuffer; + functions->NewRenderbuffer = st_new_renderbuffer; + functions->BindFramebuffer = st_bind_framebuffer; + functions->FramebufferRenderbuffer = st_framebuffer_renderbuffer; + functions->RenderTexture = st_render_texture; + functions->FinishRenderTexture = st_finish_render_texture; + /* no longer needed by core Mesa, drivers handle resizes... + functions->ResizeBuffers = st_resize_buffers; + */ +} + + +void st_destroy_cb_fbo( struct st_context *st ) +{ +} -- cgit v1.2.3 From 6da9234fd437f97267e7831f034c78b31156d939 Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 6 Aug 2007 20:53:28 +0100 Subject: New st_init_*_functions() to initialize the driver functions table. We need to do these initializations before initializing the Mesa context because context init involves creating texture/program/etc objects. --- src/mesa/state_tracker/st_cb_bufferobjects.c | 18 ++++++++--------- src/mesa/state_tracker/st_cb_bufferobjects.h | 11 +++++------ src/mesa/state_tracker/st_cb_clear.c | 10 +--------- src/mesa/state_tracker/st_cb_clear.h | 5 +++-- src/mesa/state_tracker/st_cb_drawpixels.c | 8 +------- src/mesa/state_tracker/st_cb_drawpixels.h | 4 +--- src/mesa/state_tracker/st_cb_fbo.c | 9 +-------- src/mesa/state_tracker/st_cb_fbo.h | 5 ++--- src/mesa/state_tracker/st_cb_program.c | 29 ++++++++++------------------ src/mesa/state_tracker/st_cb_texture.c | 12 +++--------- src/mesa/state_tracker/st_cb_texture.h | 6 +----- src/mesa/state_tracker/st_context.c | 18 +++++++++++++++++ src/mesa/state_tracker/st_context.h | 7 +++---- src/mesa/state_tracker/st_program.h | 5 +++-- 14 files changed, 60 insertions(+), 87 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c index a667b3e775..d020eb2007 100644 --- a/src/mesa/state_tracker/st_cb_bufferobjects.c +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c @@ -192,15 +192,13 @@ st_bufferobj_unmap(GLcontext *ctx, void -st_init_cb_bufferobjects( struct st_context *st ) +st_init_bufferobject_functions(struct dd_function_table *functions) { - GLcontext *ctx = st->ctx; - - ctx->Driver.NewBufferObject = st_bufferobj_alloc; - ctx->Driver.DeleteBuffer = st_bufferobj_free; - ctx->Driver.BufferData = st_bufferobj_data; - ctx->Driver.BufferSubData = st_bufferobj_subdata; - ctx->Driver.GetBufferSubData = st_bufferobj_get_subdata; - ctx->Driver.MapBuffer = st_bufferobj_map; - ctx->Driver.UnmapBuffer = st_bufferobj_unmap; + functions->NewBufferObject = st_bufferobj_alloc; + functions->DeleteBuffer = st_bufferobj_free; + functions->BufferData = st_bufferobj_data; + functions->BufferSubData = st_bufferobj_subdata; + functions->GetBufferSubData = st_bufferobj_get_subdata; + functions->MapBuffer = st_bufferobj_map; + functions->UnmapBuffer = st_bufferobj_unmap; } diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.h b/src/mesa/state_tracker/st_cb_bufferobjects.h index 2787411c5f..2090a743e0 100644 --- a/src/mesa/state_tracker/st_cb_bufferobjects.h +++ b/src/mesa/state_tracker/st_cb_bufferobjects.h @@ -1,4 +1,4 @@ - /************************************************************************** +/************************************************************************** * * Copyright 2005 Tungsten Graphics, Inc., Cedar Park, Texas. * All Rights Reserved. @@ -43,11 +43,6 @@ struct st_buffer_object }; -/* Hook the bufferobject implementation into mesa: - */ -void st_init_cb_bufferobjects( struct st_context *st ); - - /* Are the obj->Name tests necessary? Unfortunately yes, mesa * allocates a couple of gl_buffer_object structs statically, and the * Name == 0 test is the only way to identify them and avoid casting @@ -63,4 +58,8 @@ st_buffer_object(struct gl_buffer_object *obj) } +extern void +st_init_bufferobject_functions(struct dd_function_table *functions); + + #endif diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index c907b0ed22..0ec7784d84 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -418,15 +418,7 @@ static void st_clear(GLcontext *ctx, GLbitfield mask) } -void st_init_cb_clear( struct st_context *st ) +void st_init_clear_functions(struct dd_function_table *functions) { - struct dd_function_table *functions = &st->ctx->Driver; - functions->Clear = st_clear; } - - -void st_destroy_cb_clear( struct st_context *st ) -{ -} - diff --git a/src/mesa/state_tracker/st_cb_clear.h b/src/mesa/state_tracker/st_cb_clear.h index 32086971b5..c715e56bd5 100644 --- a/src/mesa/state_tracker/st_cb_clear.h +++ b/src/mesa/state_tracker/st_cb_clear.h @@ -29,9 +29,10 @@ #ifndef ST_CB_CLEAR_H #define ST_CB_CLEAR_H -extern void st_init_cb_clear( struct st_context *st ); -extern void st_destroy_cb_clear( struct st_context *st ); +extern void +st_init_clear_functions(struct dd_function_table *functions); + #endif /* ST_CB_CLEAR_H */ diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 13f5c5f3c7..92a4e305d1 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -262,14 +262,8 @@ st_drawpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, } -void st_init_cb_drawpixels( struct st_context *st ) +void st_init_drawpixels_functions(struct dd_function_table *functions) { - struct dd_function_table *functions = &st->ctx->Driver; - functions->DrawPixels = st_drawpixels; } - -void st_destroy_cb_drawpixels( struct st_context *st ) -{ -} diff --git a/src/mesa/state_tracker/st_cb_drawpixels.h b/src/mesa/state_tracker/st_cb_drawpixels.h index 8c36aaa931..71ba487020 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.h +++ b/src/mesa/state_tracker/st_cb_drawpixels.h @@ -30,9 +30,7 @@ #define ST_CB_DRAWPIXELS_H -void st_init_cb_drawpixels( struct st_context *st ); - -void st_destroy_cb_drawpixels( struct st_context *st ); +extern void st_init_drawpixels_functions(struct dd_function_table *functions); #endif /* ST_CB_DRAWPIXELS_H */ diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 6b9ae88dbe..d0205fd635 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -322,10 +322,8 @@ st_finish_render_texture(GLcontext *ctx, -void st_init_cb_fbo( struct st_context *st ) +void st_init_fbo_functions(struct dd_function_table *functions) { - struct dd_function_table *functions = &st->ctx->Driver; - functions->NewFramebuffer = st_new_framebuffer; functions->NewRenderbuffer = st_new_renderbuffer; functions->BindFramebuffer = st_bind_framebuffer; @@ -336,8 +334,3 @@ void st_init_cb_fbo( struct st_context *st ) functions->ResizeBuffers = st_resize_buffers; */ } - - -void st_destroy_cb_fbo( struct st_context *st ) -{ -} diff --git a/src/mesa/state_tracker/st_cb_fbo.h b/src/mesa/state_tracker/st_cb_fbo.h index f4fa66df59..6142434ec6 100644 --- a/src/mesa/state_tracker/st_cb_fbo.h +++ b/src/mesa/state_tracker/st_cb_fbo.h @@ -30,9 +30,8 @@ #define ST_CB_FBO_H -extern void st_init_cb_fbo( struct st_context *st ); - -extern void st_destroy_cb_fbo( struct st_context *st ); +extern void +st_init_fbo_functions(struct dd_function_table *functions); #endif /* ST_CB_FBO_H */ diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c index 6da2aeb2f2..ed47c12066 100644 --- a/src/mesa/state_tracker/st_cb_program.c +++ b/src/mesa/state_tracker/st_cb_program.c @@ -32,7 +32,6 @@ #include "st_context.h" #include "st_program.h" - #include "glheader.h" #include "macros.h" #include "enums.h" @@ -44,6 +43,11 @@ #include "pipe/tgsi/mesa/tgsi_mesa.h" +/* Counter to track program string changes: + */ +static GLuint program_id = 0; + + static void st_bind_program( GLcontext *ctx, GLenum target, struct gl_program *prog ) @@ -70,7 +74,7 @@ static struct gl_program *st_new_program( GLcontext *ctx, case GL_VERTEX_PROGRAM_ARB: { struct st_vertex_program *prog = CALLOC_STRUCT(st_vertex_program); - prog->id = st->program_id++; + prog->id = program_id++; prog->dirty = 1; return _mesa_init_vertex_program( ctx, @@ -84,7 +88,7 @@ static struct gl_program *st_new_program( GLcontext *ctx, { struct st_fragment_program *prog = CALLOC_STRUCT(st_fragment_program); - prog->id = st->program_id++; + prog->id = program_id++; prog->dirty = 1; return _mesa_init_fragment_program( ctx, @@ -124,7 +128,7 @@ static void st_program_string_notify( GLcontext *ctx, if (prog == &ctx->FragmentProgram._Current->Base) st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; - p->id = st->program_id++; + p->id = program_id++; p->param_state = p->Base.Base.Parameters->StateFlags; } else if (target == GL_VERTEX_PROGRAM_ARB) { @@ -133,7 +137,7 @@ static void st_program_string_notify( GLcontext *ctx, if (prog == &ctx->VertexProgram._Current->Base) st->dirty.st |= ST_NEW_VERTEX_PROGRAM; - p->id = st->program_id++; + p->id = program_id++; p->param_state = p->Base.Base.Parameters->StateFlags; /* Also tell tnl about it: @@ -144,15 +148,8 @@ static void st_program_string_notify( GLcontext *ctx, -void st_init_cb_program( struct st_context *st ) +void st_init_program_functions(struct dd_function_table *functions) { - struct dd_function_table *functions = &st->ctx->Driver; - - /* Need these flags: - */ - st->ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; - st->ctx->FragmentProgram._UseTexEnvProgram = GL_TRUE; - #if 0 assert(functions->ProgramStringNotify == _tnl_program_string); #endif @@ -162,9 +159,3 @@ void st_init_cb_program( struct st_context *st ) functions->IsProgramNative = st_is_program_native; functions->ProgramStringNotify = st_program_string_notify; } - - -void st_destroy_cb_program( struct st_context *st ) -{ -} - diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index a0245b553f..5872ae3e74 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -1241,7 +1241,7 @@ do_copy_texsubimage(GLcontext *ctx, get_teximage_source(ctx, internalFormat); if (!stImage->mt || !src) { - DBG("%s fail %p %p\n", __FUNCTION__, stImage->mt, src); + DBG("%s fail %p %p\n", __FUNCTION__, (void *) stImage->mt, (void *) src); return GL_FALSE; } @@ -1726,10 +1726,9 @@ st_tex_unmap_images(struct pipe_context *pipe, -void st_init_cb_texture( struct st_context *st ) +void +st_init_texture_functions(struct dd_function_table *functions) { - struct dd_function_table *functions = &st->ctx->Driver; - functions->ChooseTextureFormat = st_ChooseTextureFormat; functions->TexImage1D = st_TexImage1D; functions->TexImage2D = st_TexImage2D; @@ -1756,8 +1755,3 @@ void st_init_cb_texture( struct st_context *st ) functions->TextureMemCpy = do_memcpy; } - - -void st_destroy_cb_texture( struct st_context *st ) -{ -} diff --git a/src/mesa/state_tracker/st_cb_texture.h b/src/mesa/state_tracker/st_cb_texture.h index c474d16465..c732881c39 100644 --- a/src/mesa/state_tracker/st_cb_texture.h +++ b/src/mesa/state_tracker/st_cb_texture.h @@ -9,11 +9,7 @@ st_finalize_mipmap_tree(GLcontext *ctx, extern void -st_init_cb_texture( struct st_context *st ); - - -extern void -st_destroy_cb_texture( struct st_context *st ); +st_init_texture_functions(struct dd_function_table *functions); #endif /* ST_CB_TEXTURE_H */ diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 2b96286770..0ea06c692d 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -28,6 +28,7 @@ #include "imports.h" #include "st_public.h" #include "st_context.h" +#include "st_cb_bufferobjects.h" #include "st_cb_clear.h" #include "st_cb_drawpixels.h" #include "st_cb_texture.h" @@ -61,10 +62,17 @@ struct st_context *st_create_context( GLcontext *ctx, st_init_atoms( st ); st_init_draw( st ); + /* Need these flags: + */ + st->ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; + st->ctx->FragmentProgram._UseTexEnvProgram = GL_TRUE; + +#if 0 st_init_cb_clear( st ); st_init_cb_program( st ); st_init_cb_drawpixels( st ); st_init_cb_texture( st ); +#endif return st; } @@ -75,11 +83,13 @@ void st_destroy_context( struct st_context *st ) st_destroy_atoms( st ); st_destroy_draw( st ); +#if 0 st_destroy_cb_clear( st ); st_destroy_cb_program( st ); st_destroy_cb_drawpixels( st ); /*st_destroy_cb_teximage( st );*/ st_destroy_cb_texture( st ); +#endif st->pipe->destroy( st->pipe ); FREE( st ); @@ -87,3 +97,11 @@ void st_destroy_context( struct st_context *st ) +void st_init_driver_functions(struct dd_function_table *functions) +{ + st_init_bufferobject_functions(functions); + st_init_clear_functions(functions); + st_init_drawpixels_functions(functions); + st_init_program_functions(functions); + st_init_texture_functions(functions); +} diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index ef3cdb3b09..fe73630c75 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -97,10 +97,6 @@ struct st_context struct st_state_flags dirty; - /* Counter to track program string changes: - */ - GLuint program_id; - GLfloat polygon_offset_scale; /* ?? */ }; @@ -113,4 +109,7 @@ static INLINE struct st_context *st_context(GLcontext *ctx) } +extern void st_init_driver_functions(struct dd_function_table *functions); + + #endif diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index f6d5f6d76c..8dcb2ceb48 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -87,8 +87,9 @@ struct st_vertex_program GLuint param_state; }; -void st_init_cb_program( struct st_context *st ); -void st_destroy_cb_program( struct st_context *st ); + +extern void st_init_program_functions(struct dd_function_table *functions); + static inline struct st_fragment_program * st_fragment_program( struct gl_fragment_program *fp ) -- cgit v1.2.3 From 64da7515009f3551796c90acc74eb0a2ffdb68a0 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 9 Aug 2007 12:27:44 -0600 Subject: checkpoint: no longer using intel_fbo.c --- src/mesa/drivers/dri/intel_winsys/Makefile | 4 +- src/mesa/drivers/dri/intel_winsys/intel_buffers.c | 3 +- src/mesa/drivers/dri/intel_winsys/intel_context.c | 54 ++++++++++++ src/mesa/drivers/dri/intel_winsys/intel_fbo.h | 11 ++- src/mesa/drivers/dri/intel_winsys/intel_screen.c | 28 +++--- src/mesa/drivers/dri/intel_winsys/intel_surface.c | 82 +++++++++++++---- src/mesa/state_tracker/st_cb_fbo.c | 102 ++++++++++++++++++---- src/mesa/state_tracker/st_cb_fbo.h | 8 ++ src/mesa/state_tracker/st_context.c | 2 + 9 files changed, 241 insertions(+), 53 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/drivers/dri/intel_winsys/Makefile b/src/mesa/drivers/dri/intel_winsys/Makefile index 8d3d17e13e..32c2c3bb24 100644 --- a/src/mesa/drivers/dri/intel_winsys/Makefile +++ b/src/mesa/drivers/dri/intel_winsys/Makefile @@ -22,10 +22,10 @@ DRIVER_SOURCES = \ intel_ioctl.c \ intel_screen.c \ intel_surface.c \ - intel_fbo.c \ intel_batchpool.c -UNUSED = intel_depthstencil.c +UNUSED = intel_depthstencil.c \ + intel_fbo.c C_SOURCES = \ $(COMMON_SOURCES) \ diff --git a/src/mesa/drivers/dri/intel_winsys/intel_buffers.c b/src/mesa/drivers/dri/intel_winsys/intel_buffers.c index 9266fb62af..d0139d5b2a 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_buffers.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_buffers.c @@ -96,6 +96,7 @@ intel_intersect_cliprects(drm_clip_rect_t * dst, /** * Return pointer to current color drawing region, or NULL. */ +#if 0 struct pipe_region * intel_drawbuf_region(struct intel_context *intel) { @@ -120,7 +121,7 @@ intel_readbuf_region(struct intel_context *intel) else return NULL; } - +#endif /** * This will be called whenever the currently bound window is moved/resized. diff --git a/src/mesa/drivers/dri/intel_winsys/intel_context.c b/src/mesa/drivers/dri/intel_winsys/intel_context.c index 9defcc1aae..0d83d4efd6 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_context.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_context.c @@ -360,6 +360,58 @@ intelCreateContext(const __GLcontextModes * mesaVis, _vbo_CreateContext(ctx); _tnl_CreateContext(ctx); + /* + * Pipe-related setup + */ + if (!getenv("INTEL_HW")) { + intel->pipe = intel_create_softpipe( intel ); + intel->pipe->surface_alloc = intel_new_surface; + intel->pipe->supported_formats = intel_supported_formats; + } + else { + switch (intel->intelScreen->deviceID) { + case PCI_CHIP_I945_G: + case PCI_CHIP_I945_GM: + case PCI_CHIP_I945_GME: + case PCI_CHIP_G33_G: + case PCI_CHIP_Q33_G: + case PCI_CHIP_Q35_G: + case PCI_CHIP_I915_G: + case PCI_CHIP_I915_GM: + intel->pipe = intel_create_i915simple( intel ); + break; + default: + _mesa_printf("Unknown PCIID %x in %s, using software driver\n", + intel->intelScreen->deviceID, __FUNCTION__); + + intel->pipe = intel_create_softpipe( intel ); + break; + } + } + + st_create_context( &intel->ctx, intel->pipe ); + + + /* TODO: Push this down into the pipe driver: + */ + switch (intel->intelScreen->deviceID) { + case PCI_CHIP_I945_G: + case PCI_CHIP_I945_GM: + case PCI_CHIP_I945_GME: + case PCI_CHIP_G33_G: + case PCI_CHIP_Q33_G: + case PCI_CHIP_Q35_G: + intel->pipe->mipmap_tree_layout = i945_miptree_layout; + break; + case PCI_CHIP_I915_G: + case PCI_CHIP_I915_GM: + case PCI_CHIP_I830_M: + case PCI_CHIP_I855_GM: + case PCI_CHIP_I865_G: + intel->pipe->mipmap_tree_layout = i915_miptree_layout; + default: + assert(0); /*FIX*/ + } /* @@ -397,7 +449,9 @@ intelCreateContext(const __GLcontextModes * mesaVis, intel->last_swap_fence = NULL; intel->first_swap_fence = NULL; +#if 00 intel_fbo_init(intel); +#endif if (intel->ctx.Mesa_DXTn) { _mesa_enable_extension(ctx, "GL_EXT_texture_compression_s3tc"); diff --git a/src/mesa/drivers/dri/intel_winsys/intel_fbo.h b/src/mesa/drivers/dri/intel_winsys/intel_fbo.h index 578e1013c2..2801c7345d 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_fbo.h +++ b/src/mesa/drivers/dri/intel_winsys/intel_fbo.h @@ -73,19 +73,26 @@ struct intel_framebuffer * not pointers because in some circumstances a deleted renderbuffer could * result in a dangling pointer here. */ +#if 0 struct intel_renderbuffer { struct gl_renderbuffer Base; }; +#endif - +#if 0 extern struct intel_renderbuffer *intel_new_renderbuffer_fb(GLuint intFormat); +#endif extern void intel_fbo_init(struct intel_context *intel); extern struct pipe_surface * -intel_new_surface(GLuint intFormat); +intel_new_surface(struct pipe_context *pipe, GLuint pipeFormat); + + +extern const GLuint * +intel_supported_formats(struct pipe_context *pipe, GLuint *numFormats); #endif /* INTEL_FBO_H */ diff --git a/src/mesa/drivers/dri/intel_winsys/intel_screen.c b/src/mesa/drivers/dri/intel_winsys/intel_screen.c index 74cd714cf3..e5f7b36527 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_screen.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_screen.c @@ -302,34 +302,32 @@ intelCreateBuffer(__DRIscreenPrivate * driScrnPriv, /* fake frontbuffer */ /* XXX allocation should only happen in the unusual case it's actually needed */ - struct intel_renderbuffer *irb - = intel_new_renderbuffer_fb(rgbFormat); - _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_FRONT_LEFT, - &irb->Base); + struct gl_renderbuffer *rb + = st_new_renderbuffer_fb(rgbFormat); + _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_FRONT_LEFT, rb); } if (mesaVis->doubleBufferMode) { - struct intel_renderbuffer *irb - = intel_new_renderbuffer_fb(rgbFormat); - _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_BACK_LEFT, - &irb->Base); + struct gl_renderbuffer *rb + = st_new_renderbuffer_fb(rgbFormat); + _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_BACK_LEFT, rb); } if (mesaVis->depthBits == 24 && mesaVis->stencilBits == 8) { /* combined depth/stencil buffer */ - struct intel_renderbuffer *depthStencilRb - = intel_new_renderbuffer_fb(GL_DEPTH24_STENCIL8_EXT); + struct gl_renderbuffer *depthStencilRb + = st_new_renderbuffer_fb(GL_DEPTH24_STENCIL8_EXT); /* note: bind RB to two attachment points */ _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_DEPTH, - &depthStencilRb->Base); + depthStencilRb); _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_STENCIL, - &depthStencilRb->Base); + depthStencilRb); } else if (mesaVis->depthBits == 16) { /* just 16-bit depth buffer, no hw stencil */ - struct intel_renderbuffer *depthRb - = intel_new_renderbuffer_fb(GL_DEPTH_COMPONENT16); - _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_DEPTH, &depthRb->Base); + struct gl_renderbuffer *depthRb + = st_new_renderbuffer_fb(GL_DEPTH_COMPONENT16); + _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_DEPTH, depthRb); } diff --git a/src/mesa/drivers/dri/intel_winsys/intel_surface.c b/src/mesa/drivers/dri/intel_winsys/intel_surface.c index d2e2dabade..20b6bda83f 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_surface.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_surface.c @@ -159,8 +159,43 @@ write_quad_stencil(struct softpipe_surface *sps, } + + +static void +a8r8g8b8_get_tile(struct pipe_surface *ps, + GLuint x, GLuint y, GLuint w, GLuint h, GLfloat *p) +{ + const GLuint *src + = ((const GLuint *) (ps->region->map + ps->offset)) + + y * ps->region->pitch + x; + GLuint i, j; +#if 0 + assert(x + w <= ps->width); + assert(y + h <= ps->height); +#else + /* temp hack */ + if (x + w > ps->width) + w = ps->width - x; + if (y + h > ps->height) + h = ps->height -y; +#endif + for (i = 0; i < h; i++) { + for (j = 0; j < w; j++) { + p[0] = UBYTE_TO_FLOAT((src[j] >> 16) & 0xff); + p[1] = UBYTE_TO_FLOAT((src[j] >> 8) & 0xff); + p[2] = UBYTE_TO_FLOAT((src[j] >> 0) & 0xff); + p[3] = UBYTE_TO_FLOAT((src[j] >> 24) & 0xff); + p += 4; + } + src += ps->region->pitch; + } +} + + + + struct pipe_surface * -intel_new_surface(GLuint intFormat) +intel_new_surface(struct pipe_context *pipe, GLuint pipeFormat) { struct softpipe_surface *sps = CALLOC_STRUCT(softpipe_surface); if (!sps) @@ -168,31 +203,42 @@ intel_new_surface(GLuint intFormat) sps->surface.width = 0; /* set in intel_alloc_renderbuffer_storage() */ sps->surface.height = 0; + sps->surface.refcount = 1; + sps->surface.format = pipeFormat; - if (intFormat == GL_RGBA8) { - sps->surface.format = PIPE_FORMAT_U_A8_R8_G8_B8; + switch (pipeFormat) { + case PIPE_FORMAT_U_A8_R8_G8_B8: sps->read_quad_f_swz = read_quad_f_swz; sps->write_quad_f_swz = write_quad_f_swz; - } - else if (intFormat == GL_RGB5) { - sps->surface.format = PIPE_FORMAT_U_R5_G6_B5; - - } - else if (intFormat == GL_DEPTH_COMPONENT16) { - sps->surface.format = PIPE_FORMAT_U_Z16; - - } - else if (intFormat == GL_DEPTH24_STENCIL8_EXT) { - sps->surface.format = PIPE_FORMAT_S8_Z24; + sps->surface.get_tile = a8r8g8b8_get_tile; + break; + case PIPE_FORMAT_U_R5_G6_B5: + break; + case PIPE_FORMAT_U_Z16: + break; + case PIPE_FORMAT_S8_Z24: sps->read_quad_z = read_quad_z24; sps->write_quad_z = write_quad_z24; sps->read_quad_stencil = read_quad_stencil; sps->write_quad_stencil = write_quad_stencil; - } - else { - /* TBD / unknown */ - + break; } return &sps->surface; } + + + +const GLuint * +intel_supported_formats(struct pipe_context *pipe, GLuint *numFormats) +{ + static const GLuint formats[] = { + PIPE_FORMAT_U_A8_R8_G8_B8, + PIPE_FORMAT_U_R5_G6_B5, + PIPE_FORMAT_S8_Z24, + }; + + *numFormats = sizeof(formats) / sizeof(formats[0]); + return formats; +} + diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index d0205fd635..3cd1fbe851 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -53,7 +53,9 @@ struct st_renderbuffer { struct gl_renderbuffer Base; +#if 0 struct pipe_surface *surface; +#endif }; @@ -93,14 +95,14 @@ pipe_get_format_info(GLuint format) { PIPE_FORMAT_U_R8_G8_B8_A8, /* format */ GL_RGBA, /* base_format */ - 4, 4, 4, 4, 0, 0, /* color bits */ + 8, 8, 8, 8, 0, 0, /* color bits */ 0, 0, /* depth, stencil */ 4 /* size in bytes */ }, { PIPE_FORMAT_U_A8_R8_G8_B8, GL_RGBA, /* base_format */ - 4, 4, 4, 4, 0, 0, /* color bits */ + 8, 8, 8, 8, 0, 0, /* color bits */ 0, 0, /* depth, stencil */ 4 /* size in bytes */ }, @@ -166,29 +168,29 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, cpp = info->size; - if (!strb->surface) { - strb->surface = pipe->surface_alloc(pipe, pipeFormat); - if (!strb->surface) + if (!strb->Base.surface) { + strb->Base.surface = pipe->surface_alloc(pipe, pipeFormat); + if (!strb->Base.surface) return GL_FALSE; } /* free old region */ - if (strb->surface->region) { - pipe->region_release(pipe, &strb->surface->region); + if (strb->Base.surface->region) { + pipe->region_release(pipe, &strb->Base.surface->region); } /* Choose a pitch to match hardware requirements: */ pitch = ((cpp * width + 63) & ~63) / cpp; /* XXX fix: device-specific */ - strb->surface->region = pipe->region_alloc(pipe, cpp, pitch, height); - if (!strb->surface->region) + strb->Base.surface->region = pipe->region_alloc(pipe, cpp, pitch, height); + if (!strb->Base.surface->region) return GL_FALSE; /* out of memory, try s/w buffer? */ - ASSERT(strb->surface->region->buffer); + ASSERT(strb->Base.surface->region->buffer); - strb->Base.Width = strb->surface->width = width; - strb->Base.Height = strb->surface->height = height; + strb->Base.Width = strb->Base.surface->width = width; + strb->Base.Height = strb->Base.surface->height = height; return GL_TRUE; } @@ -204,11 +206,11 @@ st_renderbuffer_delete(struct gl_renderbuffer *rb) struct pipe_context *pipe = ctx->st->pipe; struct st_renderbuffer *strb = st_renderbuffer(rb); ASSERT(strb); - if (strb && strb->surface) { + if (strb && strb->Base.surface) { if (rb->surface->region) { - pipe->region_release(pipe, &strb->surface->region); + pipe->region_release(pipe, &strb->Base.surface->region); } - free(strb->surface); + free(strb->Base.surface); } free(strb); } @@ -257,6 +259,76 @@ st_new_renderbuffer(GLcontext *ctx, GLuint name) return NULL; } + +#if 000 +struct gl_renderbuffer * +st_new_renderbuffer_fb(struct pipe_region *region, GLuint width, GLuint height) +{ + struct st_renderbuffer *strb = CALLOC_STRUCT(st_renderbuffer); + if (!strb) + return; + + _mesa_init_renderbuffer(&strb->Base, name); + strb->Base.Delete = st_renderbuffer_delete; + strb->Base.AllocStorage = st_renderbuffer_alloc_storage; + strb->Base.GetPointer = null_get_pointer; + strb->Base.Width = width; + strb->Base.Heigth = height; + + strb->region = region; + + return &strb->Base; +} + +#else + +struct gl_renderbuffer * +st_new_renderbuffer_fb(GLuint intFormat) +{ + struct st_renderbuffer *irb; + + irb = CALLOC_STRUCT(st_renderbuffer); + if (!irb) { + _mesa_error(NULL, GL_OUT_OF_MEMORY, "creating renderbuffer"); + return NULL; + } + + _mesa_init_renderbuffer(&irb->Base, 0); + irb->Base.ClassID = 0x42; /* XXX temp */ + irb->Base.InternalFormat = intFormat; + + switch (intFormat) { + case GL_RGB5: + case GL_RGBA8: + irb->Base._BaseFormat = GL_RGBA; + break; + case GL_DEPTH_COMPONENT16: + irb->Base._BaseFormat = GL_DEPTH_COMPONENT; + break; + case GL_DEPTH24_STENCIL8_EXT: + irb->Base._BaseFormat = GL_DEPTH_STENCIL_EXT; + break; + default: + _mesa_problem(NULL, + "Unexpected intFormat in st_new_renderbuffer"); + return NULL; + } + + /* st-specific methods */ + irb->Base.Delete = st_renderbuffer_delete; + irb->Base.AllocStorage = st_renderbuffer_alloc_storage; + irb->Base.GetPointer = null_get_pointer; + /* span routines set in alloc_storage function */ + + irb->Base.surface = NULL;/*intel_new_surface(intFormat);*/ + /*irb->Base.surface->rb = irb;*/ + + return &irb->Base; +} +#endif + + + /** * Called via ctx->Driver.BindFramebufferEXT(). */ diff --git a/src/mesa/state_tracker/st_cb_fbo.h b/src/mesa/state_tracker/st_cb_fbo.h index 6142434ec6..7f52ab10d7 100644 --- a/src/mesa/state_tracker/st_cb_fbo.h +++ b/src/mesa/state_tracker/st_cb_fbo.h @@ -30,6 +30,14 @@ #define ST_CB_FBO_H +/* +extern struct gl_renderbuffer * +st_new_renderbuffer_fb(struct pipe_region *region, GLuint width, GLuint height); +*/ +extern struct gl_renderbuffer * +st_new_renderbuffer_fb(GLuint intFormat); + + extern void st_init_fbo_functions(struct dd_function_table *functions); diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 0ea06c692d..9f7916e40e 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -31,6 +31,7 @@ #include "st_cb_bufferobjects.h" #include "st_cb_clear.h" #include "st_cb_drawpixels.h" +#include "st_cb_fbo.h" #include "st_cb_texture.h" #include "st_atom.h" #include "st_draw.h" @@ -102,6 +103,7 @@ void st_init_driver_functions(struct dd_function_table *functions) st_init_bufferobject_functions(functions); st_init_clear_functions(functions); st_init_drawpixels_functions(functions); + st_init_fbo_functions(functions); st_init_program_functions(functions); st_init_texture_functions(functions); } -- cgit v1.2.3 From f5713c7d2e7ba8e1170fd9b1dd95379662ab6117 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 9 Aug 2007 12:59:11 -0600 Subject: Checkpoint intel_renderbuffer removal. Remove surface ptr from gl_renderbuffer. Use st_renderbuffer in most places. More clean-up. --- src/mesa/drivers/dri/intel_winsys/intel_blit.c | 14 +++-- src/mesa/main/mtypes.h | 2 - src/mesa/main/renderbuffer.c | 14 ++++- src/mesa/pipe/p_state.h | 2 - src/mesa/state_tracker/st_atom_framebuffer.c | 27 +++++---- src/mesa/state_tracker/st_cb_clear.c | 35 +++++++---- src/mesa/state_tracker/st_cb_fbo.c | 82 +++++++++----------------- src/mesa/state_tracker/st_cb_fbo.h | 23 ++++++-- 8 files changed, 107 insertions(+), 92 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/drivers/dri/intel_winsys/intel_blit.c b/src/mesa/drivers/dri/intel_winsys/intel_blit.c index 48bbbbeac9..aa4135ed2d 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_blit.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_blit.c @@ -38,6 +38,7 @@ #include "vblank.h" #include "pipe/p_context.h" +#include "state_tracker/st_cb_fbo.h" #define FILE_DEBUG_FLAG DEBUG_BLIT @@ -106,12 +107,17 @@ intelCopyBuffer(__DRIdrawablePrivate * dPriv, const struct pipe_surface *backSurf; const struct pipe_region *backRegion; int srcpitch; + struct st_renderbuffer *strb; /* blit from back color buffer if it exists, else front buffer */ - if (intel_fb->Base.Attachment[BUFFER_BACK_LEFT].Renderbuffer) - backSurf = intel_fb->Base.Attachment[BUFFER_BACK_LEFT].Renderbuffer->surface; - else - backSurf = intel_fb->Base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer->surface; + strb = st_renderbuffer(intel_fb->Base.Attachment[BUFFER_BACK_LEFT].Renderbuffer); + if (strb) { + backSurf = strb->surface; + } + else { + strb = st_renderbuffer(intel_fb->Base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer); + backSurf = strb->surface; + } backRegion = backSurf->region; srcpitch = backRegion->pitch; diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index d70df5d945..0a64e0c58c 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -2269,8 +2269,6 @@ struct gl_renderbuffer GLubyte StencilBits; GLvoid *Data; /**< This may not be used by some kinds of RBs */ - struct pipe_surface *surface; - /* Used to wrap one renderbuffer around another: */ struct gl_renderbuffer *Wrapped; diff --git a/src/mesa/main/renderbuffer.c b/src/mesa/main/renderbuffer.c index d89704196a..e7aeea8e3e 100644 --- a/src/mesa/main/renderbuffer.c +++ b/src/mesa/main/renderbuffer.c @@ -1067,9 +1067,11 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb, rb->PutMonoValues = put_mono_values_ubyte; rb->StencilBits = 8 * sizeof(GLubyte); pixelSize = sizeof(GLubyte); +#if 0 if (!rb->surface) rb->surface = (struct pipe_surface *) pipe->surface_alloc(pipe, PIPE_FORMAT_U_S8); +#endif break; case GL_STENCIL_INDEX16_EXT: rb->_ActualFormat = GL_STENCIL_INDEX16_EXT; @@ -1100,9 +1102,11 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb, rb->PutValues = put_values_ushort; rb->PutMonoValues = put_mono_values_ushort; rb->DepthBits = 8 * sizeof(GLushort); +#if 0 if (!rb->surface) rb->surface = (struct pipe_surface *) pipe->surface_alloc(pipe, PIPE_FORMAT_U_Z16); +#endif pixelSize = sizeof(GLushort); break; case GL_DEPTH_COMPONENT24: @@ -1125,9 +1129,11 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb, rb->_ActualFormat = GL_DEPTH_COMPONENT32; rb->DepthBits = 32; } +#if 0 if (!rb->surface) rb->surface = (struct pipe_surface *) pipe->surface_alloc(pipe, PIPE_FORMAT_U_Z32); +#endif pixelSize = sizeof(GLuint); break; case GL_DEPTH_STENCIL_EXT: @@ -1145,9 +1151,11 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb, rb->PutMonoValues = put_mono_values_uint; rb->DepthBits = 24; rb->StencilBits = 8; +#if 0 if (!rb->surface) rb->surface = (struct pipe_surface *) pipe->surface_alloc(pipe, PIPE_FORMAT_S8_Z24); +#endif pixelSize = sizeof(GLuint); break; case GL_COLOR_INDEX8_EXT: @@ -1210,7 +1218,7 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb, ASSERT(rb->PutMonoValues); /* free old buffer storage */ - if (rb->surface) { + if (0/**rb->surface**/) { /* pipe_surface/region */ } else if (rb->Data) { @@ -1221,8 +1229,9 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb, if (width > 0 && height > 0) { /* allocate new buffer storage */ - if (rb->surface) { + if (0/**rb->surface**/) { /* pipe_surface/region */ +#if 0 if (rb->surface->region) { pipe->region_unmap(pipe, rb->surface->region); pipe->region_release(pipe, &rb->surface->region); @@ -1231,6 +1240,7 @@ _mesa_soft_renderbuffer_storage(GLcontext *ctx, struct gl_renderbuffer *rb, /* XXX probably don't want to really map here */ pipe->region_map(pipe, rb->surface->region); rb->Data = rb->surface->region->map; +#endif } else { /* legacy renderbuffer (this will go away) */ diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index 2dcd2db868..ee29e38a48 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -260,8 +260,6 @@ struct pipe_surface GLuint offset; /**< offset from start of region, in bytes */ GLint refcount; - void *rb; /**< Ptr back to renderbuffer (temporary?) */ - /** get block/tile of pixels from surface */ void (*get_tile)(struct pipe_surface *ps, GLuint x, GLuint y, GLuint w, GLuint h, GLfloat *p); diff --git a/src/mesa/state_tracker/st_atom_framebuffer.c b/src/mesa/state_tracker/st_atom_framebuffer.c index 7edd044ad9..f054eb8f21 100644 --- a/src/mesa/state_tracker/st_atom_framebuffer.c +++ b/src/mesa/state_tracker/st_atom_framebuffer.c @@ -33,6 +33,7 @@ #include "st_context.h" #include "st_atom.h" +#include "st_cb_fbo.h" #include "pipe/p_context.h" @@ -44,7 +45,7 @@ static void update_framebuffer_state( struct st_context *st ) { struct pipe_framebuffer_state framebuffer; - struct gl_renderbuffer *rb; + struct st_renderbuffer *strb; GLuint i; memset(&framebuffer, 0, sizeof(framebuffer)); @@ -54,21 +55,23 @@ update_framebuffer_state( struct st_context *st ) */ framebuffer.num_cbufs = st->ctx->DrawBuffer->_NumColorDrawBuffers[0]; for (i = 0; i < framebuffer.num_cbufs; i++) { - rb = st->ctx->DrawBuffer->_ColorDrawBuffers[0][i]; - assert(rb->surface); - framebuffer.cbufs[i] = rb->surface; + strb = st_renderbuffer(st->ctx->DrawBuffer->_ColorDrawBuffers[0][i]); + assert(strb->surface); + framebuffer.cbufs[i] = strb->surface; } - rb = st->ctx->DrawBuffer->_DepthBuffer; - if (rb) { - assert(rb->Wrapped->surface); - framebuffer.zbuf = rb->Wrapped->surface; + strb = st_renderbuffer(st->ctx->DrawBuffer->_DepthBuffer); + if (strb) { + strb = st_renderbuffer(strb->Base.Wrapped); + assert(strb->surface); + framebuffer.zbuf = strb->surface; } - rb = st->ctx->DrawBuffer->_StencilBuffer; - if (rb) { - assert(rb->Wrapped->surface); - framebuffer.sbuf = rb->Wrapped->surface; + strb = st_renderbuffer(st->ctx->DrawBuffer->_StencilBuffer); + if (strb) { + strb = st_renderbuffer(strb->Base.Wrapped); + assert(strb->surface); + framebuffer.sbuf = strb->surface; } if (memcmp(&framebuffer, &st->state.framebuffer, sizeof(framebuffer)) != 0) { diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index d862f7ba46..4da3a2500d 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -37,6 +37,7 @@ #include "st_atom.h" #include "st_context.h" #include "st_cb_clear.h" +#include "st_cb_fbo.h" #include "st_program.h" #include "st_public.h" #include "pipe/p_context.h" @@ -288,6 +289,8 @@ clear_with_quad(GLcontext *ctx, GLuint x0, GLuint y0, static void clear_color_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { + struct st_renderbuffer *strb = st_renderbuffer(rb); + if (ctx->Color.ColorMask[0] && ctx->Color.ColorMask[1] && ctx->Color.ColorMask[2] && @@ -296,8 +299,8 @@ clear_color_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { /* clear whole buffer w/out masking */ GLuint clearValue - = color_value(rb->surface->format, ctx->Color.ClearColor); - ctx->st->pipe->clear(ctx->st->pipe, rb->surface, clearValue); + = color_value(strb->surface->format, ctx->Color.ClearColor); + ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); } else { /* masking or scissoring */ @@ -314,14 +317,16 @@ clear_color_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) static void clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { + struct st_renderbuffer *strb = st_renderbuffer(rb); + if (!ctx->Scissor.Enabled) { /* clear whole buffer w/out masking */ GLuint clearValue - = color_value(rb->surface->format, ctx->Accum.ClearColor); + = color_value(strb->surface->format, ctx->Accum.ClearColor); /* Note that clearValue is 32 bits but the accum buffer will * typically be 64bpp... */ - ctx->st->pipe->clear(ctx->st->pipe, rb->surface, clearValue); + ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); } else { /* scissoring */ @@ -339,11 +344,13 @@ clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) static void clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { + struct st_renderbuffer *strb = st_renderbuffer(rb); + if (!ctx->Scissor.Enabled && - !is_depth_stencil_format(rb->surface->format)) { + !is_depth_stencil_format(strb->surface->format)) { /* clear whole depth buffer w/out masking */ - GLuint clearValue = depth_value(rb->surface->format, ctx->Depth.Clear); - ctx->st->pipe->clear(ctx->st->pipe, rb->surface, clearValue); + GLuint clearValue = depth_value(strb->surface->format, ctx->Depth.Clear); + ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); } else { /* masking or scissoring or combined z/stencil buffer */ @@ -360,14 +367,15 @@ clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) static void clear_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { + struct st_renderbuffer *strb = st_renderbuffer(rb); const GLuint stencilMax = (1 << rb->StencilBits) - 1; GLboolean maskStencil = ctx->Stencil.WriteMask[0] != stencilMax; if (!maskStencil && !ctx->Scissor.Enabled && - !is_depth_stencil_format(rb->surface->format)) { + !is_depth_stencil_format(strb->surface->format)) { /* clear whole stencil buffer w/out masking */ GLuint clearValue = ctx->Stencil.Clear; - ctx->st->pipe->clear(ctx->st->pipe, rb->surface, clearValue); + ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); } else { /* masking or scissoring */ @@ -384,16 +392,17 @@ clear_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) static void clear_depth_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { + struct st_renderbuffer *strb = st_renderbuffer(rb); const GLuint stencilMax = 1 << rb->StencilBits; GLboolean maskStencil = ctx->Stencil.WriteMask[0] != stencilMax; - assert(is_depth_stencil_format(rb->surface->format)); + assert(is_depth_stencil_format(strb->surface->format)); if (!maskStencil && !ctx->Scissor.Enabled) { /* clear whole buffer w/out masking */ - GLuint clearValue = depth_value(rb->surface->format, ctx->Depth.Clear); + GLuint clearValue = depth_value(strb->surface->format, ctx->Depth.Clear); - switch (rb->surface->format) { + switch (strb->surface->format) { case PIPE_FORMAT_S8_Z24: clearValue |= ctx->Stencil.Clear << 24; break; @@ -406,7 +415,7 @@ clear_depth_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) assert(0); } - ctx->st->pipe->clear(ctx->st->pipe, rb->surface, clearValue); + ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); } else { /* masking or scissoring */ diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 3cd1fbe851..02bdb5aba5 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -46,29 +46,6 @@ #include "st_cb_teximage.h" -/** - * Derived renderbuffer class. Just need to add a pointer to the - * pipe surface. - */ -struct st_renderbuffer -{ - struct gl_renderbuffer Base; -#if 0 - struct pipe_surface *surface; -#endif -}; - - -/** - * Cast wrapper. - */ -static INLINE struct st_renderbuffer * -st_renderbuffer(struct gl_renderbuffer *rb) -{ - return (struct st_renderbuffer *) rb; -} - - struct pipe_format_info { GLuint format; @@ -168,29 +145,29 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, cpp = info->size; - if (!strb->Base.surface) { - strb->Base.surface = pipe->surface_alloc(pipe, pipeFormat); - if (!strb->Base.surface) + if (!strb->surface) { + strb->surface = pipe->surface_alloc(pipe, pipeFormat); + if (!strb->surface) return GL_FALSE; } /* free old region */ - if (strb->Base.surface->region) { - pipe->region_release(pipe, &strb->Base.surface->region); + if (strb->surface->region) { + pipe->region_release(pipe, &strb->surface->region); } /* Choose a pitch to match hardware requirements: */ pitch = ((cpp * width + 63) & ~63) / cpp; /* XXX fix: device-specific */ - strb->Base.surface->region = pipe->region_alloc(pipe, cpp, pitch, height); - if (!strb->Base.surface->region) + strb->surface->region = pipe->region_alloc(pipe, cpp, pitch, height); + if (!strb->surface->region) return GL_FALSE; /* out of memory, try s/w buffer? */ - ASSERT(strb->Base.surface->region->buffer); + ASSERT(strb->surface->region->buffer); - strb->Base.Width = strb->Base.surface->width = width; - strb->Base.Height = strb->Base.surface->height = height; + strb->Base.Width = strb->surface->width = width; + strb->Base.Height = strb->surface->height = height; return GL_TRUE; } @@ -206,11 +183,11 @@ st_renderbuffer_delete(struct gl_renderbuffer *rb) struct pipe_context *pipe = ctx->st->pipe; struct st_renderbuffer *strb = st_renderbuffer(rb); ASSERT(strb); - if (strb && strb->Base.surface) { - if (rb->surface->region) { - pipe->region_release(pipe, &strb->Base.surface->region); + if (strb && strb->surface) { + if (strb->surface->region) { + pipe->region_release(pipe, &strb->surface->region); } - free(strb->Base.surface); + free(strb->surface); } free(strb); } @@ -285,28 +262,28 @@ st_new_renderbuffer_fb(struct pipe_region *region, GLuint width, GLuint height) struct gl_renderbuffer * st_new_renderbuffer_fb(GLuint intFormat) { - struct st_renderbuffer *irb; + struct st_renderbuffer *strb; - irb = CALLOC_STRUCT(st_renderbuffer); - if (!irb) { + strb = CALLOC_STRUCT(st_renderbuffer); + if (!strb) { _mesa_error(NULL, GL_OUT_OF_MEMORY, "creating renderbuffer"); return NULL; } - _mesa_init_renderbuffer(&irb->Base, 0); - irb->Base.ClassID = 0x42; /* XXX temp */ - irb->Base.InternalFormat = intFormat; + _mesa_init_renderbuffer(&strb->Base, 0); + strb->Base.ClassID = 0x42; /* XXX temp */ + strb->Base.InternalFormat = intFormat; switch (intFormat) { case GL_RGB5: case GL_RGBA8: - irb->Base._BaseFormat = GL_RGBA; + strb->Base._BaseFormat = GL_RGBA; break; case GL_DEPTH_COMPONENT16: - irb->Base._BaseFormat = GL_DEPTH_COMPONENT; + strb->Base._BaseFormat = GL_DEPTH_COMPONENT; break; case GL_DEPTH24_STENCIL8_EXT: - irb->Base._BaseFormat = GL_DEPTH_STENCIL_EXT; + strb->Base._BaseFormat = GL_DEPTH_STENCIL_EXT; break; default: _mesa_problem(NULL, @@ -315,15 +292,14 @@ st_new_renderbuffer_fb(GLuint intFormat) } /* st-specific methods */ - irb->Base.Delete = st_renderbuffer_delete; - irb->Base.AllocStorage = st_renderbuffer_alloc_storage; - irb->Base.GetPointer = null_get_pointer; - /* span routines set in alloc_storage function */ + strb->Base.Delete = st_renderbuffer_delete; + strb->Base.AllocStorage = st_renderbuffer_alloc_storage; + strb->Base.GetPointer = null_get_pointer; - irb->Base.surface = NULL;/*intel_new_surface(intFormat);*/ - /*irb->Base.surface->rb = irb;*/ + /* surface is allocate in alloc_renderbuffer_storage() */ + strb->surface = NULL; - return &irb->Base; + return &strb->Base; } #endif diff --git a/src/mesa/state_tracker/st_cb_fbo.h b/src/mesa/state_tracker/st_cb_fbo.h index 7f52ab10d7..b2e7ba810c 100644 --- a/src/mesa/state_tracker/st_cb_fbo.h +++ b/src/mesa/state_tracker/st_cb_fbo.h @@ -30,10 +30,25 @@ #define ST_CB_FBO_H -/* -extern struct gl_renderbuffer * -st_new_renderbuffer_fb(struct pipe_region *region, GLuint width, GLuint height); -*/ + +/** + * Derived renderbuffer class. Just need to add a pointer to the + * pipe surface. + */ +struct st_renderbuffer +{ + struct gl_renderbuffer Base; + struct pipe_surface *surface; +}; + + +static INLINE struct st_renderbuffer * +st_renderbuffer(struct gl_renderbuffer *rb) +{ + return (struct st_renderbuffer *) rb; +} + + extern struct gl_renderbuffer * st_new_renderbuffer_fb(GLuint intFormat); -- cgit v1.2.3 From 3c07bbb1982da5629685f569285529f02b35e48c Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 9 Aug 2007 15:39:54 -0600 Subject: assertions --- src/mesa/state_tracker/st_cb_fbo.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 02bdb5aba5..15816bee9e 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -131,6 +131,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, const struct pipe_format_info *info = pipe_get_format_info(pipeFormat); GLuint cpp, pitch; + assert(info); if (!info) return GL_FALSE; @@ -147,6 +148,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, if (!strb->surface) { strb->surface = pipe->surface_alloc(pipe, pipeFormat); + assert(strb->surface); if (!strb->surface) return GL_FALSE; } -- cgit v1.2.3 From 6883930f61c67924789f2c7cbc274627407cc784 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 9 Aug 2007 22:56:21 +0100 Subject: init strb->Base.DataType appropriately, clean-ups --- src/mesa/state_tracker/st_cb_fbo.c | 14 ++++++++++++-- src/mesa/state_tracker/st_cb_fbo.h | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 15816bee9e..67e239fd6d 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -135,8 +135,15 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, if (!info) return GL_FALSE; + switch (pipeFormat) { + case PIPE_FORMAT_S8_Z24: + strb->Base.DataType = GL_UNSIGNED_INT; + break; + default: + strb->Base.DataType = GL_UNSIGNED_BYTE; /* XXX fix */ + } + strb->Base._ActualFormat = info->base_format; - strb->Base.DataType = GL_UNSIGNED_BYTE; /* XXX fix */ strb->Base.RedBits = info->red_bits; strb->Base.GreenBits = info->green_bits; strb->Base.BlueBits = info->blue_bits; @@ -205,7 +212,9 @@ null_get_pointer(GLcontext * ctx, struct gl_renderbuffer *rb, /* By returning NULL we force all software rendering to go through * the span routines. */ +#if 0 assert(0); /* Should never get called with softpipe */ +#endif return NULL; } @@ -262,7 +271,7 @@ st_new_renderbuffer_fb(struct pipe_region *region, GLuint width, GLuint height) #else struct gl_renderbuffer * -st_new_renderbuffer_fb(GLuint intFormat) +st_new_renderbuffer_fb(GLenum intFormat) { struct st_renderbuffer *strb; @@ -282,6 +291,7 @@ st_new_renderbuffer_fb(GLuint intFormat) strb->Base._BaseFormat = GL_RGBA; break; case GL_DEPTH_COMPONENT16: + case GL_DEPTH_COMPONENT32: strb->Base._BaseFormat = GL_DEPTH_COMPONENT; break; case GL_DEPTH24_STENCIL8_EXT: diff --git a/src/mesa/state_tracker/st_cb_fbo.h b/src/mesa/state_tracker/st_cb_fbo.h index b2e7ba810c..2280441db5 100644 --- a/src/mesa/state_tracker/st_cb_fbo.h +++ b/src/mesa/state_tracker/st_cb_fbo.h @@ -50,7 +50,7 @@ st_renderbuffer(struct gl_renderbuffer *rb) extern struct gl_renderbuffer * -st_new_renderbuffer_fb(GLuint intFormat); +st_new_renderbuffer_fb(GLenum intFormat); extern void -- cgit v1.2.3 From a25dd4d407a9ed797d4b9841c62f33efdfa07847 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 10 Aug 2007 08:34:18 +0100 Subject: code movement --- src/mesa/state_tracker/st_cb_fbo.c | 71 +--------- src/mesa/state_tracker/st_cb_teximage.c | 238 ++++++++++++++++++++++++++------ src/mesa/state_tracker/st_cb_teximage.h | 26 +++- src/mesa/state_tracker/st_cb_texture.c | 150 +------------------- 4 files changed, 219 insertions(+), 266 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 67e239fd6d..8443c9ea1b 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -46,75 +46,6 @@ #include "st_cb_teximage.h" -struct pipe_format_info -{ - GLuint format; - GLenum base_format; - GLubyte red_bits; - GLubyte green_bits; - GLubyte blue_bits; - GLubyte alpha_bits; - GLubyte luminance_bits; - GLubyte intensity_bits; - GLubyte depth_bits; - GLubyte stencil_bits; - GLubyte size; /**< in bytes */ -}; - - -/* - * XXX temporary here - */ -static const struct pipe_format_info * -pipe_get_format_info(GLuint format) -{ - static const struct pipe_format_info info[] = { - { - PIPE_FORMAT_U_R8_G8_B8_A8, /* format */ - GL_RGBA, /* base_format */ - 8, 8, 8, 8, 0, 0, /* color bits */ - 0, 0, /* depth, stencil */ - 4 /* size in bytes */ - }, - { - PIPE_FORMAT_U_A8_R8_G8_B8, - GL_RGBA, /* base_format */ - 8, 8, 8, 8, 0, 0, /* color bits */ - 0, 0, /* depth, stencil */ - 4 /* size in bytes */ - }, - { - PIPE_FORMAT_U_A1_R5_G5_B5, - GL_RGBA, /* base_format */ - 5, 5, 5, 1, 0, 0, /* color bits */ - 0, 0, /* depth, stencil */ - 2 /* size in bytes */ - }, - { - PIPE_FORMAT_U_R5_G6_B5, - GL_RGBA, /* base_format */ - 5, 6, 5, 0, 0, 0, /* color bits */ - 0, 0, /* depth, stencil */ - 2 /* size in bytes */ - }, - /* XXX lots more */ - { - PIPE_FORMAT_S8_Z24, - GL_DEPTH_STENCIL_EXT, /* base_format */ - 0, 0, 0, 0, 0, 0, /* color bits */ - 24, 8, /* depth, stencil */ - 4 /* size in bytes */ - } - }; - GLuint i; - - for (i = 0; i < sizeof(info) / sizeof(info[0]); i++) { - if (info[i].format == format) - return info + i; - } - return NULL; -} - /** * gl_renderbuffer::AllocStorage() @@ -128,7 +59,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, struct st_renderbuffer *strb = st_renderbuffer(rb); const GLuint pipeFormat = st_choose_pipe_format(pipe, internalFormat, GL_NONE, GL_NONE); - const struct pipe_format_info *info = pipe_get_format_info(pipeFormat); + const struct pipe_format_info *info = st_get_format_info(pipeFormat); GLuint cpp, pitch; assert(info); diff --git a/src/mesa/state_tracker/st_cb_teximage.c b/src/mesa/state_tracker/st_cb_teximage.c index 39c9367695..c54602db5d 100644 --- a/src/mesa/state_tracker/st_cb_teximage.c +++ b/src/mesa/state_tracker/st_cb_teximage.c @@ -34,6 +34,8 @@ #include "main/imports.h" #include "main/context.h" #include "main/texstore.h" +#include "main/texformat.h" +#include "main/enums.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" @@ -42,6 +44,60 @@ +/* + * XXX temporary here + */ +const struct pipe_format_info * +st_get_format_info(GLuint format) +{ + static const struct pipe_format_info info[] = { + { + PIPE_FORMAT_U_R8_G8_B8_A8, /* format */ + GL_RGBA, /* base_format */ + 8, 8, 8, 8, 0, 0, /* color bits */ + 0, 0, /* depth, stencil */ + 4 /* size in bytes */ + }, + { + PIPE_FORMAT_U_A8_R8_G8_B8, + GL_RGBA, /* base_format */ + 8, 8, 8, 8, 0, 0, /* color bits */ + 0, 0, /* depth, stencil */ + 4 /* size in bytes */ + }, + { + PIPE_FORMAT_U_A1_R5_G5_B5, + GL_RGBA, /* base_format */ + 5, 5, 5, 1, 0, 0, /* color bits */ + 0, 0, /* depth, stencil */ + 2 /* size in bytes */ + }, + { + PIPE_FORMAT_U_R5_G6_B5, + GL_RGBA, /* base_format */ + 5, 6, 5, 0, 0, 0, /* color bits */ + 0, 0, /* depth, stencil */ + 2 /* size in bytes */ + }, + /* XXX lots more */ + { + PIPE_FORMAT_S8_Z24, + GL_DEPTH_STENCIL_EXT, /* base_format */ + 0, 0, 0, 0, 0, 0, /* color bits */ + 24, 8, /* depth, stencil */ + 4 /* size in bytes */ + } + }; + GLuint i; + + for (i = 0; i < sizeof(info) / sizeof(info[0]); i++) { + if (info[i].format == format) + return info + i; + } + return NULL; +} + + /** * Search list of formats for first RGBA format. @@ -285,58 +341,152 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat, -static void -st_teximage2d(GLcontext *ctx, GLenum target, GLint level, - GLint internalFormat, - GLint width, GLint height, GLint border, - GLenum format, GLenum type, const void *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage) -{ - /* probably nothing here: use core Mesa TexImage2D fallback to - * save teximage in main memory. - * Later, when we have a complete texobj and are ready to render, - * create the pipe texture object / mipmap-tree. - */ - - _mesa_store_teximage2d(ctx, target, level, internalFormat, - width, height, border, format, type, pixels, - packing, texObj, texImage); -} - - -static void -st_texsubimage2d(GLcontext *ctx, GLenum target, GLint level, - GLint xoffset, GLint yoffset, - GLsizei width, GLsizei height, - GLenum format, GLenum type, - const GLvoid *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage) +/* It works out that this function is fine for all the supported + * hardware. However, there is still a need to map the formats onto + * hardware descriptors. + */ +/* Note that the i915 can actually support many more formats than + * these if we take the step of simply swizzling the colors + * immediately after sampling... + */ +const struct gl_texture_format * +st_ChooseTextureFormat(GLcontext * ctx, GLint internalFormat, + GLenum format, GLenum type) { #if 0 - struct pipe_mipmap_tree *mt = texObj->DriverData; + struct intel_context *intel = intel_context(ctx); + const GLboolean do32bpt = (intel->intelScreen->front.cpp == 4); +#else + const GLboolean do32bpt = 1; #endif - /* 1. find the region which stores this texture object. - * 2. convert texels to pipe format if needed. - * 3. replace texdata in the texture region. - */ -} + switch (internalFormat) { + case 4: + case GL_RGBA: + case GL_COMPRESSED_RGBA: + if (format == GL_BGRA) { + if (type == GL_UNSIGNED_BYTE || type == GL_UNSIGNED_INT_8_8_8_8_REV) { + return &_mesa_texformat_argb8888; + } + else if (type == GL_UNSIGNED_SHORT_4_4_4_4_REV) { + return &_mesa_texformat_argb4444; + } + else if (type == GL_UNSIGNED_SHORT_1_5_5_5_REV) { + return &_mesa_texformat_argb1555; + } + } + return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444; + case 3: + case GL_RGB: + case GL_COMPRESSED_RGB: + if (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) { + return &_mesa_texformat_rgb565; + } + return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_rgb565; + case GL_RGBA8: + case GL_RGB10_A2: + case GL_RGBA12: + case GL_RGBA16: + return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444; -void st_init_cb_teximage( struct st_context *st ) -{ - struct dd_function_table *functions = &st->ctx->Driver; + case GL_RGBA4: + case GL_RGBA2: + return &_mesa_texformat_argb4444; - functions->TexImage2D = st_teximage2d; - functions->TexSubImage2D = st_texsubimage2d; -} + case GL_RGB5_A1: + return &_mesa_texformat_argb1555; + case GL_RGB8: + case GL_RGB10: + case GL_RGB12: + case GL_RGB16: + return &_mesa_texformat_argb8888; -void st_destroy_cb_teximage( struct st_context *st ) -{ + case GL_RGB5: + case GL_RGB4: + case GL_R3_G3_B2: + return &_mesa_texformat_rgb565; + + case GL_ALPHA: + case GL_ALPHA4: + case GL_ALPHA8: + case GL_ALPHA12: + case GL_ALPHA16: + case GL_COMPRESSED_ALPHA: + return &_mesa_texformat_a8; + + case 1: + case GL_LUMINANCE: + case GL_LUMINANCE4: + case GL_LUMINANCE8: + case GL_LUMINANCE12: + case GL_LUMINANCE16: + case GL_COMPRESSED_LUMINANCE: + return &_mesa_texformat_l8; + + case 2: + case GL_LUMINANCE_ALPHA: + case GL_LUMINANCE4_ALPHA4: + case GL_LUMINANCE6_ALPHA2: + case GL_LUMINANCE8_ALPHA8: + case GL_LUMINANCE12_ALPHA4: + case GL_LUMINANCE12_ALPHA12: + case GL_LUMINANCE16_ALPHA16: + case GL_COMPRESSED_LUMINANCE_ALPHA: + return &_mesa_texformat_al88; + + case GL_INTENSITY: + case GL_INTENSITY4: + case GL_INTENSITY8: + case GL_INTENSITY12: + case GL_INTENSITY16: + case GL_COMPRESSED_INTENSITY: + return &_mesa_texformat_i8; + + case GL_YCBCR_MESA: + if (type == GL_UNSIGNED_SHORT_8_8_MESA || type == GL_UNSIGNED_BYTE) + return &_mesa_texformat_ycbcr; + else + return &_mesa_texformat_ycbcr_rev; + + case GL_COMPRESSED_RGB_FXT1_3DFX: + return &_mesa_texformat_rgb_fxt1; + case GL_COMPRESSED_RGBA_FXT1_3DFX: + return &_mesa_texformat_rgba_fxt1; + + case GL_RGB_S3TC: + case GL_RGB4_S3TC: + case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: + return &_mesa_texformat_rgb_dxt1; + + case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: + return &_mesa_texformat_rgba_dxt1; + + case GL_RGBA_S3TC: + case GL_RGBA4_S3TC: + case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: + return &_mesa_texformat_rgba_dxt3; + + case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: + return &_mesa_texformat_rgba_dxt5; + + case GL_DEPTH_COMPONENT: + case GL_DEPTH_COMPONENT16: + case GL_DEPTH_COMPONENT24: + case GL_DEPTH_COMPONENT32: + return &_mesa_texformat_z16; + + case GL_DEPTH_STENCIL_EXT: + case GL_DEPTH24_STENCIL8_EXT: + return &_mesa_texformat_z24_s8; + + default: + fprintf(stderr, "unexpected texture format %s in %s\n", + _mesa_lookup_enum_by_nr(internalFormat), __FUNCTION__); + return NULL; + } + + return NULL; /* never get here */ } diff --git a/src/mesa/state_tracker/st_cb_teximage.h b/src/mesa/state_tracker/st_cb_teximage.h index 462128a844..452ae59d6d 100644 --- a/src/mesa/state_tracker/st_cb_teximage.h +++ b/src/mesa/state_tracker/st_cb_teximage.h @@ -30,14 +30,34 @@ #define ST_CB_TEXIMAGE_H +struct pipe_format_info +{ + GLuint format; + GLenum base_format; + GLubyte red_bits; + GLubyte green_bits; + GLubyte blue_bits; + GLubyte alpha_bits; + GLubyte luminance_bits; + GLubyte intensity_bits; + GLubyte depth_bits; + GLubyte stencil_bits; + GLubyte size; /**< in bytes */ +}; + + +extern const struct pipe_format_info * +st_get_format_info(GLuint format); + + extern GLuint st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat, GLenum format, GLenum type); -extern void st_init_cb_teximage( struct st_context *st ); - -extern void st_destroy_cb_teximage( struct st_context *st ); +extern const struct gl_texture_format * +st_ChooseTextureFormat(GLcontext * ctx, GLint internalFormat, + GLenum format, GLenum type); #endif /* ST_CB_TEXIMAGE_H */ diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 6b361b0a4b..6850d602e2 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -38,6 +38,7 @@ #include "state_tracker/st_context.h" #include "state_tracker/st_cb_texture.h" +#include "state_tracker/st_cb_teximage.h" #include "state_tracker/st_mipmap_tree.h" #include "pipe/p_context.h" @@ -152,155 +153,6 @@ compressed_num_bytes(GLuint mesaFormat) } -/* It works out that this function is fine for all the supported - * hardware. However, there is still a need to map the formats onto - * hardware descriptors. - */ -/* Note that the i915 can actually support many more formats than - * these if we take the step of simply swizzling the colors - * immediately after sampling... - */ -static const struct gl_texture_format * -st_ChooseTextureFormat(GLcontext * ctx, GLint internalFormat, - GLenum format, GLenum type) -{ -#if 0 - struct intel_context *intel = intel_context(ctx); - const GLboolean do32bpt = (intel->intelScreen->front.cpp == 4); -#else - const GLboolean do32bpt = 1; -#endif - - switch (internalFormat) { - case 4: - case GL_RGBA: - case GL_COMPRESSED_RGBA: - if (format == GL_BGRA) { - if (type == GL_UNSIGNED_BYTE || type == GL_UNSIGNED_INT_8_8_8_8_REV) { - return &_mesa_texformat_argb8888; - } - else if (type == GL_UNSIGNED_SHORT_4_4_4_4_REV) { - return &_mesa_texformat_argb4444; - } - else if (type == GL_UNSIGNED_SHORT_1_5_5_5_REV) { - return &_mesa_texformat_argb1555; - } - } - return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444; - - case 3: - case GL_RGB: - case GL_COMPRESSED_RGB: - if (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) { - return &_mesa_texformat_rgb565; - } - return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_rgb565; - - case GL_RGBA8: - case GL_RGB10_A2: - case GL_RGBA12: - case GL_RGBA16: - return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444; - - case GL_RGBA4: - case GL_RGBA2: - return &_mesa_texformat_argb4444; - - case GL_RGB5_A1: - return &_mesa_texformat_argb1555; - - case GL_RGB8: - case GL_RGB10: - case GL_RGB12: - case GL_RGB16: - return &_mesa_texformat_argb8888; - - case GL_RGB5: - case GL_RGB4: - case GL_R3_G3_B2: - return &_mesa_texformat_rgb565; - - case GL_ALPHA: - case GL_ALPHA4: - case GL_ALPHA8: - case GL_ALPHA12: - case GL_ALPHA16: - case GL_COMPRESSED_ALPHA: - return &_mesa_texformat_a8; - - case 1: - case GL_LUMINANCE: - case GL_LUMINANCE4: - case GL_LUMINANCE8: - case GL_LUMINANCE12: - case GL_LUMINANCE16: - case GL_COMPRESSED_LUMINANCE: - return &_mesa_texformat_l8; - - case 2: - case GL_LUMINANCE_ALPHA: - case GL_LUMINANCE4_ALPHA4: - case GL_LUMINANCE6_ALPHA2: - case GL_LUMINANCE8_ALPHA8: - case GL_LUMINANCE12_ALPHA4: - case GL_LUMINANCE12_ALPHA12: - case GL_LUMINANCE16_ALPHA16: - case GL_COMPRESSED_LUMINANCE_ALPHA: - return &_mesa_texformat_al88; - - case GL_INTENSITY: - case GL_INTENSITY4: - case GL_INTENSITY8: - case GL_INTENSITY12: - case GL_INTENSITY16: - case GL_COMPRESSED_INTENSITY: - return &_mesa_texformat_i8; - - case GL_YCBCR_MESA: - if (type == GL_UNSIGNED_SHORT_8_8_MESA || type == GL_UNSIGNED_BYTE) - return &_mesa_texformat_ycbcr; - else - return &_mesa_texformat_ycbcr_rev; - - case GL_COMPRESSED_RGB_FXT1_3DFX: - return &_mesa_texformat_rgb_fxt1; - case GL_COMPRESSED_RGBA_FXT1_3DFX: - return &_mesa_texformat_rgba_fxt1; - - case GL_RGB_S3TC: - case GL_RGB4_S3TC: - case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: - return &_mesa_texformat_rgb_dxt1; - - case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: - return &_mesa_texformat_rgba_dxt1; - - case GL_RGBA_S3TC: - case GL_RGBA4_S3TC: - case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: - return &_mesa_texformat_rgba_dxt3; - - case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: - return &_mesa_texformat_rgba_dxt5; - - case GL_DEPTH_COMPONENT: - case GL_DEPTH_COMPONENT16: - case GL_DEPTH_COMPONENT24: - case GL_DEPTH_COMPONENT32: - return &_mesa_texformat_z16; - - case GL_DEPTH_STENCIL_EXT: - case GL_DEPTH24_STENCIL8_EXT: - return &_mesa_texformat_z24_s8; - - default: - fprintf(stderr, "unexpected texture format %s in %s\n", - _mesa_lookup_enum_by_nr(internalFormat), __FUNCTION__); - return NULL; - } - - return NULL; /* never get here */ -} static GLboolean -- cgit v1.2.3 From f8ab24760d0d3f07e9ee81c98207ddf92dfe74da Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 10 Aug 2007 08:37:15 +0100 Subject: rename st_cb_teximage.h st_format.h --- src/mesa/sources | 4 ++-- src/mesa/state_tracker/st_cb_drawpixels.c | 2 +- src/mesa/state_tracker/st_cb_fbo.c | 2 +- src/mesa/state_tracker/st_cb_texture.c | 2 +- src/mesa/state_tracker/st_format.c | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/sources b/src/mesa/sources index 9bcb07c6b4..be81e102ed 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -196,11 +196,11 @@ STATETRACKER_SOURCES = \ state_tracker/st_cb_drawpixels.c \ state_tracker/st_cb_fbo.c \ state_tracker/st_cb_program.c \ - state_tracker/st_cb_teximage.c \ state_tracker/st_cb_texture.c \ state_tracker/st_cb_bufferobjects.c \ - state_tracker/st_draw.c \ state_tracker/st_context.c \ + state_tracker/st_draw.c \ + state_tracker/st_format.c \ state_tracker/st_mipmap_tree.c SHADER_SOURCES = \ diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 6b7cef2b2a..20990fe80a 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -38,7 +38,7 @@ #include "st_program.h" #include "st_cb_drawpixels.h" #include "st_cb_texture.h" -#include "st_cb_teximage.h" +#include "st_format.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/tgsi/mesa/mesa_to_tgsi.h" diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 8443c9ea1b..bee7474e38 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -43,7 +43,7 @@ #include "pipe/p_defines.h" #include "st_context.h" #include "st_cb_fbo.h" -#include "st_cb_teximage.h" +#include "st_format.h" diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 6850d602e2..22c1b4baff 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -38,7 +38,7 @@ #include "state_tracker/st_context.h" #include "state_tracker/st_cb_texture.h" -#include "state_tracker/st_cb_teximage.h" +#include "state_tracker/st_format.h" #include "state_tracker/st_mipmap_tree.h" #include "pipe/p_context.h" diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c index c54602db5d..4f36c84d4e 100644 --- a/src/mesa/state_tracker/st_format.c +++ b/src/mesa/state_tracker/st_format.c @@ -40,7 +40,7 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "st_context.h" -#include "st_cb_teximage.h" +#include "st_format.h" -- cgit v1.2.3 From 137ec509946bba39940d3a7932bf196450cb951e Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 10 Aug 2007 11:17:26 -0600 Subject: sketch out some render-to-texture code --- src/mesa/state_tracker/st_cb_fbo.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index bee7474e38..99c00916f4 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -43,7 +43,9 @@ #include "pipe/p_defines.h" #include "st_context.h" #include "st_cb_fbo.h" +#include "st_cb_texture.h" #include "st_format.h" +#include "st_public.h" @@ -281,10 +283,17 @@ st_render_texture(GLcontext *ctx, struct gl_renderbuffer_attachment *att) { struct st_context *st = ctx->st; + struct pipe_context *pipe = st->pipe; struct pipe_framebuffer_state framebuffer; struct pipe_surface *texsurface; + struct pipe_mipmap_tree *mt; - texsurface = NULL; /* find the mipmap level, cube face, etc */ + mt = st_get_texobj_mipmap_tree(att->Texture); + + texsurface = pipe->get_tex_surface(pipe, mt, + att->CubeMapFace, + att->TextureLevel, + att->Zoffset); /* * XXX basically like this... set the current color (or depth) @@ -308,7 +317,12 @@ static void st_finish_render_texture(GLcontext *ctx, struct gl_renderbuffer_attachment *att) { - /* restore drawing to normal framebuffer. may be a no-op */ + struct st_renderbuffer *strb = st_renderbuffer(att->Renderbuffer); + + pipe_surface_unreference(&strb->surface); + + /* restore previous framebuffer state */ + st_invalidate_state(ctx, _NEW_BUFFERS); } -- cgit v1.2.3 From 3738606a52b585108d709ce6be8565fc6144cbc7 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 10 Aug 2007 11:35:57 -0600 Subject: more render to texture work --- src/mesa/state_tracker/st_cb_fbo.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 99c00916f4..64ec802216 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -283,26 +283,23 @@ st_render_texture(GLcontext *ctx, struct gl_renderbuffer_attachment *att) { struct st_context *st = ctx->st; + struct st_renderbuffer *strb = st_renderbuffer(att->Renderbuffer); struct pipe_context *pipe = st->pipe; struct pipe_framebuffer_state framebuffer; - struct pipe_surface *texsurface; struct pipe_mipmap_tree *mt; mt = st_get_texobj_mipmap_tree(att->Texture); - texsurface = pipe->get_tex_surface(pipe, mt, - att->CubeMapFace, - att->TextureLevel, - att->Zoffset); + /* the renderbuffer's surface is inside the mipmap_tree: */ + strb->surface = pipe->get_tex_surface(pipe, mt, + att->CubeMapFace, + att->TextureLevel, + att->Zoffset); - /* - * XXX basically like this... set the current color (or depth) - * drawing surface to be the given texture renderbuffer. - */ + /* update pipe's framebuffer state */ memset(&framebuffer, 0, sizeof(framebuffer)); framebuffer.num_cbufs = 1; - framebuffer.cbufs[0] = texsurface; - + framebuffer.cbufs[0] = strb->surface; if (memcmp(&framebuffer, &st->state.framebuffer, sizeof(framebuffer)) != 0) { st->state.framebuffer = framebuffer; st->pipe->set_framebuffer_state( st->pipe, &framebuffer ); -- cgit v1.2.3 From 9ac1a8d416c2bd50ca10186ca09f5e86f6fa4ce6 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 10 Aug 2007 12:13:48 -0600 Subject: pipe->region_alloc() now takes width instead of pitch, plus a flags param --- src/mesa/pipe/i915simple/i915_regions.c | 11 +++++++++-- src/mesa/pipe/p_context.h | 3 ++- src/mesa/pipe/p_defines.h | 19 +++++++++++++++---- src/mesa/pipe/p_state.h | 10 ---------- src/mesa/pipe/softpipe/sp_region.c | 2 +- src/mesa/state_tracker/st_cb_bufferobjects.c | 5 ++++- src/mesa/state_tracker/st_cb_drawpixels.c | 9 ++++----- src/mesa/state_tracker/st_cb_fbo.c | 9 +++------ src/mesa/state_tracker/st_mipmap_tree.c | 9 ++++++--- 9 files changed, 44 insertions(+), 33 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/pipe/i915simple/i915_regions.c b/src/mesa/pipe/i915simple/i915_regions.c index e2b807f959..b3bcae547d 100644 --- a/src/mesa/pipe/i915simple/i915_regions.c +++ b/src/mesa/pipe/i915simple/i915_regions.c @@ -31,6 +31,7 @@ * - refcounting of buffer mappings. */ +#include "pipe/p_defines.h" #include "i915_context.h" #include "i915_winsys.h" #include "i915_blit.h" @@ -70,7 +71,7 @@ i915_region_unmap(struct pipe_context *pipe, struct pipe_region *region) static struct pipe_region * i915_region_alloc(struct pipe_context *pipe, - GLuint cpp, GLuint width, GLuint height) + GLuint cpp, GLuint width, GLuint height, GLbitfield flags) { struct i915_context *i915 = i915_context( pipe ); struct pipe_region *region = calloc(sizeof(*region), 1); @@ -82,7 +83,13 @@ i915_region_alloc(struct pipe_context *pipe, * clearly want to be able to render to textures under some * circumstances, but maybe not always a requirement. */ - unsigned pitch = ((cpp * width + 63) & ~63) / cpp; + unsigned pitch; + + /* XXX is the pitch different for textures vs. drawables? */ + if (flags & PIPE_SURFACE_FLAG_TEXTURE) /* or PIPE_SURFACE_FLAG_RENDER? */ + pitch = ((cpp * width + 63) & ~63) / cpp; + else + pitch = ((cpp * width + 63) & ~63) / cpp; region->cpp = cpp; region->pitch = pitch; diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index b5dd149603..7eb492816b 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -140,7 +140,8 @@ struct pipe_context { * Some of these may go away... */ struct pipe_region *(*region_alloc)(struct pipe_context *pipe, - GLuint cpp, GLuint pitch, GLuint height); + GLuint cpp, GLuint width, GLuint height, + GLbitfield flags); void (*region_release)(struct pipe_context *pipe, struct pipe_region **r); diff --git a/src/mesa/pipe/p_defines.h b/src/mesa/pipe/p_defines.h index efbb3239a2..52ecd5b119 100644 --- a/src/mesa/pipe/p_defines.h +++ b/src/mesa/pipe/p_defines.h @@ -176,11 +176,22 @@ /** - * Buffer mapping access modes + * Surface flags */ -#define PIPE_MAP_READ 1 -#define PIPE_MAP_WRITE 2 -#define PIPE_MAP_READ_WRITE 3 +#define PIPE_SURFACE_FLAG_TEXTURE 0x1 +#define PIPE_SURFACE_FLAG_RENDER 0x2 + + +/** + * Buffer flags + */ +#define PIPE_BUFFER_FLAG_READ 0x1 +#define PIPE_BUFFER_FLAG_WRITE 0x2 + +#define PIPE_BUFFER_USE_TEXTURE 0x1 +#define PIPE_BUFFER_USE_VERTEX_BUFFER 0x2 +#define PIPE_BUFFER_USE_INDEX_BUFFER 0x4 +#define PIPE_BUFFER_USE_RENDER_TARGET 0x8 /** diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index 64a475ba00..df456cc2ed 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -329,15 +329,5 @@ struct pipe_mipmap_tree struct pipe_buffer_handle; -#define PIPE_BUFFER_FLAG_READ 0x1 -#define PIPE_BUFFER_FLAG_WRITE 0x2 - -#define PIPE_BUFFER_USE_TEXTURE 0x1 -#define PIPE_BUFFER_USE_VERTEX_BUFFER 0x2 -#define PIPE_BUFFER_USE_INDEX_BUFFER 0x4 -#define PIPE_BUFFER_USE_RENDER_TARGET 0x8 - - - #endif diff --git a/src/mesa/pipe/softpipe/sp_region.c b/src/mesa/pipe/softpipe/sp_region.c index 58749492ec..1db508f028 100644 --- a/src/mesa/pipe/softpipe/sp_region.c +++ b/src/mesa/pipe/softpipe/sp_region.c @@ -70,7 +70,7 @@ sp_region_unmap(struct pipe_context *pipe, struct pipe_region *region) static struct pipe_region * sp_region_alloc(struct pipe_context *pipe, - GLuint cpp, GLuint pitch, GLuint height) + GLuint cpp, GLuint pitch, GLuint height, GLbitfield flags) { struct softpipe_context *sp = softpipe_context( pipe ); struct pipe_region *region = calloc(sizeof(*region), 1); diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c index d020eb2007..78fc18a49a 100644 --- a/src/mesa/state_tracker/st_cb_bufferobjects.c +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c @@ -34,6 +34,9 @@ #include "st_cb_bufferobjects.h" #include "pipe/p_context.h" +#include "pipe/p_defines.h" + + /* Pixel buffers and Vertex/index buffers are handled through these * mesa callbacks. Framebuffer/Renderbuffer objects are @@ -160,7 +163,7 @@ st_bufferobj_map(GLcontext *ctx, flags = PIPE_BUFFER_FLAG_WRITE; break; - + case GL_READ_ONLY: flags = PIPE_BUFFER_FLAG_READ; break; diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index f0c7a2bfc5..6981097ef4 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -101,20 +101,19 @@ make_mipmap_tree(struct st_context *st, const GLvoid *pixels) { GLuint pipeFormat = st_choose_pipe_format(st->pipe, GL_RGBA, format, type); - int cpp = 4, pitch; + int cpp = 4; struct pipe_mipmap_tree *mt = CALLOC_STRUCT(pipe_mipmap_tree); + GLbitfield flags = PIPE_SURFACE_FLAG_TEXTURE; assert(pipeFormat); - pitch = width; /* XXX pad */ - if (unpack->BufferObj) { /* mt->region = buffer_object_region(unpack->BufferObj); */ } else { - mt->region = st->pipe->region_alloc(st->pipe, cpp, pitch, height); + mt->region = st->pipe->region_alloc(st->pipe, cpp, width, height, flags); /* XXX do texstore() here */ } @@ -128,7 +127,7 @@ make_mipmap_tree(struct st_context *st, mt->depth0 = 1; mt->cpp = cpp; mt->compressed = 0; - mt->pitch = pitch; + mt->pitch = mt->region->pitch; mt->depth_pitch = 0; mt->total_height = height; mt->level[0].level_offset = 0; diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 64ec802216..bb588d10ea 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -62,7 +62,8 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, const GLuint pipeFormat = st_choose_pipe_format(pipe, internalFormat, GL_NONE, GL_NONE); const struct pipe_format_info *info = st_get_format_info(pipeFormat); - GLuint cpp, pitch; + GLuint cpp; + GLbitfield flags = PIPE_SURFACE_FLAG_RENDER; /* want to render to surface */ assert(info); if (!info) @@ -98,11 +99,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, pipe->region_release(pipe, &strb->surface->region); } - /* Choose a pitch to match hardware requirements: - */ - pitch = ((cpp * width + 63) & ~63) / cpp; /* XXX fix: device-specific */ - - strb->surface->region = pipe->region_alloc(pipe, cpp, pitch, height); + strb->surface->region = pipe->region_alloc(pipe, cpp, width, height, flags); if (!strb->surface->region) return GL_FALSE; /* out of memory, try s/w buffer? */ diff --git a/src/mesa/state_tracker/st_mipmap_tree.c b/src/mesa/state_tracker/st_mipmap_tree.c index ac74335ba1..3cbe697ab3 100644 --- a/src/mesa/state_tracker/st_mipmap_tree.c +++ b/src/mesa/state_tracker/st_mipmap_tree.c @@ -62,6 +62,7 @@ st_miptree_create(struct pipe_context *pipe, { GLboolean ok; struct pipe_mipmap_tree *mt = calloc(sizeof(*mt), 1); + GLbitfield flags = 0x0; DBG("%s target %s format %s level %d..%d\n", __FUNCTION__, _mesa_lookup_enum_by_nr(target), @@ -79,9 +80,11 @@ st_miptree_create(struct pipe_context *pipe, mt->refcount = 1; ok = pipe->mipmap_tree_layout(pipe, mt); - if (ok) - mt->region = pipe->region_alloc(pipe, - mt->cpp, mt->pitch, mt->total_height); + if (ok) { + /* note: it's OK to pass 'pitch' as 'width' here: */ + mt->region = pipe->region_alloc(pipe, mt->cpp, mt->pitch, + mt->total_height, flags); + } if (!mt->region) { free(mt); -- cgit v1.2.3 From faa14a9ded2ddb784302b4634f0ca40c51ec1c4b Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 13 Aug 2007 14:53:27 -0600 Subject: check for ctx==NULL in st_renderbuffer_delete() --- src/mesa/state_tracker/st_cb_fbo.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index bb588d10ea..3048765114 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -118,15 +118,20 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, static void st_renderbuffer_delete(struct gl_renderbuffer *rb) { - GET_CURRENT_CONTEXT(ctx); - struct pipe_context *pipe = ctx->st->pipe; struct st_renderbuffer *strb = st_renderbuffer(rb); - ASSERT(strb); - if (strb && strb->surface) { - if (strb->surface->region) { - pipe->region_release(pipe, &strb->surface->region); + GET_CURRENT_CONTEXT(ctx); + if (ctx) { + struct pipe_context *pipe = ctx->st->pipe; + ASSERT(strb); + if (strb && strb->surface) { + if (strb->surface->region) { + pipe->region_release(pipe, &strb->surface->region); + } + free(strb->surface); } - free(strb->surface); + } + else { + _mesa_warning(NULL, "st_renderbuffer_delete() called, but no current context"); } free(strb); } -- cgit v1.2.3 From 5e1bfe426f3e2bc7a13b3814f1fa732141f15a9a Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 13 Aug 2007 16:18:03 -0600 Subject: fix up some render-to-texture code ... almost there --- src/mesa/state_tracker/st_cb_fbo.c | 47 ++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 9 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 3048765114..c0b88404b6 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -285,27 +285,48 @@ st_render_texture(GLcontext *ctx, struct gl_renderbuffer_attachment *att) { struct st_context *st = ctx->st; - struct st_renderbuffer *strb = st_renderbuffer(att->Renderbuffer); + struct st_renderbuffer *strb; + struct gl_renderbuffer *rb; struct pipe_context *pipe = st->pipe; struct pipe_framebuffer_state framebuffer; struct pipe_mipmap_tree *mt; + assert(!att->Renderbuffer); + + /* create new renderbuffer which wraps the texture image */ + rb = st_new_renderbuffer(ctx, 0); + if (!rb) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glFramebufferTexture()"); + return; + } + + _mesa_reference_renderbuffer(&att->Renderbuffer, rb); + assert(rb->RefCount == 1); + rb->AllocStorage = NULL; /* should not get called */ + strb = st_renderbuffer(rb); + + /* get the mipmap tree for the texture */ mt = st_get_texobj_mipmap_tree(att->Texture); + assert(mt); + assert(mt->level[0].width); /* the renderbuffer's surface is inside the mipmap_tree: */ strb->surface = pipe->get_tex_surface(pipe, mt, att->CubeMapFace, att->TextureLevel, att->Zoffset); + assert(strb->surface); - /* update pipe's framebuffer state */ - memset(&framebuffer, 0, sizeof(framebuffer)); - framebuffer.num_cbufs = 1; - framebuffer.cbufs[0] = strb->surface; - if (memcmp(&framebuffer, &st->state.framebuffer, sizeof(framebuffer)) != 0) { - st->state.framebuffer = framebuffer; - st->pipe->set_framebuffer_state( st->pipe, &framebuffer ); - } + /* + printf("RENDER TO TEXTURE mt=%p surf=%p\n", mt, strb->surface); + */ + + /* Invalidate buffer state so that the pipe's framebuffer state + * gets updated. + * That's where the new renderbuffer (which we just created) gets + * passed to the pipe as a (color/depth) render target. + */ + st_invalidate_state(ctx, _NEW_BUFFERS); } @@ -318,8 +339,16 @@ st_finish_render_texture(GLcontext *ctx, { struct st_renderbuffer *strb = st_renderbuffer(att->Renderbuffer); + assert(strb); + + /* + printf("FINISH RENDER TO TEXTURE surf=%p\n", strb->surface); + */ + pipe_surface_unreference(&strb->surface); + _mesa_reference_renderbuffer(&att->Renderbuffer, NULL); + /* restore previous framebuffer state */ st_invalidate_state(ctx, _NEW_BUFFERS); } -- cgit v1.2.3 From 2f605fd457ccd8763ce5b0acc8d2906a59ea22bc Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 13 Aug 2007 18:16:47 -0600 Subject: set renderbuffer Width/Height = texture size --- src/mesa/state_tracker/st_cb_fbo.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index c0b88404b6..7336327330 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -288,7 +288,6 @@ st_render_texture(GLcontext *ctx, struct st_renderbuffer *strb; struct gl_renderbuffer *rb; struct pipe_context *pipe = st->pipe; - struct pipe_framebuffer_state framebuffer; struct pipe_mipmap_tree *mt; assert(!att->Renderbuffer); @@ -310,6 +309,9 @@ st_render_texture(GLcontext *ctx, assert(mt); assert(mt->level[0].width); + rb->Width = mt->level[0].width; + rb->Height = mt->level[0].height; + /* the renderbuffer's surface is inside the mipmap_tree: */ strb->surface = pipe->get_tex_surface(pipe, mt, att->CubeMapFace, @@ -317,9 +319,8 @@ st_render_texture(GLcontext *ctx, att->Zoffset); assert(strb->surface); - /* - printf("RENDER TO TEXTURE mt=%p surf=%p\n", mt, strb->surface); - */ + printf("RENDER TO TEXTURE obj=%p mt=%p surf=%p %d x %d\n", + att->Texture, mt, strb->surface, rb->Width, rb->Height); /* Invalidate buffer state so that the pipe's framebuffer state * gets updated. @@ -341,9 +342,9 @@ st_finish_render_texture(GLcontext *ctx, assert(strb); - /* + ctx->st->pipe->flush(ctx->st->pipe, 0x0); + printf("FINISH RENDER TO TEXTURE surf=%p\n", strb->surface); - */ pipe_surface_unreference(&strb->surface); -- cgit v1.2.3 From 04f2078860d0649b016e9281f86725cb42e15b42 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 17 Aug 2007 10:27:37 +0100 Subject: added assertions, disable debug output --- src/mesa/state_tracker/st_cb_clear.c | 2 ++ src/mesa/state_tracker/st_cb_fbo.c | 5 +++++ 2 files changed, 7 insertions(+) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 492073e840..d584f0cafc 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -409,6 +409,8 @@ clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { struct st_renderbuffer *strb = st_renderbuffer(rb); + assert(strb->surface->format); + if (!ctx->Scissor.Enabled && !is_depth_stencil_format(strb->surface->format)) { /* clear whole depth buffer w/out masking */ diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 7336327330..2b9aa3e9d2 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -104,6 +104,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, return GL_FALSE; /* out of memory, try s/w buffer? */ ASSERT(strb->surface->region->buffer); + ASSERT(strb->surface->format); strb->Base.Width = strb->surface->width = width; strb->Base.Height = strb->surface->height = height; @@ -319,8 +320,10 @@ st_render_texture(GLcontext *ctx, att->Zoffset); assert(strb->surface); + /* printf("RENDER TO TEXTURE obj=%p mt=%p surf=%p %d x %d\n", att->Texture, mt, strb->surface, rb->Width, rb->Height); + */ /* Invalidate buffer state so that the pipe's framebuffer state * gets updated. @@ -344,7 +347,9 @@ st_finish_render_texture(GLcontext *ctx, ctx->st->pipe->flush(ctx->st->pipe, 0x0); + /* printf("FINISH RENDER TO TEXTURE surf=%p\n", strb->surface); + */ pipe_surface_unreference(&strb->surface); -- cgit v1.2.3 From 8a868919b50bdca4dc697d61e220a8fb50764f8e Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 22 Aug 2007 12:41:59 -0600 Subject: Improved pipe_region/surface_reference() functions Now dereferences the old object first. Target object may be NULL to clear the pointer. --- src/mesa/pipe/p_context.h | 66 +++++++++++++++++++++++++------------- src/mesa/state_tracker/st_cb_fbo.c | 2 +- 2 files changed, 45 insertions(+), 23 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 0d90a967cc..ec9973383c 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -213,38 +213,60 @@ struct pipe_context { }; - +/** + * Set 'ptr' to point to 'region' and update reference counting. + * The old thing pointed to, if any, will be unreferenced first. + * 'region' may be NULL. + */ static INLINE void -pipe_region_reference(struct pipe_region **dst, struct pipe_region *src) +pipe_region_reference(struct pipe_region **ptr, struct pipe_region *region) { - assert(*dst == NULL); - if (src) { - src->refcount++; - *dst = src; + assert(ptr); + if (*ptr) { + /* unreference the old thing */ + struct pipe_region *oldReg = *ptr; + oldReg->refcount--; + assert(oldReg->refcount >= 0); + if (oldReg->refcount == 0) { + /* free the old region */ + assert(oldReg->map_refcount == 0); + /* XXX dereference the region->buffer */ + free(oldReg); + } + *ptr = NULL; + } + if (region) { + /* reference the new thing */ + region->refcount++; + *ptr = region; } } +/** + * \sa pipe_region_reference + */ static INLINE void -pipe_surface_reference(struct pipe_surface **dst, struct pipe_surface *src) +pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf) { - assert(*dst == NULL); - if (src) { - src->refcount++; - *dst = src; + assert(ptr); + if (*ptr) { + /* unreference the old thing */ + struct pipe_surface *oldSurf = *ptr; + oldSurf->refcount--; + assert(oldSurf->refcount >= 0); + if (oldSurf->refcount == 0) { + /* free the old region */ + pipe_region_reference(&oldSurf->region, NULL); + free(oldSurf); + } + *ptr = NULL; } -} - -static INLINE void -pipe_surface_unreference(struct pipe_surface **ps) -{ - assert(*ps); - (*ps)->refcount--; - if ((*ps)->refcount <= 0) { - /* XXX need a proper surface->free method */ - free(*ps); + if (surf) { + /* reference the new thing */ + surf->refcount++; + *ptr = surf; } - *ps = NULL; } diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 2b9aa3e9d2..430ac715e5 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -351,7 +351,7 @@ st_finish_render_texture(GLcontext *ctx, printf("FINISH RENDER TO TEXTURE surf=%p\n", strb->surface); */ - pipe_surface_unreference(&strb->surface); + pipe_surface_reference(&strb->surface, NULL); _mesa_reference_renderbuffer(&att->Renderbuffer, NULL); -- cgit v1.2.3 From 7fe09341489ff61dc1a3a771fd3e75b3f866d6a9 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 23 Aug 2007 21:59:27 +0100 Subject: added GL_STENCIL_INDEX8_EXT --- src/mesa/state_tracker/st_cb_fbo.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 430ac715e5..563b5add38 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -233,6 +233,9 @@ st_new_renderbuffer_fb(GLenum intFormat) case GL_DEPTH24_STENCIL8_EXT: strb->Base._BaseFormat = GL_DEPTH_STENCIL_EXT; break; + case GL_STENCIL_INDEX8_EXT: + strb->Base._BaseFormat = GL_STENCIL_INDEX; + break; default: _mesa_problem(NULL, "Unexpected intFormat in st_new_renderbuffer"); -- cgit v1.2.3 From 617b39ce9811b0998ceb746c935cc50cacf8a9bc Mon Sep 17 00:00:00 2001 From: Michel Dänzer Date: Wed, 19 Sep 2007 17:59:51 +0100 Subject: Pad surface dimensions to multiples of 2. Avoids an assertion failure with softpipe if requested width or height is odd. --- src/mesa/state_tracker/st_cb_fbo.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 563b5add38..5b4afbd119 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -99,6 +99,10 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, pipe->region_release(pipe, &strb->surface->region); } + /* Softpipe operates on quads, so pad dimensions to multiples of 2 */ + width += width & 1; + height += height & 1; + strb->surface->region = pipe->region_alloc(pipe, cpp, width, height, flags); if (!strb->surface->region) return GL_FALSE; /* out of memory, try s/w buffer? */ -- cgit v1.2.3 From 500e3af175cf8ef66bad23ae3b9e440670421ecd Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 10 Oct 2007 11:04:48 -0600 Subject: fix width/height padding that caused failed assertion upon window resize --- src/mesa/state_tracker/st_cb_fbo.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 5b4afbd119..4a21ff5371 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -64,6 +64,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, const struct pipe_format_info *info = st_get_format_info(pipeFormat); GLuint cpp; GLbitfield flags = PIPE_SURFACE_FLAG_RENDER; /* want to render to surface */ + GLuint width2, height2; assert(info); if (!info) @@ -100,10 +101,10 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, } /* Softpipe operates on quads, so pad dimensions to multiples of 2 */ - width += width & 1; - height += height & 1; + width2 = (width + 1) & ~1; + height2 = (height + 1) & ~1; - strb->surface->region = pipe->region_alloc(pipe, cpp, width, height, flags); + strb->surface->region = pipe->region_alloc(pipe, cpp, width2, height2, flags); if (!strb->surface->region) return GL_FALSE; /* out of memory, try s/w buffer? */ -- cgit v1.2.3 From 2b31b413f97c73816a2845782aee9a49e22d2e0b Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 10 Oct 2007 14:13:21 -0600 Subject: use correct mipmap level in st_render_texture() --- src/mesa/state_tracker/st_cb_fbo.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 4a21ff5371..3e4aeab523 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -316,10 +316,10 @@ st_render_texture(GLcontext *ctx, /* get the mipmap tree for the texture */ mt = st_get_texobj_mipmap_tree(att->Texture); assert(mt); - assert(mt->level[0].width); + assert(mt->level[att->TextureLevel].width); - rb->Width = mt->level[0].width; - rb->Height = mt->level[0].height; + rb->Width = mt->level[att->TextureLevel].width; + rb->Height = mt->level[att->TextureLevel].height; /* the renderbuffer's surface is inside the mipmap_tree: */ strb->surface = pipe->get_tex_surface(pipe, mt, -- cgit v1.2.3 From 7b0b694406e4043cb163f9832c9c02934fa54568 Mon Sep 17 00:00:00 2001 From: Brian Date: Sun, 14 Oct 2007 11:55:31 -0600 Subject: 16-bit rgba surface/format for accum --- src/mesa/state_tracker/st_cb_fbo.c | 12 ++++------ src/mesa/state_tracker/st_format.c | 49 +++++++++++++++++++++++++++++++++++++- src/mesa/state_tracker/st_format.h | 5 ++++ 3 files changed, 57 insertions(+), 9 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 3e4aeab523..e1cc7d98bd 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -70,14 +70,6 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, if (!info) return GL_FALSE; - switch (pipeFormat) { - case PIPE_FORMAT_S8_Z24: - strb->Base.DataType = GL_UNSIGNED_INT; - break; - default: - strb->Base.DataType = GL_UNSIGNED_BYTE; /* XXX fix */ - } - strb->Base._ActualFormat = info->base_format; strb->Base.RedBits = info->red_bits; strb->Base.GreenBits = info->green_bits; @@ -85,6 +77,9 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, strb->Base.AlphaBits = info->alpha_bits; strb->Base.DepthBits = info->depth_bits; strb->Base.StencilBits = info->stencil_bits; + strb->Base.DataType = st_format_datatype(pipeFormat); + + assert(strb->Base.DataType); cpp = info->size; @@ -229,6 +224,7 @@ st_new_renderbuffer_fb(GLenum intFormat) switch (intFormat) { case GL_RGB5: case GL_RGBA8: + case GL_RGBA16: strb->Base._BaseFormat = GL_RGBA; break; case GL_DEPTH_COMPONENT16: diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c index 2d20892cb0..7564c6014e 100644 --- a/src/mesa/state_tracker/st_format.c +++ b/src/mesa/state_tracker/st_format.c @@ -54,6 +54,7 @@ st_get_format_info(GLuint format) { PIPE_FORMAT_U_R8_G8_B8_A8, /* format */ GL_RGBA, /* base_format */ + GL_UNSIGNED_BYTE, /* datatype for renderbuffers */ 8, 8, 8, 8, 0, 0, /* color bits */ 0, 0, /* depth, stencil */ 4 /* size in bytes */ @@ -61,6 +62,7 @@ st_get_format_info(GLuint format) { PIPE_FORMAT_U_A8_R8_G8_B8, GL_RGBA, /* base_format */ + GL_UNSIGNED_BYTE, /* datatype for renderbuffers */ 8, 8, 8, 8, 0, 0, /* color bits */ 0, 0, /* depth, stencil */ 4 /* size in bytes */ @@ -68,6 +70,7 @@ st_get_format_info(GLuint format) { PIPE_FORMAT_U_A1_R5_G5_B5, GL_RGBA, /* base_format */ + GL_UNSIGNED_SHORT, /* datatype for renderbuffers */ 5, 5, 5, 1, 0, 0, /* color bits */ 0, 0, /* depth, stencil */ 2 /* size in bytes */ @@ -75,13 +78,23 @@ st_get_format_info(GLuint format) { PIPE_FORMAT_U_R5_G6_B5, GL_RGBA, /* base_format */ + GL_UNSIGNED_SHORT, /* datatype for renderbuffers */ 5, 6, 5, 0, 0, 0, /* color bits */ 0, 0, /* depth, stencil */ 2 /* size in bytes */ }, + { + PIPE_FORMAT_S_R16_G16_B16_A16, + GL_RGBA, /* base_format */ + GL_UNSIGNED_SHORT, /* datatype for renderbuffers */ + 16, 16, 16, 16, 0, 0, /* color bits */ + 0, 0, /* depth, stencil */ + 8 /* size in bytes */ + }, { PIPE_FORMAT_U_Z16, GL_DEPTH_COMPONENT, /* base_format */ + GL_UNSIGNED_SHORT, /* datatype for renderbuffers */ 0, 0, 0, 0, 0, 0, /* color bits */ 16, 0, /* depth, stencil */ 2 /* size in bytes */ @@ -89,6 +102,7 @@ st_get_format_info(GLuint format) { PIPE_FORMAT_U_Z32, GL_DEPTH_COMPONENT, /* base_format */ + GL_UNSIGNED_INT, /* datatype for renderbuffers */ 0, 0, 0, 0, 0, 0, /* color bits */ 32, 0, /* depth, stencil */ 4 /* size in bytes */ @@ -96,6 +110,7 @@ st_get_format_info(GLuint format) { PIPE_FORMAT_S8_Z24, GL_DEPTH_STENCIL_EXT, /* base_format */ + GL_UNSIGNED_INT, /* datatype for renderbuffers */ 0, 0, 0, 0, 0, 0, /* color bits */ 24, 8, /* depth, stencil */ 4 /* size in bytes */ @@ -112,6 +127,9 @@ st_get_format_info(GLuint format) } +/** + * Return bytes per pixel for the given format. + */ GLuint st_sizeof_format(GLuint pipeFormat) { @@ -121,6 +139,18 @@ st_sizeof_format(GLuint pipeFormat) } +/** + * Return bytes per pixel for the given format. + */ +GLenum +st_format_datatype(GLuint pipeFormat) +{ + const struct pipe_format_info *info = st_get_format_info(pipeFormat); + assert(info); + return info->datatype; +} + + GLuint st_mesa_format_to_pipe_format(GLuint mesaFormat) { @@ -164,6 +194,22 @@ default_rgba_format(const GLuint formats[], GLuint num) } +/** + * Search list of formats for first RGBA format with >8 bits/channel. + */ +static GLuint +default_deep_rgba_format(const GLuint formats[], GLuint num) +{ + GLuint i; + for (i = 0; i < num; i++) { + if (formats[i] == PIPE_FORMAT_S_R16_G16_B16_A16) { + return formats[i]; + } + } + return PIPE_FORMAT_NONE; +} + + /** * Search list of formats for first depth/Z format. */ @@ -244,8 +290,9 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat, case GL_RGBA8: case GL_RGB10_A2: case GL_RGBA12: - case GL_RGBA16: return default_rgba_format(supported, n); + case GL_RGBA16: + return default_deep_rgba_format(supported, n); case GL_RGBA4: case GL_RGBA2: diff --git a/src/mesa/state_tracker/st_format.h b/src/mesa/state_tracker/st_format.h index 6b3cba0f63..17d0985411 100644 --- a/src/mesa/state_tracker/st_format.h +++ b/src/mesa/state_tracker/st_format.h @@ -34,6 +34,7 @@ struct pipe_format_info { GLuint format; GLenum base_format; + GLenum datatype; GLubyte red_bits; GLubyte green_bits; GLubyte blue_bits; @@ -54,6 +55,10 @@ extern GLuint st_sizeof_format(GLuint pipeFormat); +extern GLenum +st_format_datatype(GLuint pipeFormat); + + extern GLuint st_mesa_format_to_pipe_format(GLuint mesaFormat); -- cgit v1.2.3 From a1633c07164e8bc9630f1fa77769e7ceee585a59 Mon Sep 17 00:00:00 2001 From: Brian Date: Sat, 20 Oct 2007 15:20:46 -0600 Subject: unmap regions when reallocating renderbuffer storage --- src/mesa/state_tracker/st_cb_fbo.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index e1cc7d98bd..64a64fd6b9 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -92,6 +92,10 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, /* free old region */ if (strb->surface->region) { + /* loop here since mapping is refcounted */ + struct pipe_region *r = strb->surface->region; + while (r->map) + pipe->region_unmap(pipe, r); pipe->region_release(pipe, &strb->surface->region); } -- cgit v1.2.3 From 5c79c088cd0a2c512891b87b67a3c4f810595658 Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 23 Oct 2007 08:30:36 -0600 Subject: Don't pad renderbuffers to multiple of two pixels anymore. This was only needed to avoid out-of-bounds memory accesses with the 2x2 quad_read/write() functions which no longer exist. --- src/mesa/state_tracker/st_cb_fbo.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 64a64fd6b9..94e286feab 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -64,7 +64,6 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, const struct pipe_format_info *info = st_get_format_info(pipeFormat); GLuint cpp; GLbitfield flags = PIPE_SURFACE_FLAG_RENDER; /* want to render to surface */ - GLuint width2, height2; assert(info); if (!info) @@ -99,11 +98,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, pipe->region_release(pipe, &strb->surface->region); } - /* Softpipe operates on quads, so pad dimensions to multiples of 2 */ - width2 = (width + 1) & ~1; - height2 = (height + 1) & ~1; - - strb->surface->region = pipe->region_alloc(pipe, cpp, width2, height2, flags); + strb->surface->region = pipe->region_alloc(pipe, cpp, width, height, flags); if (!strb->surface->region) return GL_FALSE; /* out of memory, try s/w buffer? */ -- cgit v1.2.3 From f684120417c6b3ca9e7486ffeb24fe88e428834d Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 25 Oct 2007 19:27:29 -0600 Subject: Move region_alloc() and region_release() to pipe_winsys. This allows regions to be allocated w/out a rendering context. --- .../drivers/dri/intel_winsys/intel_winsys_i915.c | 61 ++++++++++++++++ src/mesa/drivers/x11/xm_buffer.c | 4 +- src/mesa/drivers/x11/xm_surface.c | 4 +- src/mesa/drivers/x11/xm_winsys.c | 83 ++++++++++++++++------ src/mesa/pipe/failover/fo_context.c | 2 - src/mesa/pipe/i915simple/i915_regions.c | 61 ---------------- src/mesa/pipe/p_context.h | 13 ++-- src/mesa/pipe/p_winsys.h | 14 ++++ src/mesa/pipe/softpipe/sp_region.c | 57 --------------- src/mesa/state_tracker/st_cb_drawpixels.c | 9 ++- src/mesa/state_tracker/st_cb_fbo.c | 8 ++- src/mesa/state_tracker/st_mipmap_tree.c | 7 +- 12 files changed, 163 insertions(+), 160 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/drivers/dri/intel_winsys/intel_winsys_i915.c b/src/mesa/drivers/dri/intel_winsys/intel_winsys_i915.c index f6eb050152..c481495309 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_winsys_i915.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_winsys_i915.c @@ -120,6 +120,64 @@ static void intel_i915_batch_flush( struct i915_winsys *sws ) +static struct pipe_region * +intel_i915_region_alloc(struct pipe_winsys *winsys, + unsigned cpp, unsigned width, + unsigned height, unsigned flags) +{ + struct pipe_region *region = calloc(sizeof(*region), 1); + const unsigned alignment = 64; + + /* Choose a pitch to match hardware requirements - requires 64 byte + * alignment of render targets. + * + * XXX: is this ok for textures?? + * clearly want to be able to render to textures under some + * circumstances, but maybe not always a requirement. + */ + unsigned pitch; + + /* XXX is the pitch different for textures vs. drawables? */ + if (flags & PIPE_SURFACE_FLAG_TEXTURE) /* or PIPE_SURFACE_FLAG_RENDER? */ + pitch = ((cpp * width + 63) & ~63) / cpp; + else + pitch = ((cpp * width + 63) & ~63) / cpp; + + region->cpp = cpp; + region->pitch = pitch; + region->height = height; /* needed? */ + region->refcount = 1; + + region->buffer = winsys->buffer_create( winsys, alignment ); + + winsys->buffer_data( winsys, + region->buffer, + pitch * cpp * height, + NULL ); + + return region; +} + +static void +intel_i915_region_release(struct pipe_winsys *winsys, + struct pipe_region **region) +{ + if (!*region) + return; + + assert((*region)->refcount > 0); + (*region)->refcount--; + + if ((*region)->refcount == 0) { + assert((*region)->map_refcount == 0); + + winsys->buffer_reference( winsys, + &((*region)->buffer), NULL ); + free(*region); + } + *region = NULL; +} + struct pipe_context * intel_create_i915simple( struct intel_context *intel ) @@ -135,6 +193,9 @@ intel_create_i915simple( struct intel_context *intel ) iws->winsys.batch_flush = intel_i915_batch_flush; iws->intel = intel; + iws->winsys.region_alloc = intel_i915_region_alloc; + iws->winsys.region_release = intel_i915_region_release; + /* Create the i915simple context: */ return i915_create( intel_create_pipe_winsys(intel), diff --git a/src/mesa/drivers/x11/xm_buffer.c b/src/mesa/drivers/x11/xm_buffer.c index b8d3df1379..09356c7329 100644 --- a/src/mesa/drivers/x11/xm_buffer.c +++ b/src/mesa/drivers/x11/xm_buffer.c @@ -37,6 +37,7 @@ #include "renderbuffer.h" #include "pipe/p_state.h" #include "pipe/p_defines.h" +#include "pipe/p_winsys.h" #include "state_tracker/st_context.h" @@ -254,7 +255,8 @@ finish_surface_init(GLcontext *ctx, struct xmesa_renderbuffer *xrb) struct pipe_context *pipe = ctx->st->pipe; if (!xrb->St.surface->region) { int w = 1, h = 1; - xrb->St.surface->region = pipe->region_alloc(pipe, 1, w, h, 0x0); + xrb->St.surface->region = pipe->winsys->region_alloc(pipe->winsys, + 1, w, h, 0x0); } } diff --git a/src/mesa/drivers/x11/xm_surface.c b/src/mesa/drivers/x11/xm_surface.c index 340f796bc8..337033f8ad 100644 --- a/src/mesa/drivers/x11/xm_surface.c +++ b/src/mesa/drivers/x11/xm_surface.c @@ -44,6 +44,7 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "pipe/p_winsys.h" #include "pipe/softpipe/sp_context.h" #include "pipe/softpipe/sp_clear.h" #include "pipe/softpipe/sp_tile_cache.h" @@ -163,7 +164,8 @@ xmesa_new_color_surface(struct pipe_context *pipe, GLuint pipeFormat) * functions. */ if (pipe) - xms->surface.surface.region = pipe->region_alloc(pipe, 1, 0, 0, 0x0); + xms->surface.surface.region = pipe->winsys->region_alloc(pipe->winsys, + 1, 0, 0, 0x0); return &xms->surface.surface; } diff --git a/src/mesa/drivers/x11/xm_winsys.c b/src/mesa/drivers/x11/xm_winsys.c index 7e29580b50..624d28dd01 100644 --- a/src/mesa/drivers/x11/xm_winsys.c +++ b/src/mesa/drivers/x11/xm_winsys.c @@ -233,6 +233,63 @@ xm_user_buffer_create(struct pipe_winsys *pws, void *ptr, unsigned bytes) } + +/** + * Round n up to next multiple. + */ +static INLINE unsigned +round_up(unsigned n, unsigned multiple) +{ + return (n + multiple - 1) & ~(multiple - 1); +} + + +static struct pipe_region * +xm_region_alloc(struct pipe_winsys *winsys, + unsigned cpp, unsigned width, unsigned height, unsigned flags) +{ + struct pipe_region *region = CALLOC_STRUCT(pipe_region); + const unsigned alignment = 64; + + region->cpp = cpp; + region->pitch = round_up(width, alignment / cpp); + region->height = height; + region->refcount = 1; + + assert(region->pitch > 0); + + region->buffer = winsys->buffer_create( winsys, alignment ) +; + + /* NULL data --> just allocate the space */ + winsys->buffer_data( winsys, + region->buffer, + region->pitch * cpp * height, + NULL ); + return region; +} + + +static void +xm_region_release(struct pipe_winsys *winsys, struct pipe_region **region) +{ + if (!*region) + return; + + assert((*region)->refcount > 0); + (*region)->refcount--; + + if ((*region)->refcount == 0) { + assert((*region)->map_refcount == 0); + + winsys->buffer_reference( winsys, &((*region)->buffer), NULL ); + free(*region); + } + *region = NULL; +} + + + struct xmesa_pipe_winsys { struct pipe_winsys winsys; @@ -259,6 +316,10 @@ xmesa_create_pipe_winsys( XMesaContext xmesa ) xws->winsys.buffer_data = xm_buffer_data; xws->winsys.buffer_subdata = xm_buffer_subdata; xws->winsys.buffer_get_subdata = xm_buffer_get_subdata; + + xws->winsys.region_alloc = xm_region_alloc; + xws->winsys.region_release = xm_region_release; + xws->winsys.flush_frontbuffer = xm_flush_frontbuffer; xws->winsys.wait_idle = xm_wait_idle; xws->winsys.printf = xm_printf; @@ -272,27 +333,9 @@ xmesa_create_pipe_winsys( XMesaContext xmesa ) struct pipe_context * xmesa_create_softpipe(XMesaContext xmesa) { - struct xm_winsys *isws = CALLOC_STRUCT( xm_winsys ); + struct xm_winsys *xm_ws = CALLOC_STRUCT( xm_winsys ); - /* Fill in this struct with callbacks that softpipe will need to - * communicate with the window system, buffer manager, etc. - * - * Softpipe would be happy with a malloc based memory manager, but - * the SwapBuffers implementation in this winsys driver requires - * that rendering be done to an appropriate xm_buffer. - */ -#if 0 - isws->sws.create_buffer = xm_create_buffer; - isws->sws.buffer_map = xm_buffer_map; - isws->sws.buffer_unmap = xm_buffer_unmap; - isws->sws.buffer_reference = xm_buffer_reference; - isws->sws.buffer_unreference = xm_buffer_unreference; - isws->sws.buffer_data = xm_buffer_data; - isws->sws.buffer_subdata = xm_buffer_subdata; - isws->sws.buffer_get_subdata = xm_buffer_get_subdata; -#endif - /* Create the softpipe context: */ - return softpipe_create( xmesa_create_pipe_winsys(xmesa), &isws->sws ); + return softpipe_create( xmesa_create_pipe_winsys(xmesa), &xm_ws->sws ); } diff --git a/src/mesa/pipe/failover/fo_context.c b/src/mesa/pipe/failover/fo_context.c index 076d516583..a3a0296598 100644 --- a/src/mesa/pipe/failover/fo_context.c +++ b/src/mesa/pipe/failover/fo_context.c @@ -137,8 +137,6 @@ struct pipe_context *failover_create( struct pipe_context *hw, failover->pipe.surface_alloc = hw->surface_alloc; failover->pipe.get_tex_surface = hw->get_tex_surface; - failover->pipe.region_alloc = hw->region_alloc; - failover->pipe.region_release = hw->region_release; failover->pipe.region_map = hw->region_map; failover->pipe.region_unmap = hw->region_unmap; failover->pipe.region_data = hw->region_data; diff --git a/src/mesa/pipe/i915simple/i915_regions.c b/src/mesa/pipe/i915simple/i915_regions.c index 577a6adfd8..0410446326 100644 --- a/src/mesa/pipe/i915simple/i915_regions.c +++ b/src/mesa/pipe/i915simple/i915_regions.c @@ -69,65 +69,6 @@ i915_region_unmap(struct pipe_context *pipe, struct pipe_region *region) } } -static struct pipe_region * -i915_region_alloc(struct pipe_context *pipe, - unsigned cpp, unsigned width, unsigned height, unsigned flags) -{ - struct i915_context *i915 = i915_context( pipe ); - struct pipe_region *region = calloc(sizeof(*region), 1); - const unsigned alignment = 64; - - /* Choose a pitch to match hardware requirements - requires 64 byte - * alignment of render targets. - * - * XXX: is this ok for textures?? - * clearly want to be able to render to textures under some - * circumstances, but maybe not always a requirement. - */ - unsigned pitch; - - /* XXX is the pitch different for textures vs. drawables? */ - if (flags & PIPE_SURFACE_FLAG_TEXTURE) /* or PIPE_SURFACE_FLAG_RENDER? */ - pitch = ((cpp * width + 63) & ~63) / cpp; - else - pitch = ((cpp * width + 63) & ~63) / cpp; - - region->cpp = cpp; - region->pitch = pitch; - region->height = height; /* needed? */ - region->refcount = 1; - - region->buffer = i915->pipe.winsys->buffer_create( i915->pipe.winsys, alignment ); - - i915->pipe.winsys->buffer_data( i915->pipe.winsys, - region->buffer, - pitch * cpp * height, - NULL ); - - return region; -} - -static void -i915_region_release(struct pipe_context *pipe, struct pipe_region **region) -{ - struct i915_context *i915 = i915_context( pipe ); - - if (!*region) - return; - - assert((*region)->refcount > 0); - (*region)->refcount--; - - if ((*region)->refcount == 0) { - assert((*region)->map_refcount == 0); - - i915->pipe.winsys->buffer_reference( i915->pipe.winsys, - &((*region)->buffer), NULL ); - free(*region); - } - *region = NULL; -} - /* * XXX Move this into core Mesa? @@ -302,8 +243,6 @@ i915_init_region_functions(struct i915_context *i915) { i915->pipe.region_map = i915_region_map; i915->pipe.region_unmap = i915_region_unmap; - i915->pipe.region_alloc = i915_region_alloc; - i915->pipe.region_release = i915_region_release; i915->pipe.region_data = i915_region_data; i915->pipe.region_copy = i915_region_copy; i915->pipe.region_fill = i915_region_fill; diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index a22ea3a8a0..b9de3667e5 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -208,14 +208,7 @@ struct pipe_context { /* * Memory region functions - * Some of these may go away... */ - struct pipe_region *(*region_alloc)(struct pipe_context *pipe, - unsigned cpp, unsigned width, unsigned height, - unsigned flags); - - void (*region_release)(struct pipe_context *pipe, struct pipe_region **r); - ubyte *(*region_map)(struct pipe_context *pipe, struct pipe_region *r); void (*region_unmap)(struct pipe_context *pipe, struct pipe_region *r); @@ -225,7 +218,8 @@ struct pipe_context { unsigned dest_offset, unsigned destx, unsigned desty, const void *src, unsigned src_stride, - unsigned srcx, unsigned srcy, unsigned width, unsigned height); + unsigned srcx, unsigned srcy, + unsigned width, unsigned height); void (*region_copy)(struct pipe_context *pipe, struct pipe_region *dest, @@ -234,7 +228,8 @@ struct pipe_context { struct pipe_region *src, /* don't make this const - need to map/unmap */ unsigned src_offset, - unsigned srcx, unsigned srcy, unsigned width, unsigned height); + unsigned srcx, unsigned srcy, + unsigned width, unsigned height); void (*region_fill)(struct pipe_context *pipe, struct pipe_region *dst, diff --git a/src/mesa/pipe/p_winsys.h b/src/mesa/pipe/p_winsys.h index 7e5d394a90..3b04c44733 100644 --- a/src/mesa/pipe/p_winsys.h +++ b/src/mesa/pipe/p_winsys.h @@ -50,6 +50,13 @@ struct pipe_buffer_handle; * driver and the hardware driver about the format of command buffers, * etc. */ + + +struct pipe_region; + +/** Opaque type */ +struct pipe_buffer_handle; + struct pipe_winsys { /** @@ -63,6 +70,13 @@ struct pipe_winsys const char *, ... ); + struct pipe_region *(*region_alloc)(struct pipe_winsys *ws, + unsigned cpp, unsigned width, + unsigned height, unsigned flags); + + void (*region_release)(struct pipe_winsys *ws, struct pipe_region **r); + + /** * The buffer manager is modeled after the dri_bufmgr interface, which * in turn is modeled after the ARB_vertex_buffer_object extension, diff --git a/src/mesa/pipe/softpipe/sp_region.c b/src/mesa/pipe/softpipe/sp_region.c index 4317a9ea1b..80a67dcabc 100644 --- a/src/mesa/pipe/softpipe/sp_region.c +++ b/src/mesa/pipe/softpipe/sp_region.c @@ -38,16 +38,6 @@ #include "pipe/p_defines.h" -/** - * Round n up to next multiple. - */ -static INLINE unsigned -round_up(unsigned n, unsigned multiple) -{ - return (n + multiple - 1) & ~(multiple - 1); -} - - static ubyte * sp_region_map(struct pipe_context *pipe, struct pipe_region *region) @@ -79,51 +69,6 @@ sp_region_unmap(struct pipe_context *pipe, struct pipe_region *region) } } -static struct pipe_region * -sp_region_alloc(struct pipe_context *pipe, - unsigned cpp, unsigned width, unsigned height, unsigned flags) -{ - struct softpipe_context *sp = softpipe_context( pipe ); - struct pipe_region *region = CALLOC_STRUCT(pipe_region); - const unsigned alignment = 64; - - region->cpp = cpp; - region->pitch = round_up(width, alignment / cpp); - region->height = height; - region->refcount = 1; - - assert(region->pitch > 0); - - region->buffer = sp->pipe.winsys->buffer_create( sp->pipe.winsys, alignment ); - - /* NULL data --> just allocate the space */ - sp->pipe.winsys->buffer_data( sp->pipe.winsys, - region->buffer, - region->pitch * cpp * height, - NULL ); - return region; -} - -static void -sp_region_release(struct pipe_context *pipe, struct pipe_region **region) -{ - struct softpipe_context *sp = softpipe_context( pipe ); - - if (!*region) - return; - - assert((*region)->refcount > 0); - (*region)->refcount--; - - if ((*region)->refcount == 0) { - assert((*region)->map_refcount == 0); - - sp->pipe.winsys->buffer_reference( sp->pipe.winsys, - &((*region)->buffer), NULL ); - free(*region); - } - *region = NULL; -} /** @@ -313,8 +258,6 @@ sp_init_region_functions(struct softpipe_context *sp) { sp->pipe.region_map = sp_region_map; sp->pipe.region_unmap = sp_region_unmap; - sp->pipe.region_alloc = sp_region_alloc; - sp->pipe.region_release = sp_region_release; sp->pipe.region_data = sp_region_data; sp->pipe.region_copy = sp_region_copy; sp->pipe.region_fill = sp_region_fill; diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index c4a954c43d..5d8890e022 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -47,6 +47,7 @@ #include "st_format.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "pipe/p_winsys.h" #include "pipe/tgsi/mesa/mesa_to_tgsi.h" #include "shader/prog_instruction.h" @@ -346,7 +347,8 @@ alloc_mipmap_tree(struct st_context *st, cpp = st_sizeof_format(pipeFormat); /* allocate texture region/storage */ - mt->region = st->pipe->region_alloc(st->pipe, cpp, width, height, flags); + mt->region = st->pipe->winsys->region_alloc(st->pipe->winsys, + cpp, width, height, flags); mt->target = PIPE_TEXTURE_2D; mt->internal_format = GL_RGBA; @@ -468,7 +470,7 @@ make_mipmap_tree(struct st_context *st, static void free_mipmap_tree(struct pipe_context *pipe, struct pipe_mipmap_tree *mt) { - pipe->region_release(pipe, &mt->region); + pipe->winsys->region_release(pipe->winsys, &mt->region); free(mt); } @@ -977,7 +979,8 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, /* allocate texture region/storage */ - mt->region = pipe->region_alloc(pipe, cpp, width, height, flags); + mt->region = pipe->winsys->region_alloc(pipe->winsys, + cpp, width, height, flags); pitch = mt->region->pitch; /* map texture region */ diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 94e286feab..f22132b3cf 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -41,6 +41,7 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "pipe/p_winsys.h" #include "st_context.h" #include "st_cb_fbo.h" #include "st_cb_texture.h" @@ -95,10 +96,11 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, struct pipe_region *r = strb->surface->region; while (r->map) pipe->region_unmap(pipe, r); - pipe->region_release(pipe, &strb->surface->region); + pipe->winsys->region_release(pipe->winsys, &strb->surface->region); } - strb->surface->region = pipe->region_alloc(pipe, cpp, width, height, flags); + strb->surface->region = pipe->winsys->region_alloc(pipe->winsys, cpp, + width, height, flags); if (!strb->surface->region) return GL_FALSE; /* out of memory, try s/w buffer? */ @@ -125,7 +127,7 @@ st_renderbuffer_delete(struct gl_renderbuffer *rb) ASSERT(strb); if (strb && strb->surface) { if (strb->surface->region) { - pipe->region_release(pipe, &strb->surface->region); + pipe->winsys->region_release(pipe->winsys, &strb->surface->region); } free(strb->surface); } diff --git a/src/mesa/state_tracker/st_mipmap_tree.c b/src/mesa/state_tracker/st_mipmap_tree.c index faca148d80..d1db590bee 100644 --- a/src/mesa/state_tracker/st_mipmap_tree.c +++ b/src/mesa/state_tracker/st_mipmap_tree.c @@ -31,6 +31,7 @@ #include "pipe/p_state.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "pipe/p_winsys.h" #define DBG if(0) printf @@ -87,8 +88,8 @@ st_miptree_create(struct pipe_context *pipe, ok = pipe->mipmap_tree_layout(pipe, mt); if (ok) { /* note: it's OK to pass 'pitch' as 'width' here: */ - mt->region = pipe->region_alloc(pipe, mt->cpp, mt->pitch, - mt->total_height, flags); + mt->region = pipe->winsys->region_alloc(pipe->winsys, mt->cpp, mt->pitch, + mt->total_height, flags); mt->pitch = mt->region->pitch; /*XXX NEW */ } @@ -124,7 +125,7 @@ st_miptree_release(struct pipe_context *pipe, DBG("%s deleting %p\n", __FUNCTION__, (void *) *mt); - pipe->region_release(pipe, &((*mt)->region)); + pipe->winsys->region_release(pipe->winsys, &((*mt)->region)); for (i = 0; i < MAX_TEXTURE_LEVELS; i++) if ((*mt)->level[i].image_offset) -- cgit v1.2.3 From e4f6f0ec02133e9297c3f2db787dee14bf0ae6e1 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 26 Oct 2007 10:45:42 -0600 Subject: surface_alloc() is now a winsys function. This allows surfaces to be allocated without a rendering context. A few loose ends to resolve, but in working condition. --- .../drivers/dri/intel_winsys/intel_winsys_pipe.c | 14 ++ src/mesa/drivers/x11/xm_api.c | 7 + src/mesa/drivers/x11/xm_surface.c | 123 +++++++++----- src/mesa/drivers/x11/xm_winsys.c | 27 +++ src/mesa/drivers/x11/xmesaP.h | 13 +- src/mesa/pipe/failover/fo_context.c | 2 + src/mesa/pipe/i915simple/i915_surface.c | 189 ++++++++++++++++----- src/mesa/pipe/p_context.h | 9 +- src/mesa/pipe/p_winsys.h | 4 + src/mesa/pipe/softpipe/sp_surface.c | 107 +++++++++--- src/mesa/pipe/softpipe/sp_surface.h | 15 +- src/mesa/state_tracker/st_cb_fbo.c | 2 +- 12 files changed, 393 insertions(+), 119 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c b/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c index 6f244e1100..4569b1e3bf 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c @@ -253,6 +253,18 @@ intel_i915_region_release(struct pipe_winsys *winsys, } +static struct pipe_surface * +intel_i915_surface_alloc(struct pipe_winsys *winsys, unsigned format) +{ + struct pipe_surface *surf = CALLOC_STRUCT(pipe_surface); + if (surf) { + surf->format = format; + surf->refcount = 1; + } + return surf; +} + + static void intel_printf( struct pipe_winsys *sws, const char *fmtString, ... ) { @@ -298,5 +310,7 @@ intel_create_pipe_winsys( struct intel_context *intel ) iws->winsys.region_alloc = intel_i915_region_alloc; iws->winsys.region_release = intel_i915_region_release; + iws->winsys.surface_alloc = intel_i915_surface_alloc; + return &iws->winsys; } diff --git a/src/mesa/drivers/x11/xm_api.c b/src/mesa/drivers/x11/xm_api.c index 187663e66c..1d2b93d100 100644 --- a/src/mesa/drivers/x11/xm_api.c +++ b/src/mesa/drivers/x11/xm_api.c @@ -1610,8 +1610,15 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) st_create_context( mesaCtx, xmesa_create_softpipe( c ) ); + /* override these functions, as if the xlib driver were derived from + * the softpipe driver. + */ +#if 0 mesaCtx->st->pipe->surface_alloc = xmesa_surface_alloc; +#endif mesaCtx->st->pipe->supported_formats = xmesa_supported_formats; + mesaCtx->st->pipe->get_tile_rgba = xmesa_get_tile_rgba; + mesaCtx->st->pipe->put_tile_rgba = xmesa_put_tile_rgba; mesaCtx->st->haveFramebufferRegions = GL_FALSE; diff --git a/src/mesa/drivers/x11/xm_surface.c b/src/mesa/drivers/x11/xm_surface.c index 337033f8ad..3655a55e4e 100644 --- a/src/mesa/drivers/x11/xm_surface.c +++ b/src/mesa/drivers/x11/xm_surface.c @@ -48,6 +48,7 @@ #include "pipe/softpipe/sp_context.h" #include "pipe/softpipe/sp_clear.h" #include "pipe/softpipe/sp_tile_cache.h" +#include "pipe/softpipe/sp_surface.h" #include "state_tracker/st_context.h" @@ -67,6 +68,13 @@ xmesa_surf(struct softpipe_surface *sps) } +static INLINE struct xmesa_surface * +xmesa_surface(struct pipe_surface *ps) +{ + return (struct xmesa_surface *) ps; +} + + static INLINE struct xmesa_renderbuffer * xmesa_rb(struct softpipe_surface *sps) { @@ -78,53 +86,71 @@ xmesa_rb(struct softpipe_surface *sps) #define FLIP(Y) Y = xrb->St.Base.Height - (Y) - 1; -static void -get_tile(struct pipe_surface *ps, - uint x, uint y, uint w, uint h, float *p) +void +xmesa_get_tile_rgba(struct pipe_context *pipe, struct pipe_surface *ps, + uint x, uint y, uint w, uint h, float *p) { - struct xmesa_renderbuffer *xrb = xmesa_rb((struct softpipe_surface *) ps); - GLubyte tmp[MAX_WIDTH * 4]; - GLuint i, j; - uint w0 = w; - GET_CURRENT_CONTEXT(ctx); - - CLIP_TILE; - - FLIP(y); - for (i = 0; i < h; i++) { - xrb->St.Base.GetRow(ctx, &xrb->St.Base, w, x, y - i, tmp); - for (j = 0; j < w * 4; j++) { - p[j] = UBYTE_TO_FLOAT(tmp[j]); + struct xmesa_surface *xms = xmesa_surface(ps); + struct xmesa_renderbuffer *xrb = xms->xrb; + + if (xrb) { + /* this is a front/back color buffer */ + GLubyte tmp[MAX_WIDTH * 4]; + GLuint i, j; + uint w0 = w; + GET_CURRENT_CONTEXT(ctx); + + CLIP_TILE; + + FLIP(y); + for (i = 0; i < h; i++) { + xrb->St.Base.GetRow(ctx, &xrb->St.Base, w, x, y - i, tmp); + for (j = 0; j < w * 4; j++) { + p[j] = UBYTE_TO_FLOAT(tmp[j]); + } + p += w0 * 4; } - p += w0 * 4; + } + else { + /* other softpipe surface */ + softpipe_get_tile_rgba(pipe, ps, x, y, w, h, p); } } -static void -put_tile(struct pipe_surface *ps, - uint x, uint y, uint w, uint h, const float *p) +void +xmesa_put_tile_rgba(struct pipe_context *pipe, struct pipe_surface *ps, + uint x, uint y, uint w, uint h, const float *p) { - struct xmesa_renderbuffer *xrb = xmesa_rb((struct softpipe_surface *) ps); - GLubyte tmp[MAX_WIDTH * 4]; - GLuint i, j; - uint w0 = w; - GET_CURRENT_CONTEXT(ctx); - CLIP_TILE; - FLIP(y); - for (i = 0; i < h; i++) { - for (j = 0; j < w * 4; j++) { - UNCLAMPED_FLOAT_TO_UBYTE(tmp[j], p[j]); + struct xmesa_surface *xms = xmesa_surface(ps); + struct xmesa_renderbuffer *xrb = xms->xrb; + + if (xrb) { + /* this is a front/back color buffer */ + GLubyte tmp[MAX_WIDTH * 4]; + GLuint i, j; + uint w0 = w; + GET_CURRENT_CONTEXT(ctx); + CLIP_TILE; + FLIP(y); + for (i = 0; i < h; i++) { + for (j = 0; j < w * 4; j++) { + UNCLAMPED_FLOAT_TO_UBYTE(tmp[j], p[j]); + } + xrb->St.Base.PutRow(ctx, &xrb->St.Base, w, x, y - i, tmp, NULL); + p += w0 * 4; } - xrb->St.Base.PutRow(ctx, &xrb->St.Base, w, x, y - i, tmp, NULL); - p += w0 * 4; - } #if 0 /* debug: flush */ - { - XMesaContext xm = XMESA_CONTEXT(ctx); - XSync(xm->display, 0); - } + { + XMesaContext xm = XMESA_CONTEXT(ctx); + XSync(xm->display, 0); + } #endif + } + else { + /* other softpipe surface */ + softpipe_put_tile_rgba(pipe, ps, x, y, w, h, p); + } } @@ -141,12 +167,15 @@ xmesa_new_color_surface(struct pipe_context *pipe, GLuint pipeFormat) assert(pipeFormat); - xms->surface.surface.format = pipeFormat; - xms->surface.surface.refcount = 1; + xms->surface.format = pipeFormat; + xms->surface.refcount = 1; +#if 0 /* some of the functions plugged in by this call will get overridden */ softpipe_init_surface_funcs(&xms->surface); +#endif +#if 0 switch (pipeFormat) { case PIPE_FORMAT_U_A8_R8_G8_B8: xms->surface.get_tile = get_tile; @@ -157,6 +186,7 @@ xmesa_new_color_surface(struct pipe_context *pipe, GLuint pipeFormat) default: abort(); } +#endif /* Note, the region we allocate doesn't actually have any storage * since we're drawing into an XImage or Pixmap. @@ -164,10 +194,10 @@ xmesa_new_color_surface(struct pipe_context *pipe, GLuint pipeFormat) * functions. */ if (pipe) - xms->surface.surface.region = pipe->winsys->region_alloc(pipe->winsys, - 1, 0, 0, 0x0); + xms->surface.region = pipe->winsys->region_alloc(pipe->winsys, + 1, 0, 0, 0x0); - return &xms->surface.surface; + return &xms->surface; } @@ -183,14 +213,15 @@ xmesa_surface_alloc(struct pipe_context *pipe, GLuint pipeFormat) assert(pipe); assert(pipeFormat); - xms->surface.surface.format = pipeFormat; - xms->surface.surface.refcount = 1; + xms->surface.format = pipeFormat; + xms->surface.refcount = 1; +#if 0 /* * This is really just a softpipe surface, not an XImage/Pixmap surface. */ softpipe_init_surface_funcs(&xms->surface); - - return &xms->surface.surface; +#endif + return &xms->surface; } diff --git a/src/mesa/drivers/x11/xm_winsys.c b/src/mesa/drivers/x11/xm_winsys.c index 624d28dd01..36805437f0 100644 --- a/src/mesa/drivers/x11/xm_winsys.c +++ b/src/mesa/drivers/x11/xm_winsys.c @@ -289,6 +289,31 @@ xm_region_release(struct pipe_winsys *winsys, struct pipe_region **region) } +/** + * Called via pipe->surface_alloc() to create new surfaces (textures, + * renderbuffers, etc. + */ +static struct pipe_surface * +xm_surface_alloc(struct pipe_winsys *ws, GLuint pipeFormat) +{ + struct xmesa_surface *xms = CALLOC_STRUCT(xmesa_surface); + + assert(ws); + assert(pipeFormat); + + xms->surface.format = pipeFormat; + xms->surface.refcount = 1; +#if 0 + /* + * This is really just a softpipe surface, not an XImage/Pixmap surface. + */ + softpipe_init_surface_funcs(&xms->surface); +#endif + return &xms->surface; +} + + + struct xmesa_pipe_winsys { @@ -320,6 +345,8 @@ xmesa_create_pipe_winsys( XMesaContext xmesa ) xws->winsys.region_alloc = xm_region_alloc; xws->winsys.region_release = xm_region_release; + xws->winsys.surface_alloc = xm_surface_alloc; + xws->winsys.flush_frontbuffer = xm_flush_frontbuffer; xws->winsys.wait_idle = xm_wait_idle; xws->winsys.printf = xm_printf; diff --git a/src/mesa/drivers/x11/xmesaP.h b/src/mesa/drivers/x11/xmesaP.h index 9cbe8670f9..8af95504fb 100644 --- a/src/mesa/drivers/x11/xmesaP.h +++ b/src/mesa/drivers/x11/xmesaP.h @@ -598,7 +598,7 @@ struct pipe_context; struct xmesa_surface { - struct softpipe_surface surface; + struct pipe_surface surface; struct xmesa_renderbuffer *xrb; }; @@ -618,8 +618,15 @@ xmesa_surface_alloc(struct pipe_context *pipe, GLuint format); extern struct pipe_surface * xmesa_new_color_surface(struct pipe_context *pipe, GLuint format); -extern const GLuint * -xmesa_supported_formats(struct pipe_context *pipe, GLuint *numFormats); +extern const uint * +xmesa_supported_formats(struct pipe_context *pipe, uint *numFormats); +extern void +xmesa_get_tile_rgba(struct pipe_context *pipe, struct pipe_surface *ps, + uint x, uint y, uint w, uint h, float *p); + +extern void +xmesa_put_tile_rgba(struct pipe_context *pipe, struct pipe_surface *ps, + uint x, uint y, uint w, uint h, const float *p); #endif diff --git a/src/mesa/pipe/failover/fo_context.c b/src/mesa/pipe/failover/fo_context.c index a3a0296598..7e02b751bb 100644 --- a/src/mesa/pipe/failover/fo_context.c +++ b/src/mesa/pipe/failover/fo_context.c @@ -134,7 +134,9 @@ struct pipe_context *failover_create( struct pipe_context *hw, failover_init_state_functions( failover ); +#if 0 failover->pipe.surface_alloc = hw->surface_alloc; +#endif failover->pipe.get_tex_surface = hw->get_tex_surface; failover->pipe.region_map = hw->region_map; diff --git a/src/mesa/pipe/i915simple/i915_surface.c b/src/mesa/pipe/i915simple/i915_surface.c index a07a21c13b..b4b5bd1ce5 100644 --- a/src/mesa/pipe/i915simple/i915_surface.c +++ b/src/mesa/pipe/i915simple/i915_surface.c @@ -29,13 +29,20 @@ #include "i915_state.h" #include "pipe/p_defines.h" #include "pipe/p_util.h" +#include "pipe/p_winsys.h" -struct i915_surface -{ - struct pipe_surface surface; - /* anything else? */ -}; +#define CLIP_TILE \ + do { \ + if (x >= ps->width) \ + return; \ + if (y >= ps->height) \ + return; \ + if (x + w > ps->width) \ + w = ps->width - x; \ + if (y + h > ps->height) \ + h = ps->height -y; \ + } while(0) /** @@ -53,30 +60,44 @@ i915_get_tile_rgba(struct pipe_context *pipe, unsigned i, j; unsigned w0 = w; - assert(ps->format == PIPE_FORMAT_U_A8_R8_G8_B8); - -#if 0 - assert(x + w <= ps->width); - assert(y + h <= ps->height); -#else - /* temp clipping hack */ - if (x + w > ps->width) - w = ps->width - x; - if (y + h > ps->height) - h = ps->height -y; -#endif - for (i = 0; i < h; i++) { - float *pRow = p; - for (j = 0; j < w; j++) { - const unsigned pixel = src[j]; - pRow[0] = UBYTE_TO_FLOAT((pixel >> 16) & 0xff); - pRow[1] = UBYTE_TO_FLOAT((pixel >> 8) & 0xff); - pRow[2] = UBYTE_TO_FLOAT((pixel >> 0) & 0xff); - pRow[3] = UBYTE_TO_FLOAT((pixel >> 24) & 0xff); - pRow += 4; + CLIP_TILE; + + switch (ps->format) { + case PIPE_FORMAT_U_A8_R8_G8_B8: + for (i = 0; i < h; i++) { + float *pRow = p; + for (j = 0; j < w; j++) { + const unsigned pixel = src[j]; + pRow[0] = UBYTE_TO_FLOAT((pixel >> 16) & 0xff); + pRow[1] = UBYTE_TO_FLOAT((pixel >> 8) & 0xff); + pRow[2] = UBYTE_TO_FLOAT((pixel >> 0) & 0xff); + pRow[3] = UBYTE_TO_FLOAT((pixel >> 24) & 0xff); + pRow += 4; + } + src += ps->region->pitch; + p += w0 * 4; + } + break; + case PIPE_FORMAT_S8_Z24: + { + const float scale = 1.0 / (float) 0xffffff; + for (i = 0; i < h; i++) { + float *pRow = p; + for (j = 0; j < w; j++) { + const unsigned pixel = src[j]; + pRow[0] = + pRow[1] = + pRow[2] = + pRow[3] = (pixel & 0xffffff) * scale; + pRow += 4; + } + src += ps->region->pitch; + p += w0 * 4; + } } - src += ps->region->pitch; - p += w0 * 4; + break; + default: + assert(0); } } @@ -86,34 +107,122 @@ i915_put_tile_rgba(struct pipe_context *pipe, struct pipe_surface *ps, uint x, uint y, uint w, uint h, const float *p) { - /* any need to put tiles into i915 surfaces? */ + /* TODO */ assert(0); } +/* + * XXX note: same as code in sp_surface.c + */ +static void +i915_get_tile(struct pipe_context *pipe, + struct pipe_surface *ps, + uint x, uint y, uint w, uint h, + void *p, int dst_stride) +{ + const uint cpp = ps->region->cpp; + const uint w0 = w; + const ubyte *pSrc; + ubyte *pDest; + uint i; -static struct pipe_surface * -i915_surface_alloc(struct pipe_context *pipe, unsigned format) + assert(ps->region->map); + + CLIP_TILE; + + if (dst_stride == 0) { + dst_stride = w0 * cpp; + } + + pSrc = ps->region->map + ps->offset + (y * ps->region->pitch + x) * cpp; + pDest = (ubyte *) p; + + for (i = 0; i < h; i++) { + memcpy(pDest, pSrc, w0 * cpp); + pDest += dst_stride; + pSrc += ps->region->pitch * cpp; + } +} + + +/* + * XXX note: same as code in sp_surface.c + */ +static void +i915_put_tile(struct pipe_context *pipe, + struct pipe_surface *ps, + uint x, uint y, uint w, uint h, + const void *p, int src_stride) { - struct i915_surface *surf = CALLOC_STRUCT(i915_surface); + const uint cpp = ps->region->cpp; + const uint w0 = w; + const ubyte *pSrc; + ubyte *pDest; + uint i; + + assert(ps->region->map); + + CLIP_TILE; + + if (src_stride == 0) { + src_stride = w0 * cpp; + } + + pSrc = (const ubyte *) p; + pDest = ps->region->map + ps->offset + (y * ps->region->pitch + x) * cpp; + + for (i = 0; i < h; i++) { + memcpy(pDest, pSrc, w0 * cpp); + pDest += ps->region->pitch * cpp; + pSrc += src_stride; + } +} - if (!surf) - return NULL; - surf->surface.format = format; - surf->surface.refcount = 1; +/* + * XXX note: same as code in sp_surface.c + */ +static struct pipe_surface * +i915_get_tex_surface(struct pipe_context *pipe, + struct pipe_mipmap_tree *mt, + unsigned face, unsigned level, unsigned zslice) +{ + struct pipe_surface *ps; + unsigned offset; /* in bytes */ - // surf->surface.get_tile = i915_get_tile; - // surf->surface.put_tile = i915_put_tile; + offset = mt->level[level].level_offset; - return &surf->surface; + if (mt->target == PIPE_TEXTURE_CUBE) { + offset += mt->level[level].image_offset[face] * mt->cpp; + } + else if (mt->target == PIPE_TEXTURE_3D) { + offset += mt->level[level].image_offset[zslice] * mt->cpp; + } + else { + assert(face == 0); + assert(zslice == 0); + } + + ps = pipe->winsys->surface_alloc(pipe->winsys, mt->format); + if (ps) { + assert(ps->format); + assert(ps->refcount); + pipe_region_reference(&ps->region, mt->region); + ps->width = mt->level[level].width; + ps->height = mt->level[level].height; + ps->offset = offset; + } + return ps; } void i915_init_surface_functions(struct i915_context *i915) { - i915->pipe.surface_alloc = i915_surface_alloc; + i915->pipe.get_tex_surface = i915_get_tex_surface; + i915->pipe.get_tile = i915_get_tile; + i915->pipe.put_tile = i915_put_tile; i915->pipe.get_tile_rgba = i915_get_tile_rgba; i915->pipe.put_tile_rgba = i915_put_tile_rgba; } diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index b9de3667e5..3a041f158b 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -176,13 +176,7 @@ struct pipe_context { unsigned index, const struct pipe_feedback_buffer *); - /* - * Surface functions - * This might go away... - */ - struct pipe_surface *(*surface_alloc)(struct pipe_context *pipe, - unsigned format); - + /** Get a surface which is a "view" into a texture */ struct pipe_surface *(*get_tex_surface)(struct pipe_context *pipe, struct pipe_mipmap_tree *texture, unsigned face, unsigned level, @@ -198,7 +192,6 @@ struct pipe_context { struct pipe_surface *ps, uint x, uint y, uint w, uint h, const void *p, int src_stride); - /* XXX temporary here, move these to softpipe */ void (*get_tile_rgba)(struct pipe_context *pipe, struct pipe_surface *ps, uint x, uint y, uint w, uint h, float *p); diff --git a/src/mesa/pipe/p_winsys.h b/src/mesa/pipe/p_winsys.h index 3b04c44733..10a2caf1a2 100644 --- a/src/mesa/pipe/p_winsys.h +++ b/src/mesa/pipe/p_winsys.h @@ -77,6 +77,10 @@ struct pipe_winsys void (*region_release)(struct pipe_winsys *ws, struct pipe_region **r); + /** allocate a new surface (no context dependency) */ + struct pipe_surface *(*surface_alloc)(struct pipe_winsys *ws, + unsigned format); + /** * The buffer manager is modeled after the dri_bufmgr interface, which * in turn is modeled after the ARB_vertex_buffer_object extension, diff --git a/src/mesa/pipe/softpipe/sp_surface.c b/src/mesa/pipe/softpipe/sp_surface.c index 4accafa384..d1aa2aba97 100644 --- a/src/mesa/pipe/softpipe/sp_surface.c +++ b/src/mesa/pipe/softpipe/sp_surface.c @@ -27,6 +27,7 @@ #include "pipe/p_defines.h" #include "pipe/p_util.h" +#include "pipe/p_winsys.h" #include "sp_context.h" #include "sp_state.h" #include "sp_surface.h" @@ -361,7 +362,7 @@ i8_get_tile(struct pipe_surface *ps, static void a8_l8_get_tile(struct pipe_surface *ps, - unsigned x, unsigned y, unsigned w, unsigned h, float *p) + unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const ushort *src = ((const ushort *) (ps->region->map + ps->offset)) @@ -466,7 +467,7 @@ void softpipe_init_surface_funcs(struct softpipe_surface *sps) { assert(sps->surface.format); - +#if 0 switch (sps->surface.format) { case PIPE_FORMAT_U_A8_R8_G8_B8: sps->get_tile = a8r8g8b8_get_tile; @@ -507,6 +508,7 @@ softpipe_init_surface_funcs(struct softpipe_surface *sps) default: assert(0); } +#endif } @@ -555,7 +557,7 @@ softpipe_get_tex_surface(struct pipe_context *pipe, assert(zslice == 0); } - ps = pipe->surface_alloc(pipe, mt->format); + ps = pipe->winsys->surface_alloc(pipe->winsys, mt->format); if (ps) { assert(ps->format); assert(ps->refcount); @@ -637,26 +639,90 @@ softpipe_put_tile(struct pipe_context *pipe, /* XXX TEMPORARY */ -static void -get_tile_rgba_generic(struct pipe_context *pipe, - struct pipe_surface *ps, - uint x, uint y, uint w, uint h, - float *p) +void +softpipe_get_tile_rgba(struct pipe_context *pipe, + struct pipe_surface *ps, + uint x, uint y, uint w, uint h, + float *p) { - struct softpipe_surface *sps = softpipe_surface(ps); - sps->get_tile(ps, x, y, w, h, p); + switch (ps->format) { + case PIPE_FORMAT_U_A8_R8_G8_B8: + a8r8g8b8_get_tile(ps, x, y, w, h, p); + break; + case PIPE_FORMAT_U_A1_R5_G5_B5: + a1r5g5b5_get_tile(ps, x, y, w, h, p); + break; + case PIPE_FORMAT_U_L8: + l8_get_tile(ps, x, y, w, h, p); + break; + case PIPE_FORMAT_U_A8: + a8_get_tile(ps, x, y, w, h, p); + break; + case PIPE_FORMAT_U_I8: + i8_get_tile(ps, x, y, w, h, p); + break; + case PIPE_FORMAT_U_A8_L8: + a8_l8_get_tile(ps, x, y, w, h, p); + break; + case PIPE_FORMAT_S_R16_G16_B16_A16: + r16g16b16a16_get_tile(ps, x, y, w, h, p); + break; + case PIPE_FORMAT_U_Z16: + z16_get_tile(ps, x, y, w, h, p); + break; + case PIPE_FORMAT_U_Z32: + z32_get_tile(ps, x, y, w, h, p); + break; + case PIPE_FORMAT_S8_Z24: + s8z24_get_tile(ps, x, y, w, h, p); + break; + default: + assert(0); + } } /* XXX TEMPORARY */ -static void -put_tile_rgba_generic(struct pipe_context *pipe, - struct pipe_surface *ps, - uint x, uint y, uint w, uint h, - const float *p) +void +softpipe_put_tile_rgba(struct pipe_context *pipe, + struct pipe_surface *ps, + uint x, uint y, uint w, uint h, + const float *p) { - struct softpipe_surface *sps = softpipe_surface(ps); - sps->put_tile(ps, x, y, w, h, p); + switch (ps->format) { + case PIPE_FORMAT_U_A8_R8_G8_B8: + a8r8g8b8_put_tile(ps, x, y, w, h, p); + break; + case PIPE_FORMAT_U_A1_R5_G5_B5: + /*a1r5g5b5_put_tile(ps, x, y, w, h, p);*/ + break; + case PIPE_FORMAT_U_L8: + /*l8_put_tile(ps, x, y, w, h, p);*/ + break; + case PIPE_FORMAT_U_A8: + /*a8_put_tile(ps, x, y, w, h, p);*/ + break; + case PIPE_FORMAT_U_I8: + /*i8_put_tile(ps, x, y, w, h, p);*/ + break; + case PIPE_FORMAT_U_A8_L8: + /*a8_l8_put_tile(ps, x, y, w, h, p);*/ + break; + case PIPE_FORMAT_S_R16_G16_B16_A16: + r16g16b16a16_put_tile(ps, x, y, w, h, p); + break; + case PIPE_FORMAT_U_Z16: + /*z16_put_tile(ps, x, y, w, h, p);*/ + break; + case PIPE_FORMAT_U_Z32: + /*z32_put_tile(ps, x, y, w, h, p);*/ + break; + case PIPE_FORMAT_S8_Z24: + /*s8z24_put_tile(ps, x, y, w, h, p);*/ + break; + default: + assert(0); + } } @@ -664,11 +730,12 @@ put_tile_rgba_generic(struct pipe_context *pipe, void sp_init_surface_functions(struct softpipe_context *sp) { +#if 0 sp->pipe.surface_alloc = softpipe_surface_alloc; - +#endif sp->pipe.get_tile = softpipe_get_tile; sp->pipe.put_tile = softpipe_put_tile; - sp->pipe.get_tile_rgba = get_tile_rgba_generic; - sp->pipe.put_tile_rgba = put_tile_rgba_generic; + sp->pipe.get_tile_rgba = softpipe_get_tile_rgba; + sp->pipe.put_tile_rgba = softpipe_put_tile_rgba; } diff --git a/src/mesa/pipe/softpipe/sp_surface.h b/src/mesa/pipe/softpipe/sp_surface.h index af6533d4f0..359a438c86 100644 --- a/src/mesa/pipe/softpipe/sp_surface.h +++ b/src/mesa/pipe/softpipe/sp_surface.h @@ -46,20 +46,33 @@ struct softpipe_tile_cache; struct softpipe_surface { struct pipe_surface surface; +#if 0 /* XXX these are temporary here */ void (*get_tile)(struct pipe_surface *ps, uint x, uint y, uint w, uint h, float *p); void (*put_tile)(struct pipe_surface *ps, uint x, uint y, uint w, uint h, const float *p); +#endif }; - extern struct pipe_surface * softpipe_get_tex_surface(struct pipe_context *pipe, struct pipe_mipmap_tree *mt, unsigned face, unsigned level, unsigned zslice); +extern void +softpipe_get_tile_rgba(struct pipe_context *pipe, + struct pipe_surface *ps, + uint x, uint y, uint w, uint h, + float *p); + +extern void +softpipe_put_tile_rgba(struct pipe_context *pipe, + struct pipe_surface *ps, + uint x, uint y, uint w, uint h, + const float *p); + extern void softpipe_init_surface_funcs(struct softpipe_surface *sps); diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index f22132b3cf..160edc4274 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -84,7 +84,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, cpp = info->size; if (!strb->surface) { - strb->surface = pipe->surface_alloc(pipe, pipeFormat); + strb->surface = pipe->winsys->surface_alloc(pipe->winsys, pipeFormat); assert(strb->surface); if (!strb->surface) return GL_FALSE; -- cgit v1.2.3 From f16f23b3ab4caf6588ce713fc682aac6e9f808fb Mon Sep 17 00:00:00 2001 From: michal Date: Sat, 27 Oct 2007 17:30:23 +0100 Subject: Use PIPE_FORMAT in state tracker. Fix PIPE_FORMAT field encoding. Re-implement st_get_format_info. --- src/mesa/pipe/p_format.h | 2 +- src/mesa/state_tracker/st_cb_fbo.c | 23 ++--- src/mesa/state_tracker/st_format.c | 183 +++++++++++++++++++++++++++++++++++-- src/mesa/state_tracker/st_format.h | 6 +- 4 files changed, 192 insertions(+), 22 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/pipe/p_format.h b/src/mesa/pipe/p_format.h index 3046538f12..1cab3c27b2 100644 --- a/src/mesa/pipe/p_format.h +++ b/src/mesa/pipe/p_format.h @@ -84,7 +84,7 @@ struct pipe_format_rgbazs ((EXP8) << 26) |\ ((TYPE) << 28) ) -#define _PIPE_FORMAT_SWZ( SWZX, SWZY, SWZZ, SWZW ) (((SWZX) << 2) | ((SWZY) << 5) | ((SWZZ) << 8) | ((SWZW) << 11)) +#define _PIPE_FORMAT_SWZ( SWZX, SWZY, SWZZ, SWZW ) (((SWZX) << 0) | ((SWZY) << 3) | ((SWZZ) << 6) | ((SWZW) << 9)) #define _PIPE_FORMAT_RGBAZS_1U( SWZ, SIZE, TYPE )\ _PIPE_FORMAT_RGBAZS( SWZ, SIZE, SIZE, SIZE, SIZE, 0, TYPE ) diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 160edc4274..5512bdeed8 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -62,26 +62,27 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, struct st_renderbuffer *strb = st_renderbuffer(rb); const GLuint pipeFormat = st_choose_pipe_format(pipe, internalFormat, GL_NONE, GL_NONE); - const struct pipe_format_info *info = st_get_format_info(pipeFormat); + struct pipe_format_info info; GLuint cpp; GLbitfield flags = PIPE_SURFACE_FLAG_RENDER; /* want to render to surface */ - assert(info); - if (!info) + if (!st_get_format_info( pipeFormat, &info )) { + assert( 0 ); return GL_FALSE; + } - strb->Base._ActualFormat = info->base_format; - strb->Base.RedBits = info->red_bits; - strb->Base.GreenBits = info->green_bits; - strb->Base.BlueBits = info->blue_bits; - strb->Base.AlphaBits = info->alpha_bits; - strb->Base.DepthBits = info->depth_bits; - strb->Base.StencilBits = info->stencil_bits; + strb->Base._ActualFormat = info.base_format; + strb->Base.RedBits = info.red_bits; + strb->Base.GreenBits = info.green_bits; + strb->Base.BlueBits = info.blue_bits; + strb->Base.AlphaBits = info.alpha_bits; + strb->Base.DepthBits = info.depth_bits; + strb->Base.StencilBits = info.stencil_bits; strb->Base.DataType = st_format_datatype(pipeFormat); assert(strb->Base.DataType); - cpp = info->size; + cpp = info.size; if (!strb->surface) { strb->surface = pipe->winsys->surface_alloc(pipe->winsys, pipeFormat); diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c index 5ccbe721eb..5a50d2d63a 100644 --- a/src/mesa/state_tracker/st_format.c +++ b/src/mesa/state_tracker/st_format.c @@ -36,20 +36,74 @@ #include "main/texstore.h" #include "main/texformat.h" #include "main/enums.h" +#include "main/macros.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "st_context.h" #include "st_format.h" +static GLuint +format_bits( + struct pipe_format_rgbazs info, + GLuint comp ) +{ + GLuint size; + if (info.swizzleX == comp) { + size = info.sizeX; + } + else if (info.swizzleY == comp) { + size = info.sizeY; + } + else if (info.swizzleZ == comp) { + size = info.sizeZ; + } + else if (info.swizzleW == comp) { + size = info.sizeW; + } + else { + size = 0; + } + return size << (info.exp8 * 3); +} + +static GLuint +format_max_bits( + struct pipe_format_rgbazs info ) +{ + GLuint size = format_bits( info, PIPE_FORMAT_COMP_R ); + + size = MAX2( size, format_bits( info, PIPE_FORMAT_COMP_G ) ); + size = MAX2( size, format_bits( info, PIPE_FORMAT_COMP_B ) ); + size = MAX2( size, format_bits( info, PIPE_FORMAT_COMP_A ) ); + size = MAX2( size, format_bits( info, PIPE_FORMAT_COMP_Z ) ); + size = MAX2( size, format_bits( info, PIPE_FORMAT_COMP_S ) ); + return size; +} + +static GLuint +format_size( + struct pipe_format_rgbazs info ) +{ + return + format_bits( info, PIPE_FORMAT_COMP_R ) + + format_bits( info, PIPE_FORMAT_COMP_G ) + + format_bits( info, PIPE_FORMAT_COMP_B ) + + format_bits( info, PIPE_FORMAT_COMP_A ) + + format_bits( info, PIPE_FORMAT_COMP_Z ) + + format_bits( info, PIPE_FORMAT_COMP_S ); +} /* * XXX temporary here */ -const struct pipe_format_info * -st_get_format_info(GLuint format) +GLboolean +st_get_format_info( + GLuint format, + struct pipe_format_info *pinfo ) { +#if 0 static const struct pipe_format_info info[] = { { PIPE_FORMAT_U_R8_G8_B8_A8, /* format */ @@ -124,6 +178,113 @@ st_get_format_info(GLuint format) return info + i; } return NULL; +#endif + + union pipe_format fmt; + + fmt.value32 = format; + if (fmt.header.layout == PIPE_FORMAT_LAYOUT_RGBAZS) { + struct pipe_format_rgbazs info; + + info = fmt.rgbazs; + +#if 0 + printf( + "PIPE_FORMAT: X(%u), Y(%u), Z(%u), W(%u)\n", + info.sizeX, + info.sizeY, + info.sizeZ, + info.sizeW ); +#endif + + /* Data type */ + if (format == PIPE_FORMAT_U_A1_R5_G5_B5 || format == PIPE_FORMAT_U_R5_G6_B5) { + pinfo->datatype = GL_UNSIGNED_SHORT; + } + else { + GLuint size; + + assert( info.type == PIPE_FORMAT_TYPE_UNORM ); + + size = format_max_bits( info ); + if (size == 8) { + pinfo->datatype = GL_UNSIGNED_BYTE; + } + else if (size == 16) { + pinfo->datatype = GL_UNSIGNED_SHORT; + } + else { + assert( size <= 32 ); + + pinfo->datatype = GL_UNSIGNED_INT; + } + } + + /* Component bits */ + pinfo->red_bits = format_bits( info, PIPE_FORMAT_COMP_R ); + pinfo->green_bits = format_bits( info, PIPE_FORMAT_COMP_G ); + pinfo->blue_bits = format_bits( info, PIPE_FORMAT_COMP_B ); + pinfo->alpha_bits = format_bits( info, PIPE_FORMAT_COMP_A ); + pinfo->depth_bits = format_bits( info, PIPE_FORMAT_COMP_Z ); + pinfo->stencil_bits = format_bits( info, PIPE_FORMAT_COMP_S ); + + /* Format size */ + pinfo->size = format_size( info ) / 8; + + /* Luminance & Intensity bits */ + if( info.swizzleX == PIPE_FORMAT_COMP_R && info.swizzleY == PIPE_FORMAT_COMP_R && info.swizzleZ == PIPE_FORMAT_COMP_R ) { + if( info.swizzleW == PIPE_FORMAT_COMP_R ) { + pinfo->luminance_bits = 0; + pinfo->intensity_bits = pinfo->red_bits; + } + else { + pinfo->luminance_bits = pinfo->red_bits; + pinfo->intensity_bits = 0; + } + pinfo->red_bits = 0; + } + + /* Base format */ + if (pinfo->depth_bits) { + if (pinfo->stencil_bits) { + pinfo->base_format = GL_DEPTH_STENCIL_EXT; + } + else { + pinfo->base_format = GL_DEPTH_COMPONENT; + } + } + else if (pinfo->stencil_bits) { + pinfo->base_format = GL_STENCIL_INDEX; + } + else { + pinfo->base_format = GL_RGBA; + } + } + else { + struct pipe_format_ycbcr info; + + assert( fmt.header.layout == PIPE_FORMAT_LAYOUT_YCBCR ); + + info = fmt.ycbcr; + + /* TODO */ + assert( 0 ); + } + +#if 0 + printf( + "ST_FORMAT: R(%u), G(%u), B(%u), A(%u), Z(%u), S(%u)\n", + pinfo->red_bits, + pinfo->green_bits, + pinfo->blue_bits, + pinfo->alpha_bits, + pinfo->depth_bits, + pinfo->stencil_bits ); +#endif + + pinfo->format = format; + + return GL_TRUE; } @@ -133,9 +294,12 @@ st_get_format_info(GLuint format) GLuint st_sizeof_format(GLuint pipeFormat) { - const struct pipe_format_info *info = st_get_format_info(pipeFormat); - assert(info); - return info->size; + struct pipe_format_info info; + if (!st_get_format_info( pipeFormat, &info )) { + assert( 0 ); + return 0; + } + return info.size; } @@ -145,9 +309,12 @@ st_sizeof_format(GLuint pipeFormat) GLenum st_format_datatype(GLuint pipeFormat) { - const struct pipe_format_info *info = st_get_format_info(pipeFormat); - assert(info); - return info->datatype; + struct pipe_format_info info; + if (!st_get_format_info( pipeFormat, &info )) { + assert( 0 ); + return 0; + } + return info.datatype; } diff --git a/src/mesa/state_tracker/st_format.h b/src/mesa/state_tracker/st_format.h index 17d0985411..23abc36edf 100644 --- a/src/mesa/state_tracker/st_format.h +++ b/src/mesa/state_tracker/st_format.h @@ -47,8 +47,10 @@ struct pipe_format_info }; -extern const struct pipe_format_info * -st_get_format_info(GLuint format); +extern GLboolean +st_get_format_info( + GLuint format, + struct pipe_format_info *pinfo ); extern GLuint -- cgit v1.2.3 From 7de874ec2c7b9e3aff7f81b7e30045b45381fbad Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Mon, 29 Oct 2007 16:59:57 +0000 Subject: Make it compile under linux. Move pipe_region/surface_reference functions to pipe/p_inlines.h. Remove #include "p_util.h" from pipe/p_context.h. --- src/mesa/pipe/i915simple/i915_surface.c | 1 + src/mesa/pipe/p_context.h | 60 ------------------- src/mesa/pipe/p_inlines.h | 89 ++++++++++++++++++++++++++++ src/mesa/pipe/softpipe/sp_state_blend.c | 2 + src/mesa/pipe/softpipe/sp_state_rasterizer.c | 1 + src/mesa/pipe/softpipe/sp_state_sampler.c | 1 + src/mesa/pipe/softpipe/sp_surface.c | 1 + src/mesa/pipe/softpipe/sp_tex_layout.c | 1 + src/mesa/pipe/softpipe/sp_tex_sample.c | 2 +- src/mesa/pipe/softpipe/sp_tile_cache.c | 3 +- src/mesa/pipe/tgsi/exec/tgsi_exec.c | 6 +- src/mesa/state_tracker/st_cb_drawpixels.c | 1 + src/mesa/state_tracker/st_cb_fbo.c | 1 + 13 files changed, 104 insertions(+), 65 deletions(-) create mode 100644 src/mesa/pipe/p_inlines.h (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/pipe/i915simple/i915_surface.c b/src/mesa/pipe/i915simple/i915_surface.c index b4b5bd1ce5..afe15fb525 100644 --- a/src/mesa/pipe/i915simple/i915_surface.c +++ b/src/mesa/pipe/i915simple/i915_surface.c @@ -29,6 +29,7 @@ #include "i915_state.h" #include "pipe/p_defines.h" #include "pipe/p_util.h" +#include "pipe/p_inlines.h" #include "pipe/p_winsys.h" diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 3bd266674f..33d1878158 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -29,7 +29,6 @@ #define PIPE_CONTEXT_H #include "p_state.h" -#include "p_util.h" struct pipe_state_cache; /** @@ -246,63 +245,4 @@ struct pipe_context { unsigned flags ); }; - -/** - * Set 'ptr' to point to 'region' and update reference counting. - * The old thing pointed to, if any, will be unreferenced first. - * 'region' may be NULL. - */ -static INLINE void -pipe_region_reference(struct pipe_region **ptr, struct pipe_region *region) -{ - assert(ptr); - if (*ptr) { - /* unreference the old thing */ - struct pipe_region *oldReg = *ptr; - assert(oldReg->refcount > 0); - oldReg->refcount--; - if (oldReg->refcount == 0) { - /* free the old region */ - assert(oldReg->map_refcount == 0); - /* XXX dereference the region->buffer */ - FREE( oldReg ); - } - *ptr = NULL; - } - if (region) { - /* reference the new thing */ - region->refcount++; - *ptr = region; - } -} - - -/** - * \sa pipe_region_reference - */ -static INLINE void -pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf) -{ - assert(ptr); - if (*ptr) { - /* unreference the old thing */ - struct pipe_surface *oldSurf = *ptr; - assert(oldSurf->refcount > 0); - oldSurf->refcount--; - if (oldSurf->refcount == 0) { - /* free the old region */ - pipe_region_reference(&oldSurf->region, NULL); - FREE( oldSurf ); - } - *ptr = NULL; - } - if (surf) { - /* reference the new thing */ - surf->refcount++; - *ptr = surf; - } -} - - #endif /* PIPE_CONTEXT_H */ - diff --git a/src/mesa/pipe/p_inlines.h b/src/mesa/pipe/p_inlines.h new file mode 100644 index 0000000000..ea666fa20a --- /dev/null +++ b/src/mesa/pipe/p_inlines.h @@ -0,0 +1,89 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef P_INLINES_H +#define P_INLINES_H + +#include "p_context.h" +//#include "p_util.h" + +/** + * Set 'ptr' to point to 'region' and update reference counting. + * The old thing pointed to, if any, will be unreferenced first. + * 'region' may be NULL. + */ +static INLINE void +pipe_region_reference(struct pipe_region **ptr, struct pipe_region *region) +{ + assert(ptr); + if (*ptr) { + /* unreference the old thing */ + struct pipe_region *oldReg = *ptr; + assert(oldReg->refcount > 0); + oldReg->refcount--; + if (oldReg->refcount == 0) { + /* free the old region */ + assert(oldReg->map_refcount == 0); + /* XXX dereference the region->buffer */ + FREE( oldReg ); + } + *ptr = NULL; + } + if (region) { + /* reference the new thing */ + region->refcount++; + *ptr = region; + } +} + +/** + * \sa pipe_region_reference + */ +static INLINE void +pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf) +{ + assert(ptr); + if (*ptr) { + /* unreference the old thing */ + struct pipe_surface *oldSurf = *ptr; + assert(oldSurf->refcount > 0); + oldSurf->refcount--; + if (oldSurf->refcount == 0) { + /* free the old region */ + pipe_region_reference(&oldSurf->region, NULL); + FREE( oldSurf ); + } + *ptr = NULL; + } + if (surf) { + /* reference the new thing */ + surf->refcount++; + *ptr = surf; + } +} + +#endif /* P_INLINES_H */ diff --git a/src/mesa/pipe/softpipe/sp_state_blend.c b/src/mesa/pipe/softpipe/sp_state_blend.c index e9e6a55e0d..5ceec2513f 100644 --- a/src/mesa/pipe/softpipe/sp_state_blend.c +++ b/src/mesa/pipe/softpipe/sp_state_blend.c @@ -27,6 +27,8 @@ /* Authors: Keith Whitwell */ + +#include "pipe/p_util.h" #include "sp_context.h" #include "sp_state.h" diff --git a/src/mesa/pipe/softpipe/sp_state_rasterizer.c b/src/mesa/pipe/softpipe/sp_state_rasterizer.c index a69e0d9012..ce8fa4f2b8 100644 --- a/src/mesa/pipe/softpipe/sp_state_rasterizer.c +++ b/src/mesa/pipe/softpipe/sp_state_rasterizer.c @@ -26,6 +26,7 @@ **************************************************************************/ #include "pipe/p_defines.h" +#include "pipe/p_util.h" #include "sp_context.h" #include "sp_state.h" #include "pipe/draw/draw_context.h" diff --git a/src/mesa/pipe/softpipe/sp_state_sampler.c b/src/mesa/pipe/softpipe/sp_state_sampler.c index 7b528fbaf3..246a7d6eda 100644 --- a/src/mesa/pipe/softpipe/sp_state_sampler.c +++ b/src/mesa/pipe/softpipe/sp_state_sampler.c @@ -29,6 +29,7 @@ * Brian Paul */ +#include "pipe/p_util.h" #include "sp_context.h" #include "sp_state.h" #include "sp_tile_cache.h" diff --git a/src/mesa/pipe/softpipe/sp_surface.c b/src/mesa/pipe/softpipe/sp_surface.c index 9d5529d8d6..eeaf98ce36 100644 --- a/src/mesa/pipe/softpipe/sp_surface.c +++ b/src/mesa/pipe/softpipe/sp_surface.c @@ -27,6 +27,7 @@ #include "pipe/p_defines.h" #include "pipe/p_util.h" +#include "pipe/p_inlines.h" #include "pipe/p_winsys.h" #include "sp_context.h" #include "sp_state.h" diff --git a/src/mesa/pipe/softpipe/sp_tex_layout.c b/src/mesa/pipe/softpipe/sp_tex_layout.c index 3ac7bfcb73..8156b00301 100644 --- a/src/mesa/pipe/softpipe/sp_tex_layout.c +++ b/src/mesa/pipe/softpipe/sp_tex_layout.c @@ -32,6 +32,7 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "pipe/p_util.h" #include "sp_tex_layout.h" diff --git a/src/mesa/pipe/softpipe/sp_tex_sample.c b/src/mesa/pipe/softpipe/sp_tex_sample.c index 0b91ef0e37..e3e607d27c 100644 --- a/src/mesa/pipe/softpipe/sp_tex_sample.c +++ b/src/mesa/pipe/softpipe/sp_tex_sample.c @@ -32,13 +32,13 @@ * Brian Paul */ - #include "sp_context.h" #include "sp_surface.h" #include "sp_tex_sample.h" #include "sp_tile_cache.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "pipe/p_util.h" #include "pipe/tgsi/exec/tgsi_exec.h" diff --git a/src/mesa/pipe/softpipe/sp_tile_cache.c b/src/mesa/pipe/softpipe/sp_tile_cache.c index 473316b674..9542ec3765 100644 --- a/src/mesa/pipe/softpipe/sp_tile_cache.c +++ b/src/mesa/pipe/softpipe/sp_tile_cache.c @@ -32,7 +32,8 @@ * Brian Paul */ - +#include "pipe/p_util.h" +#include "pipe/p_inlines.h" #include "sp_context.h" #include "sp_surface.h" #include "sp_tile_cache.h" diff --git a/src/mesa/pipe/tgsi/exec/tgsi_exec.c b/src/mesa/pipe/tgsi/exec/tgsi_exec.c index 7607ded63a..3494b21599 100644 --- a/src/mesa/pipe/tgsi/exec/tgsi_exec.c +++ b/src/mesa/pipe/tgsi/exec/tgsi_exec.c @@ -50,10 +50,10 @@ * Brian Paul */ -#include "tgsi_platform.h" -#include "tgsi_core.h" +#include "pipe/p_compiler.h" #include "pipe/p_state.h" - +#include "pipe/p_util.h" +#include "tgsi_core.h" #define TILE_TOP_LEFT 0 #define TILE_TOP_RIGHT 1 diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 99e1e3ed25..3c57317415 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -48,6 +48,7 @@ #include "st_mesa_to_tgsi.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "pipe/p_inlines.h" #include "pipe/p_winsys.h" #include "shader/prog_instruction.h" diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 5512bdeed8..1ffd1a30b8 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -41,6 +41,7 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "pipe/p_inlines.h" #include "pipe/p_winsys.h" #include "st_context.h" #include "st_cb_fbo.h" -- cgit v1.2.3 From 3470d819fd7e3d3dd259d6fb2d4b963a514f0520 Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 6 Nov 2007 15:17:20 -0700 Subject: realloc surface if format changes, remove dead code --- src/mesa/state_tracker/st_cb_fbo.c | 39 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 1ffd1a30b8..7c18f380cd 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -61,7 +61,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, { struct pipe_context *pipe = ctx->st->pipe; struct st_renderbuffer *strb = st_renderbuffer(rb); - const GLuint pipeFormat + const uint pipeFormat = st_choose_pipe_format(pipe, internalFormat, GL_NONE, GL_NONE); struct pipe_format_info info; GLuint cpp; @@ -85,6 +85,12 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, cpp = info.size; + if (strb->surface && strb->surface->format != pipeFormat) { + /* need to change surface types, free this surface */ + pipe_surface_reference(&strb->surface, NULL); + assert(strb->surface == NULL); + } + if (!strb->surface) { strb->surface = pipe->winsys->surface_alloc(pipe->winsys, pipeFormat); assert(strb->surface); @@ -187,28 +193,10 @@ st_new_renderbuffer(GLcontext *ctx, GLuint name) } -#if 000 -struct gl_renderbuffer * -st_new_renderbuffer_fb(struct pipe_region *region, GLuint width, GLuint height) -{ - struct st_renderbuffer *strb = CALLOC_STRUCT(st_renderbuffer); - if (!strb) - return; - - _mesa_init_renderbuffer(&strb->Base, name); - strb->Base.Delete = st_renderbuffer_delete; - strb->Base.AllocStorage = st_renderbuffer_alloc_storage; - strb->Base.GetPointer = null_get_pointer; - strb->Base.Width = width; - strb->Base.Heigth = height; - - strb->region = region; - - return &strb->Base; -} - -#else - +/** + * Allocate a renderbuffer for a an on-screen window (not a user-created + * renderbuffer). The window system code determines the internal format. + */ struct gl_renderbuffer * st_new_renderbuffer_fb(GLenum intFormat) { @@ -221,7 +209,7 @@ st_new_renderbuffer_fb(GLenum intFormat) } _mesa_init_renderbuffer(&strb->Base, 0); - strb->Base.ClassID = 0x42; /* XXX temp */ + strb->Base.ClassID = 0x4242; /* just a unique value */ strb->Base.InternalFormat = intFormat; switch (intFormat) { @@ -251,12 +239,11 @@ st_new_renderbuffer_fb(GLenum intFormat) strb->Base.AllocStorage = st_renderbuffer_alloc_storage; strb->Base.GetPointer = null_get_pointer; - /* surface is allocate in alloc_renderbuffer_storage() */ + /* surface is allocated in st_renderbuffer_alloc_storage() */ strb->surface = NULL; return &strb->Base; } -#endif -- cgit v1.2.3 From 7d1a04e499564212a2a9aace12b05f424a357d3f Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 7 Nov 2007 08:05:09 -0700 Subject: Add winsys->surface_release() to complement winsys->surface_alloc(). pipe_surface now has a pointer to the winsys which create/owns the surface. This allows clean surface deallocation w/out a rendering context. --- .../drivers/dri/intel_winsys/intel_winsys_pipe.c | 17 +++++++++++++++ src/mesa/pipe/p_inlines.h | 16 +++++---------- src/mesa/pipe/p_state.h | 3 +++ src/mesa/pipe/p_winsys.h | 2 ++ src/mesa/pipe/xlib/xm_api.c | 11 +++------- src/mesa/pipe/xlib/xm_buffer.c | 24 ++++++++-------------- src/mesa/pipe/xlib/xm_surface.c | 8 ++++---- src/mesa/pipe/xlib/xm_winsys.c | 15 +++++++++++++- src/mesa/pipe/xlib/xmesaP.h | 11 +++++----- src/mesa/state_tracker/st_cb_fbo.c | 17 ++++----------- 10 files changed, 66 insertions(+), 58 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c b/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c index cc76a40a5a..56a600aebe 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c @@ -264,11 +264,27 @@ intel_i915_surface_alloc(struct pipe_winsys *winsys, unsigned format) if (surf) { surf->format = format; surf->refcount = 1; + surf->winsys = winsys; } return surf; } +static void +intel_i915_surface_release(struct pipe_winsys *winsys, struct pipe_surface **s) +{ + struct pipe_surface *surf = *s; + surf->refcount--; + if (surf->refcount == 0) { + if (surf->region) + winsys->region_release(winsys, &surf->region); + free(surf); + } + *s = NULL; +} + + + static void intel_printf( struct pipe_winsys *sws, const char *fmtString, ... ) { @@ -315,6 +331,7 @@ intel_create_pipe_winsys( struct intel_context *intel ) iws->winsys.region_release = intel_i915_region_release; iws->winsys.surface_alloc = intel_i915_surface_alloc; + iws->winsys.surface_release = intel_i915_surface_release; return &iws->winsys; } diff --git a/src/mesa/pipe/p_inlines.h b/src/mesa/pipe/p_inlines.h index ea666fa20a..2418d016e1 100644 --- a/src/mesa/pipe/p_inlines.h +++ b/src/mesa/pipe/p_inlines.h @@ -29,7 +29,8 @@ #define P_INLINES_H #include "p_context.h" -//#include "p_util.h" +#include "p_winsys.h" + /** * Set 'ptr' to point to 'region' and update reference counting. @@ -68,16 +69,9 @@ pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf) { assert(ptr); if (*ptr) { - /* unreference the old thing */ - struct pipe_surface *oldSurf = *ptr; - assert(oldSurf->refcount > 0); - oldSurf->refcount--; - if (oldSurf->refcount == 0) { - /* free the old region */ - pipe_region_reference(&oldSurf->region, NULL); - FREE( oldSurf ); - } - *ptr = NULL; + struct pipe_winsys *winsys = (*ptr)->winsys; + winsys->surface_release(winsys, ptr); + assert(!*ptr); } if (surf) { /* reference the new thing */ diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index 0e1a038c2e..848c32701f 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -60,6 +60,8 @@ struct pipe_surface; /* opaque type */ struct pipe_buffer_handle; +struct pipe_winsys; + /*** *** State objects @@ -281,6 +283,7 @@ struct pipe_surface unsigned width, height; unsigned offset; /**< offset from start of region, in bytes */ unsigned refcount; + struct pipe_winsys *winsys; /**< winsys which owns/created the surface */ }; diff --git a/src/mesa/pipe/p_winsys.h b/src/mesa/pipe/p_winsys.h index 5bc6e6475a..e4c888ad33 100644 --- a/src/mesa/pipe/p_winsys.h +++ b/src/mesa/pipe/p_winsys.h @@ -86,6 +86,8 @@ struct pipe_winsys struct pipe_surface *(*surface_alloc)(struct pipe_winsys *ws, unsigned format); + void (*surface_release)(struct pipe_winsys *ws, struct pipe_surface **s); + /** * The buffer manager is modeled after the dri_bufmgr interface, which * in turn is modeled after the ARB_vertex_buffer_object extension, diff --git a/src/mesa/pipe/xlib/xm_api.c b/src/mesa/pipe/xlib/xm_api.c index 939dfe745b..ec889ca34f 100644 --- a/src/mesa/pipe/xlib/xm_api.c +++ b/src/mesa/pipe/xlib/xm_api.c @@ -301,6 +301,7 @@ create_xmesa_buffer(XMesaDrawable d, BufferType type, { XMesaBuffer b; GLframebuffer *fb; + struct pipe_winsys *winsys = xmesa_get_pipe_winsys(); ASSERT(type == WINDOW || type == PIXMAP || type == PBUFFER); @@ -328,7 +329,7 @@ create_xmesa_buffer(XMesaDrawable d, BufferType type, /* * Front renderbuffer */ - b->frontxrb = xmesa_create_renderbuffer(NULL, 0, &vis->mesa_visual, GL_FALSE); + b->frontxrb = xmesa_create_renderbuffer(winsys, 0, &vis->mesa_visual, GL_FALSE); if (!b->frontxrb) { _mesa_free(b); return NULL; @@ -337,18 +338,12 @@ create_xmesa_buffer(XMesaDrawable d, BufferType type, b->frontxrb->drawable = d; b->frontxrb->pixmap = (XMesaPixmap) d; _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &b->frontxrb->St.Base); -#if 0 /* sketch... */ - { - struct pipe_surface *front_surf; - front_surf = xmesa_create_front_surface(vis, d); - } -#endif /* * Back renderbuffer */ if (vis->mesa_visual.doubleBufferMode) { - b->backxrb = xmesa_create_renderbuffer(NULL, 0, &vis->mesa_visual, GL_TRUE); + b->backxrb = xmesa_create_renderbuffer(winsys, 0, &vis->mesa_visual, GL_TRUE); if (!b->backxrb) { /* XXX free front xrb too */ _mesa_free(b); diff --git a/src/mesa/pipe/xlib/xm_buffer.c b/src/mesa/pipe/xlib/xm_buffer.c index b4a05ac685..7dc85bf2eb 100644 --- a/src/mesa/pipe/xlib/xm_buffer.c +++ b/src/mesa/pipe/xlib/xm_buffer.c @@ -241,6 +241,12 @@ alloc_back_buffer(XMesaBuffer b, GLuint width, GLuint height) static void xmesa_delete_renderbuffer(struct gl_renderbuffer *rb) { + struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb); + if (xrb->St.surface) { + struct pipe_winsys *ws = xrb->St.surface->winsys; + ws->surface_release(ws, &xrb->St.surface); + } + /* XXX Note: the ximage or Pixmap attached to this renderbuffer * should probably get freed here, but that's currently done in * XMesaDestroyBuffer(). @@ -289,11 +295,6 @@ xmesa_alloc_front_storage(GLcontext *ctx, struct gl_renderbuffer *rb, if (!xrb->St.surface || !xrb->St.surface->region) finish_surface_init(ctx, xrb); -#if 0 - xmesa_set_renderbuffer_funcs(xrb, xmesa->pixelformat, - xmesa->xm_visual->BitsPerPixel); -#endif - /* surface info */ xms->surface.width = width; xms->surface.height = height; @@ -353,11 +354,6 @@ xmesa_alloc_back_storage(GLcontext *ctx, struct gl_renderbuffer *rb, xrb->origin4 = NULL; } -#if 0 - xmesa_set_renderbuffer_funcs(xrb, xmesa->pixelformat, - xmesa->xm_visual->BitsPerPixel); -#endif - if (!xrb->St.surface || !xrb->St.surface->region) finish_surface_init(ctx, xrb); @@ -381,11 +377,11 @@ xmesa_alloc_back_storage(GLcontext *ctx, struct gl_renderbuffer *rb, * renderbuffers. */ struct xmesa_renderbuffer * -xmesa_create_renderbuffer(GLcontext *ctx, GLuint name, const GLvisual *visual, +xmesa_create_renderbuffer(struct pipe_winsys *winsys, + GLuint name, const GLvisual *visual, GLboolean backBuffer) { struct xmesa_renderbuffer *xrb = CALLOC_STRUCT(xmesa_renderbuffer); - struct pipe_context *pipe = NULL;/*ctx->st->pipe;*/ if (xrb) { GLuint name = 0; GLuint pipeFormat = 0; @@ -416,11 +412,9 @@ xmesa_create_renderbuffer(GLcontext *ctx, GLuint name, const GLvisual *visual, xrb->St.Base.IndexBits = visual->indexBits; } /* only need to set Red/Green/EtcBits fields for user-created RBs */ - - xrb->St.surface = xmesa_new_color_surface(pipe, pipeFormat); + xrb->St.surface = xmesa_new_color_surface(winsys, pipeFormat); xms = (struct xmesa_surface *) xrb->St.surface; xms->xrb = xrb; - } return xrb; } diff --git a/src/mesa/pipe/xlib/xm_surface.c b/src/mesa/pipe/xlib/xm_surface.c index 9969cc728d..43e5050747 100644 --- a/src/mesa/pipe/xlib/xm_surface.c +++ b/src/mesa/pipe/xlib/xm_surface.c @@ -609,7 +609,7 @@ clear_32bit_ximage_surface(struct pipe_context *pipe, struct pipe_surface *ps, * have special/unique quad read/write functions for X. */ struct pipe_surface * -xmesa_new_color_surface(struct pipe_context *pipe, GLuint pipeFormat) +xmesa_new_color_surface(struct pipe_winsys *winsys, GLuint pipeFormat) { struct xmesa_surface *xms = CALLOC_STRUCT(xmesa_surface); @@ -617,15 +617,14 @@ xmesa_new_color_surface(struct pipe_context *pipe, GLuint pipeFormat) xms->surface.format = pipeFormat; xms->surface.refcount = 1; + xms->surface.winsys = winsys; /* Note, the region we allocate doesn't actually have any storage * since we're drawing into an XImage or Pixmap. * The region's size will get set in the xmesa_alloc_front/back_storage() * functions. */ - if (pipe) - xms->surface.region = pipe->winsys->region_alloc(pipe->winsys, - 1, 0, 0, 0x0); + xms->surface.region = winsys->region_alloc(winsys, 1, 1, 1, 0x0); return &xms->surface; } @@ -645,6 +644,7 @@ xmesa_surface_alloc(struct pipe_context *pipe, GLuint pipeFormat) xms->surface.format = pipeFormat; xms->surface.refcount = 1; + xms->surface.winsys = pipe->winsys; return &xms->surface; } diff --git a/src/mesa/pipe/xlib/xm_winsys.c b/src/mesa/pipe/xlib/xm_winsys.c index f7e55ed8f7..b73fcab68d 100644 --- a/src/mesa/pipe/xlib/xm_winsys.c +++ b/src/mesa/pipe/xlib/xm_winsys.c @@ -284,6 +284,7 @@ xm_surface_alloc(struct pipe_winsys *ws, GLuint pipeFormat) xms->surface.format = pipeFormat; xms->surface.refcount = 1; + xms->surface.winsys = ws; #if 0 /* * This is really just a softpipe surface, not an XImage/Pixmap surface. @@ -295,13 +296,24 @@ xm_surface_alloc(struct pipe_winsys *ws, GLuint pipeFormat) +static void +xm_surface_release(struct pipe_winsys *ws, struct pipe_surface **s) +{ + struct pipe_surface *surf = *s; + if (surf->region) + winsys->region_release(winsys, &surf->region); + free(surf); + *s = NULL; +} + + /** * Return pointer to a pipe_winsys object. * For Xlib, this is a singleton object. * Nothing special for the Xlib driver so no subclassing or anything. */ -static struct pipe_winsys * +struct pipe_winsys * xmesa_get_pipe_winsys(void) { static struct pipe_winsys *ws = NULL; @@ -325,6 +337,7 @@ xmesa_get_pipe_winsys(void) ws->region_release = xm_region_release; ws->surface_alloc = xm_surface_alloc; + ws->surface_release = xm_surface_release; ws->flush_frontbuffer = xm_flush_frontbuffer; ws->wait_idle = xm_wait_idle; diff --git a/src/mesa/pipe/xlib/xmesaP.h b/src/mesa/pipe/xlib/xmesaP.h index c70dc67608..ba0ccdbcec 100644 --- a/src/mesa/pipe/xlib/xmesaP.h +++ b/src/mesa/pipe/xlib/xmesaP.h @@ -51,10 +51,6 @@ typedef struct { } bgr_t; -struct xmesa_renderbuffer; - - - /** Framebuffer pixel formats */ enum pixel_format { PF_Index, /**< Color Index mode */ @@ -451,7 +447,8 @@ extern const int xmesa_kernel1[16]; */ extern struct xmesa_renderbuffer * -xmesa_create_renderbuffer(GLcontext *ctx, GLuint name, const GLvisual *visual, +xmesa_create_renderbuffer(struct pipe_winsys *winsys, + GLuint name, const GLvisual *visual, GLboolean backBuffer); extern void @@ -545,8 +542,10 @@ extern struct pipe_surface * xmesa_surface_alloc(struct pipe_context *pipe, GLuint format); extern struct pipe_surface * -xmesa_new_color_surface(struct pipe_context *pipe, GLuint format); +xmesa_new_color_surface(struct pipe_winsys *winsys, GLuint format); +extern struct pipe_winsys * +xmesa_get_pipe_winsys(void); extern void xmesa_get_tile(struct pipe_context *pipe, struct pipe_surface *ps, diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 7c18f380cd..0d23f7eec4 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -129,19 +129,10 @@ static void st_renderbuffer_delete(struct gl_renderbuffer *rb) { struct st_renderbuffer *strb = st_renderbuffer(rb); - GET_CURRENT_CONTEXT(ctx); - if (ctx) { - struct pipe_context *pipe = ctx->st->pipe; - ASSERT(strb); - if (strb && strb->surface) { - if (strb->surface->region) { - pipe->winsys->region_release(pipe->winsys, &strb->surface->region); - } - free(strb->surface); - } - } - else { - _mesa_warning(NULL, "st_renderbuffer_delete() called, but no current context"); + ASSERT(strb); + if (strb->surface) { + struct pipe_winsys *ws = strb->surface->winsys; + ws->surface_release(ws, &strb->surface); } free(strb); } -- cgit v1.2.3 From 02f7f46fa15c7d31d774c638684d4f5b81e360ec Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 8 Nov 2007 11:38:50 -0700 Subject: new init_renderbuffer_bits() helper --- src/mesa/state_tracker/st_cb_fbo.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 0d23f7eec4..f58d532b2a 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -52,24 +52,15 @@ /** - * gl_renderbuffer::AllocStorage() + * Compute the renderbuffer's Red/Green/EtcBit fields from the pipe format. */ -static GLboolean -st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, - GLenum internalFormat, - GLuint width, GLuint height) +static int +init_renderbuffer_bits(struct st_renderbuffer *strb, uint pipeFormat) { - struct pipe_context *pipe = ctx->st->pipe; - struct st_renderbuffer *strb = st_renderbuffer(rb); - const uint pipeFormat - = st_choose_pipe_format(pipe, internalFormat, GL_NONE, GL_NONE); struct pipe_format_info info; - GLuint cpp; - GLbitfield flags = PIPE_SURFACE_FLAG_RENDER; /* want to render to surface */ if (!st_get_format_info( pipeFormat, &info )) { assert( 0 ); - return GL_FALSE; } strb->Base._ActualFormat = info.base_format; @@ -81,9 +72,26 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, strb->Base.StencilBits = info.stencil_bits; strb->Base.DataType = st_format_datatype(pipeFormat); - assert(strb->Base.DataType); + return info.size; +} - cpp = info.size; + +/** + * gl_renderbuffer::AllocStorage() + */ +static GLboolean +st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, + GLenum internalFormat, + GLuint width, GLuint height) +{ + struct pipe_context *pipe = ctx->st->pipe; + struct st_renderbuffer *strb = st_renderbuffer(rb); + const uint pipeFormat + = st_choose_pipe_format(pipe, internalFormat, GL_NONE, GL_NONE); + GLuint cpp; + GLbitfield flags = PIPE_SURFACE_FLAG_RENDER; /* want to render to surface */ + + cpp = init_renderbuffer_bits(strb, pipeFormat); if (strb->surface && strb->surface->format != pipeFormat) { /* need to change surface types, free this surface */ @@ -305,6 +313,8 @@ st_render_texture(GLcontext *ctx, att->Zoffset); assert(strb->surface); + init_renderbuffer_bits(strb, mt->format); + /* printf("RENDER TO TEXTURE obj=%p mt=%p surf=%p %d x %d\n", att->Texture, mt, strb->surface, rb->Width, rb->Height); -- cgit v1.2.3 From 11a80160fd60d1eb1541b49128c659526a5d8ac8 Mon Sep 17 00:00:00 2001 From: Michel Dänzer Date: Wed, 28 Nov 2007 19:04:54 +0100 Subject: Move dimensions from struct pipe_region to struct pipe_surface. --- .../drivers/dri/intel_winsys/intel_swapbuffers.c | 6 +- .../drivers/dri/intel_winsys/intel_winsys_pipe.c | 30 +-- src/mesa/pipe/failover/fo_context.c | 6 +- src/mesa/pipe/i915simple/i915_clear.c | 9 +- src/mesa/pipe/i915simple/i915_regions.c | 172 --------------- src/mesa/pipe/i915simple/i915_state_emit.c | 25 +-- src/mesa/pipe/i915simple/i915_surface.c | 185 +++++++++++++++- src/mesa/pipe/p_context.h | 48 ++-- src/mesa/pipe/p_state.h | 5 +- src/mesa/pipe/p_winsys.h | 6 +- src/mesa/pipe/softpipe/sp_clear.c | 16 +- src/mesa/pipe/softpipe/sp_region.c | 186 ---------------- src/mesa/pipe/softpipe/sp_surface.c | 244 ++++++++++++++++++--- src/mesa/pipe/xlib/xm_buffer.c | 5 +- src/mesa/pipe/xlib/xm_surface.c | 2 +- src/mesa/pipe/xlib/xm_winsys.c | 22 +- src/mesa/state_tracker/st_cb_drawpixels.c | 50 ++--- src/mesa/state_tracker/st_cb_fbo.c | 8 +- src/mesa/state_tracker/st_cb_readpixels.c | 6 +- src/mesa/state_tracker/st_cb_texture.c | 35 +-- src/mesa/state_tracker/st_mipmap_tree.c | 54 +++-- 21 files changed, 550 insertions(+), 570 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/drivers/dri/intel_winsys/intel_swapbuffers.c b/src/mesa/drivers/dri/intel_winsys/intel_swapbuffers.c index 9fcb2dac27..f96209d1b0 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_swapbuffers.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_swapbuffers.c @@ -89,15 +89,15 @@ intelDisplaySurface(__DRIdrawablePrivate *dPriv, const int pitch = intelScreen->front.pitch / intelScreen->front.cpp; const int cpp = intelScreen->front.cpp; const struct pipe_region *srcRegion = surf->region; - const int srcpitch = srcRegion->pitch; + const int srcpitch = surf->pitch; int BR13, CMD; int i; ASSERT(srcRegion); - ASSERT(srcRegion->cpp == cpp); + ASSERT(surf->cpp == cpp); DBG(SWAP, "screen pitch %d src surface pitch %d\n", - pitch, srcRegion->pitch); + pitch, surf->pitch); if (cpp == 2) { BR13 = (pitch * cpp) | (0xCC << 16) | (1 << 24); diff --git a/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c b/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c index ae02f98a78..7b3aa99482 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c @@ -173,14 +173,10 @@ intel_flush_frontbuffer( struct pipe_winsys *winsys, } -static struct pipe_region * -intel_i915_region_alloc(struct pipe_winsys *winsys, - unsigned cpp, unsigned width, - unsigned height, unsigned flags) +static unsigned +intel_i915_surface_pitch(struct pipe_winsys *winsys, + unsigned cpp, unsigned width, unsigned flags) { - struct pipe_region *region = calloc(sizeof(*region), 1); - const unsigned alignment = 64; - /* Choose a pitch to match hardware requirements - requires 64 byte * alignment of render targets. * @@ -188,24 +184,29 @@ intel_i915_region_alloc(struct pipe_winsys *winsys, * clearly want to be able to render to textures under some * circumstances, but maybe not always a requirement. */ - unsigned pitch; /* XXX is the pitch different for textures vs. drawables? */ if (flags & PIPE_SURFACE_FLAG_TEXTURE) /* or PIPE_SURFACE_FLAG_RENDER? */ - pitch = ((cpp * width + 63) & ~63) / cpp; + return ((cpp * width + 63) & ~63) / cpp; else - pitch = ((cpp * width + 63) & ~63) / cpp; + return ((cpp * width + 63) & ~63) / cpp; +} + + +static struct pipe_region * +intel_i915_region_alloc(struct pipe_winsys *winsys, + unsigned size, unsigned flags) +{ + struct pipe_region *region = calloc(sizeof(*region), 1); + const unsigned alignment = 64; - region->cpp = cpp; - region->pitch = pitch; - region->height = height; /* needed? */ region->refcount = 1; region->buffer = winsys->buffer_create( winsys, alignment ); winsys->buffer_data( winsys, region->buffer, - pitch * cpp * height, + size, NULL, PIPE_BUFFER_USAGE_PIXEL ); @@ -301,6 +302,7 @@ intel_create_pipe_winsys( int fd ) iws->winsys.get_name = intel_get_name; iws->winsys.region_alloc = intel_i915_region_alloc; iws->winsys.region_release = intel_i915_region_release; + iws->winsys.surface_pitch = intel_i915_surface_pitch; iws->winsys.surface_alloc = intel_i915_surface_alloc; iws->winsys.surface_release = intel_i915_surface_release; diff --git a/src/mesa/pipe/failover/fo_context.c b/src/mesa/pipe/failover/fo_context.c index c5fab73fb1..0cc9cab408 100644 --- a/src/mesa/pipe/failover/fo_context.c +++ b/src/mesa/pipe/failover/fo_context.c @@ -142,9 +142,9 @@ struct pipe_context *failover_create( struct pipe_context *hw, failover->pipe.region_map = hw->region_map; failover->pipe.region_unmap = hw->region_unmap; - failover->pipe.region_data = hw->region_data; - failover->pipe.region_copy = hw->region_copy; - failover->pipe.region_fill = hw->region_fill; + failover->pipe.surface_data = hw->surface_data; + failover->pipe.surface_copy = hw->surface_copy; + failover->pipe.surface_fill = hw->surface_fill; failover->pipe.mipmap_tree_layout = hw->mipmap_tree_layout; failover->pipe.flush = hw->flush; diff --git a/src/mesa/pipe/i915simple/i915_clear.c b/src/mesa/pipe/i915simple/i915_clear.c index e8087df5a4..cde69daacc 100644 --- a/src/mesa/pipe/i915simple/i915_clear.c +++ b/src/mesa/pipe/i915simple/i915_clear.c @@ -43,12 +43,5 @@ void i915_clear(struct pipe_context *pipe, struct pipe_surface *ps, unsigned clearValue) { - int x, y, w, h; - - x = 0; - y = 0; - w = ps->width; - h = ps->height; - - pipe->region_fill(pipe, ps->region, 0, x, y, w, h, clearValue); + pipe->surface_fill(pipe, ps, 0, 0, ps->width, ps->height, clearValue); } diff --git a/src/mesa/pipe/i915simple/i915_regions.c b/src/mesa/pipe/i915simple/i915_regions.c index e8c4c92bc8..82fdec83d0 100644 --- a/src/mesa/pipe/i915simple/i915_regions.c +++ b/src/mesa/pipe/i915simple/i915_regions.c @@ -34,7 +34,6 @@ #include "pipe/p_defines.h" #include "pipe/p_winsys.h" #include "i915_context.h" -#include "i915_blit.h" @@ -70,181 +69,10 @@ i915_region_unmap(struct pipe_context *pipe, struct pipe_region *region) } -/* - * XXX Move this into core Mesa? - */ -static void -_mesa_copy_rect(ubyte * dst, - unsigned cpp, - unsigned dst_pitch, - unsigned dst_x, - unsigned dst_y, - unsigned width, - unsigned height, - const ubyte * src, - unsigned src_pitch, - unsigned src_x, - unsigned src_y) -{ - unsigned i; - - dst_pitch *= cpp; - src_pitch *= cpp; - dst += dst_x * cpp; - src += src_x * cpp; - dst += dst_y * dst_pitch; - src += src_y * dst_pitch; - width *= cpp; - - if (width == dst_pitch && width == src_pitch) - memcpy(dst, src, height * width); - else { - for (i = 0; i < height; i++) { - memcpy(dst, src, width); - dst += dst_pitch; - src += src_pitch; - } - } -} - - -/* Upload data to a rectangular sub-region. Lots of choices how to do this: - * - * - memcpy by span to current destination - * - upload data as new buffer and blit - * - * Currently always memcpy. - */ -static void -i915_region_data(struct pipe_context *pipe, - struct pipe_region *dst, - unsigned dst_offset, - unsigned dstx, unsigned dsty, - const void *src, unsigned src_pitch, - unsigned srcx, unsigned srcy, unsigned width, unsigned height) -{ - _mesa_copy_rect(pipe->region_map(pipe, dst) + dst_offset, - dst->cpp, - dst->pitch, - dstx, dsty, width, height, src, src_pitch, srcx, srcy); - - pipe->region_unmap(pipe, dst); -} - - -/* Assumes all values are within bounds -- no checking at this level - - * do it higher up if required. - */ -static void -i915_region_copy(struct pipe_context *pipe, - struct pipe_region *dst, - unsigned dst_offset, - unsigned dstx, unsigned dsty, - struct pipe_region *src, - unsigned src_offset, - unsigned srcx, unsigned srcy, unsigned width, unsigned height) -{ - assert( dst != src ); - assert( dst->cpp == src->cpp ); - - if (0) { - _mesa_copy_rect(pipe->region_map(pipe, dst) + dst_offset, - dst->cpp, - dst->pitch, - dstx, dsty, - width, height, - pipe->region_map(pipe, src) + src_offset, - src->pitch, - srcx, srcy); - - pipe->region_unmap(pipe, src); - pipe->region_unmap(pipe, dst); - } - else { - i915_copy_blit( i915_context(pipe), - dst->cpp, - (short) src->pitch, src->buffer, src_offset, - (short) dst->pitch, dst->buffer, dst_offset, - (short) srcx, (short) srcy, (short) dstx, (short) dsty, (short) width, (short) height ); - } -} - -/* Fill a rectangular sub-region. Need better logic about when to - * push buffers into AGP - will currently do so whenever possible. - */ -static ubyte * -get_pointer(struct pipe_region *dst, unsigned x, unsigned y) -{ - return dst->map + (y * dst->pitch + x) * dst->cpp; -} - - -static void -i915_region_fill(struct pipe_context *pipe, - struct pipe_region *dst, - unsigned dst_offset, - unsigned dstx, unsigned dsty, - unsigned width, unsigned height, unsigned value) -{ - if (0) { - unsigned i, j; - - (void)pipe->region_map(pipe, dst); - - switch (dst->cpp) { - case 1: { - ubyte *row = get_pointer(dst, dstx, dsty); - for (i = 0; i < height; i++) { - memset(row, value, width); - row += dst->pitch; - } - } - break; - case 2: { - ushort *row = (ushort *) get_pointer(dst, dstx, dsty); - for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) - row[j] = (ushort) value; - row += dst->pitch; - } - } - break; - case 4: { - unsigned *row = (unsigned *) get_pointer(dst, dstx, dsty); - for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) - row[j] = value; - row += dst->pitch; - } - } - break; - default: - assert(0); - break; - } - } - else { - i915_fill_blit( i915_context(pipe), - dst->cpp, - (short) dst->pitch, - dst->buffer, dst_offset, - (short) dstx, (short) dsty, - (short) width, (short) height, - value ); - } -} - - - - - void i915_init_region_functions(struct i915_context *i915) { i915->pipe.region_map = i915_region_map; i915->pipe.region_unmap = i915_region_unmap; - i915->pipe.region_data = i915_region_data; - i915->pipe.region_copy = i915_region_copy; - i915->pipe.region_fill = i915_region_fill; } diff --git a/src/mesa/pipe/i915simple/i915_state_emit.c b/src/mesa/pipe/i915simple/i915_state_emit.c index d793e92a14..900a91d896 100644 --- a/src/mesa/pipe/i915simple/i915_state_emit.c +++ b/src/mesa/pipe/i915simple/i915_state_emit.c @@ -208,10 +208,11 @@ i915_emit_hardware_state(struct i915_context *i915 ) /* 8 dwords, 2 relocs */ if (i915->hardware_dirty & I915_HW_STATIC) { - if (i915->framebuffer.cbufs[0]) { - struct pipe_region *cbuf_region = i915->framebuffer.cbufs[0]->region; - unsigned pitch = (cbuf_region->pitch * - cbuf_region->cpp); + struct pipe_surface *cbuf_surface = i915->framebuffer.cbufs[0]; + struct pipe_surface *depth_surface = i915->framebuffer.zbuf; + + if (cbuf_surface) { + unsigned pitch = (cbuf_surface->pitch * cbuf_surface->cpp); OUT_BATCH(_3DSTATE_BUF_INFO_CMD); @@ -219,17 +220,15 @@ i915_emit_hardware_state(struct i915_context *i915 ) BUF_3D_PITCH(pitch) | /* pitch in bytes */ BUF_3D_USE_FENCE); - OUT_RELOC(cbuf_region->buffer, + OUT_RELOC(cbuf_surface->region->buffer, I915_BUFFER_ACCESS_WRITE, 0); } /* What happens if no zbuf?? */ - if (i915->framebuffer.zbuf) { - struct pipe_region *depth_region = i915->framebuffer.zbuf->region; - unsigned zpitch = (depth_region->pitch * - depth_region->cpp); + if (depth_surface) { + unsigned zpitch = (depth_surface->pitch * depth_surface->cpp); OUT_BATCH(_3DSTATE_BUF_INFO_CMD); @@ -237,7 +236,7 @@ i915_emit_hardware_state(struct i915_context *i915 ) BUF_3D_PITCH(zpitch) | /* pitch in bytes */ BUF_3D_USE_FENCE); - OUT_RELOC(depth_region->buffer, + OUT_RELOC(depth_surface->region->buffer, I915_BUFFER_ACCESS_WRITE, 0); } @@ -245,13 +244,13 @@ i915_emit_hardware_state(struct i915_context *i915 ) { unsigned cformat, zformat = 0; - if (i915->framebuffer.cbufs[0]) - cformat = i915->framebuffer.cbufs[0]->format; + if (cbuf_surface) + cformat = cbuf_surface->format; else cformat = PIPE_FORMAT_U_A8_R8_G8_B8; /* arbitrary */ cformat = translate_format(cformat); - if (i915->framebuffer.zbuf) + if (depth_surface) zformat = translate_depth_format( i915->framebuffer.zbuf->format ); OUT_BATCH(_3DSTATE_DST_BUF_VARS_CMD); diff --git a/src/mesa/pipe/i915simple/i915_surface.c b/src/mesa/pipe/i915simple/i915_surface.c index bec7ddb731..e4a5de00d7 100644 --- a/src/mesa/pipe/i915simple/i915_surface.c +++ b/src/mesa/pipe/i915simple/i915_surface.c @@ -26,6 +26,7 @@ **************************************************************************/ #include "i915_context.h" +#include "i915_blit.h" #include "i915_state.h" #include "pipe/p_defines.h" #include "pipe/p_util.h" @@ -57,7 +58,7 @@ i915_get_tile_rgba(struct pipe_context *pipe, { const unsigned *src = ((const unsigned *) (ps->region->map + ps->offset)) - + y * ps->region->pitch + x; + + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -75,7 +76,7 @@ i915_get_tile_rgba(struct pipe_context *pipe, pRow[3] = UBYTE_TO_FLOAT((pixel >> 24) & 0xff); pRow += 4; } - src += ps->region->pitch; + src += ps->pitch; p += w0 * 4; } break; @@ -92,7 +93,7 @@ i915_get_tile_rgba(struct pipe_context *pipe, pRow[3] = (pixel & 0xffffff) * scale; pRow += 4; } - src += ps->region->pitch; + src += ps->pitch; p += w0 * 4; } } @@ -122,7 +123,7 @@ i915_get_tile(struct pipe_context *pipe, uint x, uint y, uint w, uint h, void *p, int dst_stride) { - const uint cpp = ps->region->cpp; + const uint cpp = ps->cpp; const uint w0 = w; const ubyte *pSrc; ubyte *pDest; @@ -136,13 +137,13 @@ i915_get_tile(struct pipe_context *pipe, dst_stride = w0 * cpp; } - pSrc = ps->region->map + ps->offset + (y * ps->region->pitch + x) * cpp; + pSrc = ps->region->map + ps->offset + (y * ps->pitch + x) * cpp; pDest = (ubyte *) p; for (i = 0; i < h; i++) { memcpy(pDest, pSrc, w0 * cpp); pDest += dst_stride; - pSrc += ps->region->pitch * cpp; + pSrc += ps->pitch * cpp; } } @@ -156,7 +157,7 @@ i915_put_tile(struct pipe_context *pipe, uint x, uint y, uint w, uint h, const void *p, int src_stride) { - const uint cpp = ps->region->cpp; + const uint cpp = ps->cpp; const uint w0 = w; const ubyte *pSrc; ubyte *pDest; @@ -171,11 +172,11 @@ i915_put_tile(struct pipe_context *pipe, } pSrc = (const ubyte *) p; - pDest = ps->region->map + ps->offset + (y * ps->region->pitch + x) * cpp; + pDest = ps->region->map + ps->offset + (y * ps->pitch + x) * cpp; for (i = 0; i < h; i++) { memcpy(pDest, pSrc, w0 * cpp); - pDest += ps->region->pitch * cpp; + pDest += ps->pitch * cpp; pSrc += src_stride; } } @@ -210,14 +211,177 @@ i915_get_tex_surface(struct pipe_context *pipe, assert(ps->format); assert(ps->refcount); pipe_region_reference(&ps->region, mt->region); + ps->cpp = mt->cpp; ps->width = mt->level[level].width; ps->height = mt->level[level].height; + ps->pitch = mt->pitch; ps->offset = offset; } return ps; } +/* + * XXX Move this into core Mesa? + */ +static void +_mesa_copy_rect(ubyte * dst, + unsigned cpp, + unsigned dst_pitch, + unsigned dst_x, + unsigned dst_y, + unsigned width, + unsigned height, + const ubyte * src, + unsigned src_pitch, + unsigned src_x, + unsigned src_y) +{ + unsigned i; + + dst_pitch *= cpp; + src_pitch *= cpp; + dst += dst_x * cpp; + src += src_x * cpp; + dst += dst_y * dst_pitch; + src += src_y * dst_pitch; + width *= cpp; + + if (width == dst_pitch && width == src_pitch) + memcpy(dst, src, height * width); + else { + for (i = 0; i < height; i++) { + memcpy(dst, src, width); + dst += dst_pitch; + src += src_pitch; + } + } +} + + +/* Upload data to a rectangular sub-region. Lots of choices how to do this: + * + * - memcpy by span to current destination + * - upload data as new buffer and blit + * + * Currently always memcpy. + */ +static void +i915_surface_data(struct pipe_context *pipe, + struct pipe_surface *dst, + unsigned dstx, unsigned dsty, + const void *src, unsigned src_pitch, + unsigned srcx, unsigned srcy, unsigned width, unsigned height) +{ + _mesa_copy_rect(pipe->region_map(pipe, dst->region) + dst->offset, + dst->cpp, + dst->pitch, + dstx, dsty, width, height, src, src_pitch, srcx, srcy); + + pipe->region_unmap(pipe, dst->region); +} + + +/* Assumes all values are within bounds -- no checking at this level - + * do it higher up if required. + */ +static void +i915_surface_copy(struct pipe_context *pipe, + struct pipe_surface *dst, + unsigned dstx, unsigned dsty, + struct pipe_surface *src, + unsigned srcx, unsigned srcy, unsigned width, unsigned height) +{ + assert( dst != src ); + assert( dst->cpp == src->cpp ); + + if (0) { + _mesa_copy_rect(pipe->region_map(pipe, dst->region) + dst->offset, + dst->cpp, + dst->pitch, + dstx, dsty, + width, height, + pipe->region_map(pipe, src->region) + src->offset, + src->pitch, + srcx, srcy); + + pipe->region_unmap(pipe, src->region); + pipe->region_unmap(pipe, dst->region); + } + else { + i915_copy_blit( i915_context(pipe), + dst->cpp, + (short) src->pitch, src->region->buffer, src->offset, + (short) dst->pitch, dst->region->buffer, dst->offset, + (short) srcx, (short) srcy, (short) dstx, (short) dsty, (short) width, (short) height ); + } +} + +/* Fill a rectangular sub-region. Need better logic about when to + * push buffers into AGP - will currently do so whenever possible. + */ +static ubyte * +get_pointer(struct pipe_surface *dst, unsigned x, unsigned y) +{ + return dst->region->map + (y * dst->pitch + x) * dst->cpp; +} + + +static void +i915_surface_fill(struct pipe_context *pipe, + struct pipe_surface *dst, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height, unsigned value) +{ + if (0) { + unsigned i, j; + + (void)pipe->region_map(pipe, dst->region); + + switch (dst->cpp) { + case 1: { + ubyte *row = get_pointer(dst, dstx, dsty); + for (i = 0; i < height; i++) { + memset(row, value, width); + row += dst->pitch; + } + } + break; + case 2: { + ushort *row = (ushort *) get_pointer(dst, dstx, dsty); + for (i = 0; i < height; i++) { + for (j = 0; j < width; j++) + row[j] = (ushort) value; + row += dst->pitch; + } + } + break; + case 4: { + unsigned *row = (unsigned *) get_pointer(dst, dstx, dsty); + for (i = 0; i < height; i++) { + for (j = 0; j < width; j++) + row[j] = value; + row += dst->pitch; + } + } + break; + default: + assert(0); + break; + } + } + else { + i915_fill_blit( i915_context(pipe), + dst->cpp, + (short) dst->pitch, + dst->region->buffer, dst->offset, + (short) dstx, (short) dsty, + (short) width, (short) height, + value ); + } +} + + void i915_init_surface_functions(struct i915_context *i915) { @@ -226,4 +390,7 @@ i915_init_surface_functions(struct i915_context *i915) i915->pipe.put_tile = i915_put_tile; i915->pipe.get_tile_rgba = i915_get_tile_rgba; i915->pipe.put_tile_rgba = i915_put_tile_rgba; + i915->pipe.surface_data = i915_surface_data; + i915->pipe.surface_copy = i915_surface_copy; + i915->pipe.surface_fill = i915_surface_fill; } diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 8bed958feb..e145b22f2f 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -208,30 +208,30 @@ struct pipe_context { void (*region_unmap)(struct pipe_context *pipe, struct pipe_region *r); - void (*region_data)(struct pipe_context *pipe, - struct pipe_region *dest, - unsigned dest_offset, - unsigned destx, unsigned desty, - const void *src, unsigned src_stride, - unsigned srcx, unsigned srcy, - unsigned width, unsigned height); - - void (*region_copy)(struct pipe_context *pipe, - struct pipe_region *dest, - unsigned dest_offset, - unsigned destx, unsigned desty, - struct pipe_region *src, /* don't make this const - - need to map/unmap */ - unsigned src_offset, - unsigned srcx, unsigned srcy, - unsigned width, unsigned height); - - void (*region_fill)(struct pipe_context *pipe, - struct pipe_region *dst, - unsigned dst_offset, - unsigned dstx, unsigned dsty, - unsigned width, unsigned height, - unsigned value); + + /* + * Surface functions + */ + void (*surface_data)(struct pipe_context *pipe, + struct pipe_surface *dest, + unsigned destx, unsigned desty, + const void *src, unsigned src_stride, + unsigned srcx, unsigned srcy, + unsigned width, unsigned height); + + void (*surface_copy)(struct pipe_context *pipe, + struct pipe_surface *dest, + unsigned destx, unsigned desty, + struct pipe_surface *src, /* don't make this const - + need to map/unmap */ + unsigned srcx, unsigned srcy, + unsigned width, unsigned height); + + void (*surface_fill)(struct pipe_context *pipe, + struct pipe_surface *dst, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height, + unsigned value); /* diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index 570f44e24e..642734aeb8 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -265,9 +265,6 @@ struct pipe_region struct pipe_buffer_handle *buffer; /**< driver private buffer handle */ unsigned refcount; /**< Reference count for region */ - unsigned cpp; /**< bytes per pixel */ - unsigned pitch; /**< in pixels */ - unsigned height; /**< in pixels */ ubyte *map; /**< only non-NULL when region is actually mapped */ unsigned map_refcount; /**< Reference count for mapping */ }; @@ -281,7 +278,9 @@ struct pipe_surface { struct pipe_region *region; unsigned format; /**< PIPE_FORMAT_x */ + unsigned cpp; /**< bytes per pixel */ unsigned width, height; + unsigned pitch; /**< in pixels */ unsigned offset; /**< offset from start of region, in bytes */ unsigned refcount; struct pipe_winsys *winsys; /**< winsys which owns/created the surface */ diff --git a/src/mesa/pipe/p_winsys.h b/src/mesa/pipe/p_winsys.h index 41d522e11e..5adca1d6fd 100644 --- a/src/mesa/pipe/p_winsys.h +++ b/src/mesa/pipe/p_winsys.h @@ -80,12 +80,14 @@ struct pipe_winsys * flags is bitmask of PIPE_SURFACE_FLAG_RENDER, PIPE_SURFACE_FLAG_TEXTURE */ struct pipe_region *(*region_alloc)(struct pipe_winsys *ws, - unsigned cpp, unsigned width, - unsigned height, unsigned flags); + unsigned size, unsigned flags); void (*region_release)(struct pipe_winsys *ws, struct pipe_region **r); + unsigned (*surface_pitch)(struct pipe_winsys *ws, unsigned cpp, + unsigned with, unsigned flags); + /** allocate a new surface (no context dependency) */ struct pipe_surface *(*surface_alloc)(struct pipe_winsys *ws, unsigned format); diff --git a/src/mesa/pipe/softpipe/sp_clear.c b/src/mesa/pipe/softpipe/sp_clear.c index 87f850b6fd..a4276362b9 100644 --- a/src/mesa/pipe/softpipe/sp_clear.c +++ b/src/mesa/pipe/softpipe/sp_clear.c @@ -47,23 +47,9 @@ softpipe_clear(struct pipe_context *pipe, struct pipe_surface *ps, unsigned clearValue) { struct softpipe_context *softpipe = softpipe_context(pipe); - unsigned x, y, w, h; softpipe_update_derived(softpipe); /* not needed?? */ - /* Use the X coord to trick region_fill() into filling at an offset - * from the start of the region. Perhaps pipe_region should have the - * 'offset' field, not pipe_surface??? - */ - assert(ps->offset % ps->region->cpp == 0); - x = ps->offset / ps->region->cpp; - y = 0; - w = ps->width; - h = ps->height; - - assert(w <= ps->region->pitch); - assert(h <= ps->region->height); - if (ps == sp_tile_cache_get_surface(softpipe->zbuf_cache)) { float clear[4]; clear[0] = 1.0; /* XXX hack */ @@ -78,7 +64,7 @@ softpipe_clear(struct pipe_context *pipe, struct pipe_surface *ps, sp_tile_cache_clear(softpipe->cbuf_cache[0], clear); } - pipe->region_fill(pipe, ps->region, 0, x, y, w, h, clearValue); + pipe->surface_fill(pipe, ps, 0, 0, ps->width, ps->height, clearValue); #if 0 diff --git a/src/mesa/pipe/softpipe/sp_region.c b/src/mesa/pipe/softpipe/sp_region.c index fef63ef2f6..58dc6bb96e 100644 --- a/src/mesa/pipe/softpipe/sp_region.c +++ b/src/mesa/pipe/softpipe/sp_region.c @@ -70,196 +70,10 @@ sp_region_unmap(struct pipe_context *pipe, struct pipe_region *region) } - -/** - * Copy 2D rect from one place to another. - * Position and sizes are in pixels. - */ -static void -copy_rect(ubyte * dst, - unsigned cpp, - unsigned dst_pitch, - unsigned dst_x, - unsigned dst_y, - unsigned width, - unsigned height, - const ubyte * src, - unsigned src_pitch, - unsigned src_x, - unsigned src_y) -{ - unsigned i; - - dst_pitch *= cpp; - src_pitch *= cpp; - dst += dst_x * cpp; - src += src_x * cpp; - dst += dst_y * dst_pitch; - src += src_y * src_pitch; - width *= cpp; - - if (width == dst_pitch && width == src_pitch) - memcpy(dst, src, height * width); - else { - for (i = 0; i < height; i++) { - memcpy(dst, src, width); - dst += dst_pitch; - src += src_pitch; - } - } -} - - -/* Upload data to a rectangular sub-region. Lots of choices how to do this: - * - * - memcpy by span to current destination - * - upload data as new buffer and blit - * - * Currently always memcpy. - */ -static void -sp_region_data(struct pipe_context *pipe, - struct pipe_region *dst, - unsigned dst_offset, - unsigned dstx, unsigned dsty, - const void *src, unsigned src_pitch, - unsigned srcx, unsigned srcy, unsigned width, unsigned height) -{ - copy_rect(pipe->region_map(pipe, dst) + dst_offset, - dst->cpp, - dst->pitch, - dstx, dsty, width, height, src, src_pitch, srcx, srcy); - - pipe->region_unmap(pipe, dst); -} - -/* Assumes all values are within bounds -- no checking at this level - - * do it higher up if required. - */ -static void -sp_region_copy(struct pipe_context *pipe, - struct pipe_region *dst, - unsigned dst_offset, - unsigned dstx, unsigned dsty, - struct pipe_region *src, - unsigned src_offset, - unsigned srcx, unsigned srcy, unsigned width, unsigned height) -{ - ubyte *src_map, *dst_map; - assert( dst->cpp == src->cpp ); - - dst_map = pipe->region_map(pipe, dst); - src_map = pipe->region_map(pipe, src); - copy_rect(dst_map + dst_offset, - dst->cpp, - dst->pitch, - dstx, dsty, - width, height, - src_map + src_offset, - src->pitch, - srcx, srcy); - - pipe->region_unmap(pipe, src); - pipe->region_unmap(pipe, dst); -} - - -static ubyte * -get_pointer(struct pipe_region *dst, unsigned x, unsigned y) -{ - return dst->map + (y * dst->pitch + x) * dst->cpp; -} - - -#define UBYTE_TO_USHORT(B) ((B) | ((B) << 8)) - - -/** - * Fill a rectangular sub-region. Need better logic about when to - * push buffers into AGP - will currently do so whenever possible. - */ -static void -sp_region_fill(struct pipe_context *pipe, - struct pipe_region *dst, - unsigned dst_offset, - unsigned dstx, unsigned dsty, - unsigned width, unsigned height, unsigned value) -{ - unsigned i, j; - - assert(dst->pitch > 0); - assert(width <= dst->pitch); - - (void)pipe->region_map(pipe, dst); - - switch (dst->cpp) { - case 1: - { - ubyte *row = get_pointer(dst, dstx, dsty); - for (i = 0; i < height; i++) { - memset(row, value, width); - row += dst->pitch; - } - } - break; - case 2: - { - ushort *row = (ushort *) get_pointer(dst, dstx, dsty); - for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) - row[j] = (ushort) value; - row += dst->pitch; - } - } - break; - case 4: - { - unsigned *row = (unsigned *) get_pointer(dst, dstx, dsty); - for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) - row[j] = value; - row += dst->pitch; - } - } - break; - case 8: - { - /* expand the 4-byte clear value to an 8-byte value */ - ushort *row = (ushort *) get_pointer(dst, dstx, dsty); - ushort val0 = UBYTE_TO_USHORT((value >> 0) & 0xff); - ushort val1 = UBYTE_TO_USHORT((value >> 8) & 0xff); - ushort val2 = UBYTE_TO_USHORT((value >> 16) & 0xff); - ushort val3 = UBYTE_TO_USHORT((value >> 24) & 0xff); - for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) { - row[j*4+0] = val0; - row[j*4+1] = val1; - row[j*4+2] = val2; - row[j*4+3] = val3; - } - row += dst->pitch * 4; - } - } - break; - default: - assert(0); - break; - } - - pipe->region_unmap( pipe, dst ); -} - - - - - void sp_init_region_functions(struct softpipe_context *sp) { sp->pipe.region_map = sp_region_map; sp->pipe.region_unmap = sp_region_unmap; - sp->pipe.region_data = sp_region_data; - sp->pipe.region_copy = sp_region_copy; - sp->pipe.region_fill = sp_region_fill; } diff --git a/src/mesa/pipe/softpipe/sp_surface.c b/src/mesa/pipe/softpipe/sp_surface.c index b7c9d4f004..2ddf3ab99c 100644 --- a/src/mesa/pipe/softpipe/sp_surface.c +++ b/src/mesa/pipe/softpipe/sp_surface.c @@ -77,7 +77,7 @@ a8r8g8b8_get_tile(struct pipe_surface *ps, { const unsigned *src = ((const unsigned *) (ps->region->map + ps->offset)) - + y * ps->region->pitch + x; + + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -95,7 +95,7 @@ a8r8g8b8_get_tile(struct pipe_surface *ps, pRow[3] = UBYTE_TO_FLOAT((pixel >> 24) & 0xff); pRow += 4; } - src += ps->region->pitch; + src += ps->pitch; p += w0 * 4; } } @@ -108,7 +108,7 @@ a8r8g8b8_put_tile(struct pipe_surface *ps, { unsigned *dst = ((unsigned *) (ps->region->map + ps->offset)) - + y * ps->region->pitch + x; + + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -127,7 +127,7 @@ a8r8g8b8_put_tile(struct pipe_surface *ps, dst[j] = (a << 24) | (r << 16) | (g << 8) | b; pRow += 4; } - dst += ps->region->pitch; + dst += ps->pitch; p += w0 * 4; } } @@ -141,7 +141,7 @@ a1r5g5b5_get_tile(struct pipe_surface *ps, { const ushort *src = ((const ushort *) (ps->region->map + ps->offset)) - + y * ps->region->pitch + x; + + y * ps->pitch + x; unsigned i, j; assert(ps->format == PIPE_FORMAT_U_A1_R5_G5_B5); @@ -155,7 +155,7 @@ a1r5g5b5_get_tile(struct pipe_surface *ps, p[3] = ((pixel >> 15) ) * 1.0f; p += 4; } - src += ps->region->pitch; + src += ps->pitch; } } @@ -172,7 +172,7 @@ z16_get_tile(struct pipe_surface *ps, { const ushort *src = ((const ushort *) (ps->region->map + ps->offset)) - + y * ps->region->pitch + x; + + y * ps->pitch + x; const float scale = 1.0f / 65535.0f; unsigned i, j; unsigned w0 = w; @@ -189,7 +189,7 @@ z16_get_tile(struct pipe_surface *ps, pRow[j * 4 + 2] = pRow[j * 4 + 3] = src[j] * scale; } - src += ps->region->pitch; + src += ps->pitch; p += 4 * w0; } } @@ -205,7 +205,7 @@ l8_get_tile(struct pipe_surface *ps, { const ubyte *src = ((const ubyte *) (ps->region->map + ps->offset)) - + y * ps->region->pitch + x; + + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -222,7 +222,7 @@ l8_get_tile(struct pipe_surface *ps, pRow[3] = 1.0; pRow += 4; } - src += ps->region->pitch; + src += ps->pitch; p += w0 * 4; } } @@ -236,7 +236,7 @@ a8_get_tile(struct pipe_surface *ps, { const ubyte *src = ((const ubyte *) (ps->region->map + ps->offset)) - + y * ps->region->pitch + x; + + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -253,7 +253,7 @@ a8_get_tile(struct pipe_surface *ps, pRow[3] = UBYTE_TO_FLOAT(src[j]); pRow += 4; } - src += ps->region->pitch; + src += ps->pitch; p += w0 * 4; } } @@ -267,7 +267,7 @@ r16g16b16a16_get_tile(struct pipe_surface *ps, { const short *src = ((const short *) (ps->region->map + ps->offset)) - + (y * ps->region->pitch + x) * 4; + + (y * ps->pitch + x) * 4; unsigned i, j; unsigned w0 = w; @@ -286,7 +286,7 @@ r16g16b16a16_get_tile(struct pipe_surface *ps, pRow += 4; pixel += 4; } - src += ps->region->pitch * 4; + src += ps->pitch * 4; p += w0 * 4; } } @@ -299,7 +299,7 @@ r16g16b16a16_put_tile(struct pipe_surface *ps, { short *dst = ((short *) (ps->region->map + ps->offset)) - + (y * ps->region->pitch + x) * 4; + + (y * ps->pitch + x) * 4; unsigned i, j; unsigned w0 = w; @@ -321,7 +321,7 @@ r16g16b16a16_put_tile(struct pipe_surface *ps, dst[j*4+3] = a; pRow += 4; } - dst += ps->region->pitch * 4; + dst += ps->pitch * 4; p += w0 * 4; } } @@ -336,7 +336,7 @@ i8_get_tile(struct pipe_surface *ps, { const ubyte *src = ((const ubyte *) (ps->region->map + ps->offset)) - + y * ps->region->pitch + x; + + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -353,7 +353,7 @@ i8_get_tile(struct pipe_surface *ps, pRow[3] = UBYTE_TO_FLOAT(src[j]); pRow += 4; } - src += ps->region->pitch; + src += ps->pitch; p += w0 * 4; } } @@ -367,7 +367,7 @@ a8_l8_get_tile(struct pipe_surface *ps, { const ushort *src = ((const ushort *) (ps->region->map + ps->offset)) - + y * ps->region->pitch + x; + + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -385,7 +385,7 @@ a8_l8_get_tile(struct pipe_surface *ps, pRow[3] = UBYTE_TO_FLOAT(p >> 8); pRow += 4; } - src += ps->region->pitch; + src += ps->pitch; p += w0 * 4; } } @@ -404,7 +404,7 @@ z32_get_tile(struct pipe_surface *ps, { const uint *src = ((const uint *) (ps->region->map + ps->offset)) - + y * ps->region->pitch + x; + + y * ps->pitch + x; const double scale = 1.0 / (double) 0xffffffff; unsigned i, j; unsigned w0 = w; @@ -421,7 +421,7 @@ z32_get_tile(struct pipe_surface *ps, pRow[j * 4 + 2] = pRow[j * 4 + 3] = (float) (scale * src[j]); } - src += ps->region->pitch; + src += ps->pitch; p += 4 * w0; } } @@ -438,7 +438,7 @@ s8z24_get_tile(struct pipe_surface *ps, { const uint *src = ((const uint *) (ps->region->map + ps->offset)) - + y * ps->region->pitch + x; + + y * ps->pitch + x; const double scale = 1.0 / ((1 << 24) - 1); unsigned i, j; unsigned w0 = w; @@ -455,7 +455,7 @@ s8z24_get_tile(struct pipe_surface *ps, pRow[j * 4 + 2] = pRow[j * 4 + 3] = (float) (scale * (src[j] & 0xffffff)); } - src += ps->region->pitch; + src += ps->pitch; p += 4 * w0; } } @@ -472,7 +472,7 @@ z24s8_get_tile(struct pipe_surface *ps, { const uint *src = ((const uint *) (ps->region->map + ps->offset)) - + y * ps->region->pitch + x; + + y * ps->pitch + x; const double scale = 1.0 / ((1 << 24) - 1); unsigned i, j; unsigned w0 = w; @@ -489,7 +489,7 @@ z24s8_get_tile(struct pipe_surface *ps, pRow[j * 4 + 2] = pRow[j * 4 + 3] = (float) (scale * (src[j] >> 8)); } - src += ps->region->pitch; + src += ps->pitch; p += 4 * w0; } } @@ -525,8 +525,10 @@ softpipe_get_tex_surface(struct pipe_context *pipe, assert(ps->format); assert(ps->refcount); pipe_region_reference(&ps->region, mt->region); + ps->cpp = mt->cpp; ps->width = mt->level[level].width; ps->height = mt->level[level].height; + ps->pitch = mt->pitch; ps->offset = offset; } return ps; @@ -541,7 +543,7 @@ softpipe_get_tile(struct pipe_context *pipe, struct pipe_surface *ps, uint x, uint y, uint w, uint h, void *p, int dst_stride) { - const uint cpp = ps->region->cpp; + const uint cpp = ps->cpp; const ubyte *pSrc; ubyte *pDest; uint i; @@ -554,13 +556,13 @@ softpipe_get_tile(struct pipe_context *pipe, struct pipe_surface *ps, CLIP_TILE; - pSrc = ps->region->map + ps->offset + (y * ps->region->pitch + x) * cpp; + pSrc = ps->region->map + ps->offset + (y * ps->pitch + x) * cpp; pDest = (ubyte *) p; for (i = 0; i < h; i++) { memcpy(pDest, pSrc, w * cpp); pDest += dst_stride; - pSrc += ps->region->pitch * cpp; + pSrc += ps->pitch * cpp; } } @@ -573,7 +575,7 @@ softpipe_put_tile(struct pipe_context *pipe, struct pipe_surface *ps, uint x, uint y, uint w, uint h, const void *p, int src_stride) { - const uint cpp = ps->region->cpp; + const uint cpp = ps->cpp; const ubyte *pSrc; ubyte *pDest; uint i; @@ -587,11 +589,11 @@ softpipe_put_tile(struct pipe_context *pipe, struct pipe_surface *ps, CLIP_TILE; pSrc = (const ubyte *) p; - pDest = ps->region->map + ps->offset + (y * ps->region->pitch + x) * cpp; + pDest = ps->region->map + ps->offset + (y * ps->pitch + x) * cpp; for (i = 0; i < h; i++) { memcpy(pDest, pSrc, w * cpp); - pDest += ps->region->pitch * cpp; + pDest += ps->pitch * cpp; pSrc += src_stride; } } @@ -691,6 +693,180 @@ softpipe_put_tile_rgba(struct pipe_context *pipe, } +/** + * Copy 2D rect from one place to another. + * Position and sizes are in pixels. + */ +static void +copy_rect(ubyte * dst, + unsigned cpp, + unsigned dst_pitch, + unsigned dst_x, + unsigned dst_y, + unsigned width, + unsigned height, + const ubyte * src, + unsigned src_pitch, + unsigned src_x, + unsigned src_y) +{ + unsigned i; + + dst_pitch *= cpp; + src_pitch *= cpp; + dst += dst_x * cpp; + src += src_x * cpp; + dst += dst_y * dst_pitch; + src += src_y * src_pitch; + width *= cpp; + + if (width == dst_pitch && width == src_pitch) + memcpy(dst, src, height * width); + else { + for (i = 0; i < height; i++) { + memcpy(dst, src, width); + dst += dst_pitch; + src += src_pitch; + } + } +} + + +/* Upload data to a rectangular sub-region. Lots of choices how to do this: + * + * - memcpy by span to current destination + * - upload data as new buffer and blit + * + * Currently always memcpy. + */ +static void +sp_surface_data(struct pipe_context *pipe, + struct pipe_surface *dst, + unsigned dstx, unsigned dsty, + const void *src, unsigned src_pitch, + unsigned srcx, unsigned srcy, unsigned width, unsigned height) +{ + copy_rect(pipe->region_map(pipe, dst->region) + dst->offset, + dst->cpp, + dst->pitch, + dstx, dsty, width, height, src, src_pitch, srcx, srcy); + + pipe->region_unmap(pipe, dst->region); +} + +/* Assumes all values are within bounds -- no checking at this level - + * do it higher up if required. + */ +static void +sp_surface_copy(struct pipe_context *pipe, + struct pipe_surface *dst, + unsigned dstx, unsigned dsty, + struct pipe_surface *src, + unsigned srcx, unsigned srcy, unsigned width, unsigned height) +{ + ubyte *src_map, *dst_map; + assert( dst->cpp == src->cpp ); + + dst_map = pipe->region_map(pipe, dst->region); + src_map = pipe->region_map(pipe, src->region); + copy_rect(dst_map + dst->offset, + dst->cpp, + dst->pitch, + dstx, dsty, + width, height, + src_map + src->offset, + src->pitch, + srcx, srcy); + + pipe->region_unmap(pipe, src->region); + pipe->region_unmap(pipe, dst->region); +} + + +static ubyte * +get_pointer(struct pipe_surface *dst, unsigned x, unsigned y) +{ + return dst->region->map + (y * dst->pitch + x) * dst->cpp; +} + + +#define UBYTE_TO_USHORT(B) ((B) | ((B) << 8)) + + +/** + * Fill a rectangular sub-region. Need better logic about when to + * push buffers into AGP - will currently do so whenever possible. + */ +static void +sp_surface_fill(struct pipe_context *pipe, + struct pipe_surface *dst, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height, unsigned value) +{ + unsigned i, j; + + assert(dst->pitch > 0); + assert(width <= dst->pitch); + + (void)pipe->region_map(pipe, dst->region); + + switch (dst->cpp) { + case 1: + { + ubyte *row = get_pointer(dst, dstx, dsty); + for (i = 0; i < height; i++) { + memset(row, value, width); + row += dst->pitch; + } + } + break; + case 2: + { + ushort *row = (ushort *) get_pointer(dst, dstx, dsty); + for (i = 0; i < height; i++) { + for (j = 0; j < width; j++) + row[j] = (ushort) value; + row += dst->pitch; + } + } + break; + case 4: + { + unsigned *row = (unsigned *) get_pointer(dst, dstx, dsty); + for (i = 0; i < height; i++) { + for (j = 0; j < width; j++) + row[j] = value; + row += dst->pitch; + } + } + break; + case 8: + { + /* expand the 4-byte clear value to an 8-byte value */ + ushort *row = (ushort *) get_pointer(dst, dstx, dsty); + ushort val0 = UBYTE_TO_USHORT((value >> 0) & 0xff); + ushort val1 = UBYTE_TO_USHORT((value >> 8) & 0xff); + ushort val2 = UBYTE_TO_USHORT((value >> 16) & 0xff); + ushort val3 = UBYTE_TO_USHORT((value >> 24) & 0xff); + for (i = 0; i < height; i++) { + for (j = 0; j < width; j++) { + row[j*4+0] = val0; + row[j*4+1] = val1; + row[j*4+2] = val2; + row[j*4+3] = val3; + } + row += dst->pitch * 4; + } + } + break; + default: + assert(0); + break; + } + + pipe->region_unmap( pipe, dst->region ); +} + void sp_init_surface_functions(struct softpipe_context *sp) @@ -700,4 +876,8 @@ sp_init_surface_functions(struct softpipe_context *sp) sp->pipe.get_tile_rgba = softpipe_get_tile_rgba; sp->pipe.put_tile_rgba = softpipe_put_tile_rgba; + + sp->pipe.surface_data = sp_surface_data; + sp->pipe.surface_copy = sp_surface_copy; + sp->pipe.surface_fill = sp_surface_fill; } diff --git a/src/mesa/pipe/xlib/xm_buffer.c b/src/mesa/pipe/xlib/xm_buffer.c index 7dc85bf2eb..71a2003e6d 100644 --- a/src/mesa/pipe/xlib/xm_buffer.c +++ b/src/mesa/pipe/xlib/xm_buffer.c @@ -260,9 +260,8 @@ finish_surface_init(GLcontext *ctx, struct xmesa_renderbuffer *xrb) { struct pipe_context *pipe = ctx->st->pipe; if (!xrb->St.surface->region) { - int w = 1, h = 1; - xrb->St.surface->region = pipe->winsys->region_alloc(pipe->winsys, - 1, w, h, 0x0); + xrb->St.surface->region = pipe->winsys->region_alloc(pipe->winsys, 1, + 0x0); } } diff --git a/src/mesa/pipe/xlib/xm_surface.c b/src/mesa/pipe/xlib/xm_surface.c index 43e5050747..2394563095 100644 --- a/src/mesa/pipe/xlib/xm_surface.c +++ b/src/mesa/pipe/xlib/xm_surface.c @@ -624,7 +624,7 @@ xmesa_new_color_surface(struct pipe_winsys *winsys, GLuint pipeFormat) * The region's size will get set in the xmesa_alloc_front/back_storage() * functions. */ - xms->surface.region = winsys->region_alloc(winsys, 1, 1, 1, 0x0); + xms->surface.region = winsys->region_alloc(winsys, 1, 0x0); return &xms->surface; } diff --git a/src/mesa/pipe/xlib/xm_winsys.c b/src/mesa/pipe/xlib/xm_winsys.c index b842cf766e..99816a811d 100644 --- a/src/mesa/pipe/xlib/xm_winsys.c +++ b/src/mesa/pipe/xlib/xm_winsys.c @@ -220,27 +220,30 @@ round_up(unsigned n, unsigned multiple) } +static unsigned +xm_surface_pitch(struct pipe_winsys *winsys, unsigned cpp, unsigned width, + unsigned flags) +{ + return round_up(width, 64 / cpp); +} + + static struct pipe_region * -xm_region_alloc(struct pipe_winsys *winsys, - unsigned cpp, unsigned width, unsigned height, unsigned flags) +xm_region_alloc(struct pipe_winsys *winsys, unsigned size, unsigned flags) { struct pipe_region *region = CALLOC_STRUCT(pipe_region); const unsigned alignment = 64; - region->cpp = cpp; - region->pitch = round_up(width, alignment / cpp); - region->height = height; region->refcount = 1; - assert(region->pitch > 0); + assert(size > 0); - region->buffer = winsys->buffer_create( winsys, alignment ) -; + region->buffer = winsys->buffer_create( winsys, alignment ); /* NULL data --> just allocate the space */ winsys->buffer_data( winsys, region->buffer, - region->pitch * cpp * height, + size, NULL, PIPE_BUFFER_USAGE_PIXEL ); return region; @@ -335,6 +338,7 @@ xmesa_get_pipe_winsys(void) ws->region_alloc = xm_region_alloc; ws->region_release = xm_region_release; + ws->surface_pitch = xm_surface_pitch; ws->surface_alloc = xm_surface_alloc; ws->surface_release = xm_surface_release; diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index df41d5ce5b..39c0cf6b32 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -455,10 +455,6 @@ alloc_mipmap_tree(struct st_context *st, cpp = st_sizeof_format(pipeFormat); - /* allocate texture region/storage */ - mt->region = st->pipe->winsys->region_alloc(st->pipe->winsys, - cpp, width, height, flags); - mt->target = PIPE_TEXTURE_2D; mt->internal_format = GL_RGBA; mt->format = pipeFormat; @@ -469,7 +465,10 @@ alloc_mipmap_tree(struct st_context *st, mt->depth0 = 1; mt->cpp = cpp; mt->compressed = 0; - mt->pitch = mt->region->pitch; + mt->pitch = st->pipe->winsys->surface_pitch(st->pipe->winsys, cpp, width, + flags); + mt->region = st->pipe->winsys->region_alloc(st->pipe->winsys, + mt->pitch * cpp * height, flags); mt->depth_pitch = 0; mt->total_height = height; mt->level[0].level_offset = 0; @@ -524,7 +523,7 @@ make_mipmap_tree(struct st_context *st, { static const GLuint dstImageOffsets = 0; GLboolean success; - GLuint pitch = mt->region->pitch; + GLuint pitch = mt->pitch; GLubyte *dest; const GLbitfield imageTransferStateSave = ctx->_ImageTransferState; @@ -569,7 +568,7 @@ make_mipmap_tree(struct st_context *st, mt->depth0 = 1; mt->cpp = cpp; mt->compressed = 0; - mt->pitch = mt->region->pitch; + mt->pitch = mt->pitch; mt->depth_pitch = 0; mt->total_height = height; mt->level[0].level_offset = 0; @@ -952,13 +951,13 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, switch (ps->format) { case PIPE_FORMAT_U_S8: { - ubyte *dest = stmap + spanY * ps->region->pitch + spanX; + ubyte *dest = stmap + spanY * ps->pitch + spanX; memcpy(dest, values, spanWidth); } break; case PIPE_FORMAT_S8_Z24: { - uint *dest = (uint *) stmap + spanY * ps->region->pitch + spanX; + uint *dest = (uint *) stmap + spanY * ps->pitch + spanX; GLint k; for (k = 0; k < spanWidth; k++) { uint p = dest[k]; @@ -1054,7 +1053,7 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, { struct pipe_context *pipe = ctx->st->pipe; const uint flags = PIPE_SURFACE_FLAG_TEXTURE; - uint format = 0, cpp, comp, pitch; + uint format = 0, cpp, comp; ubyte *dest; struct pipe_mipmap_tree *mt; int row, col; @@ -1091,9 +1090,9 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, /* allocate texture region/storage */ + mt->pitch = pipe->winsys->surface_pitch(pipe->winsys, cpp, width, flags); mt->region = pipe->winsys->region_alloc(pipe->winsys, - cpp, width, height, flags); - pitch = mt->region->pitch; + mt->pitch * cpp * height, flags); /* map texture region */ dest = pipe->region_map(pipe, mt->region); @@ -1110,7 +1109,7 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, for (row = 0; row < height; row++) { const GLubyte *src = (const GLubyte *) _mesa_image_address2d(unpack, bitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, row, 0); - ubyte *destRow = dest + row * pitch * cpp; + ubyte *destRow = dest + row * mt->pitch * cpp; if (unpack->LsbFirst) { /* Lsb first */ @@ -1172,7 +1171,6 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, mt->depth0 = 1; mt->cpp = cpp; mt->compressed = 0; - mt->pitch = mt->region->pitch; mt->depth_pitch = 0; mt->total_height = height; mt->level[0].level_offset = 0; @@ -1256,7 +1254,7 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, y = ctx->DrawBuffer->Height - y - 1; } - dst = drawMap + (y * psDraw->region->pitch + dstx) * psDraw->region->cpp; + dst = drawMap + (y * psDraw->pitch + dstx) * psDraw->cpp; src = buffer + i * width; switch (psDraw->format) { @@ -1297,6 +1295,7 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, struct st_vertex_program *stvp; struct st_fragment_program *stfp; struct pipe_surface *psRead; + struct pipe_surface *psTex; struct pipe_mipmap_tree *mt; GLfloat *color; uint format; @@ -1332,6 +1331,8 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, if (!mt) return; + psTex = pipe->get_tex_surface(pipe, mt, 0, 0, 0); + if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) { srcy = ctx->DrawBuffer->Height - srcy - height; } @@ -1342,21 +1343,16 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, */ if (st->haveFramebufferRegions) { /* copy source framebuffer region into mipmap/texture */ - pipe->region_copy(pipe, - mt->region, /* dest */ - 0, /* dest_offset */ - 0, 0, /* destx/y */ - psRead->region, - 0, /* src_offset */ - srcx, srcy, width, height); + pipe->surface_copy(pipe, + psTex, /* dest */ + 0, 0, /* destx/y */ + psRead, + srcx, srcy, width, height); } else { /* alternate path using get/put_tile() */ - struct pipe_surface *psTex; GLfloat *buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - psTex = pipe->get_tex_surface(pipe, mt, 0, 0, 0); - (void) pipe->region_map(pipe, psRead->region); (void) pipe->region_map(pipe, psTex->region); @@ -1366,17 +1362,15 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, pipe->region_unmap(pipe, psRead->region); pipe->region_unmap(pipe, psTex->region); - pipe_surface_reference(&psTex, NULL); - free(buf); } - /* draw textured quad */ draw_textured_quad(ctx, dstx, dsty, ctx->Current.RasterPos[2], width, height, ctx->Pixel.ZoomX, ctx->Pixel.ZoomY, mt, stvp, stfp, color, GL_TRUE); + pipe_surface_reference(&psTex, NULL); free_mipmap_tree(st->pipe, mt); } diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index f58d532b2a..80c92e8b7a 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -104,6 +104,9 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, assert(strb->surface); if (!strb->surface) return GL_FALSE; + strb->surface->cpp = cpp; + strb->surface->pitch = pipe->winsys->surface_pitch(pipe->winsys, cpp, + width, flags); } /* free old region */ @@ -115,8 +118,9 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, pipe->winsys->region_release(pipe->winsys, &strb->surface->region); } - strb->surface->region = pipe->winsys->region_alloc(pipe->winsys, cpp, - width, height, flags); + strb->surface->region = pipe->winsys->region_alloc(pipe->winsys, + strb->surface->pitch * + cpp * height, flags); if (!strb->surface->region) return GL_FALSE; /* out of memory, try s/w buffer? */ diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c index 2e7c01672a..83fe480af8 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -87,13 +87,13 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, switch (ps->format) { case PIPE_FORMAT_U_S8: { - const ubyte *src = stmap + srcY * ps->region->pitch + x; + const ubyte *src = stmap + srcY * ps->pitch + x; memcpy(values, src, width); } break; case PIPE_FORMAT_S8_Z24: { - const uint *src = (uint *) stmap + srcY * ps->region->pitch + x; + const uint *src = (uint *) stmap + srcY * ps->pitch + x; GLint k; for (k = 0; k < width; k++) { values[k] = src[k] >> 24; @@ -102,7 +102,7 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, break; case PIPE_FORMAT_Z24_S8: { - const uint *src = (uint *) stmap + srcY * ps->region->pitch + x; + const uint *src = (uint *) stmap + srcY * ps->pitch + x; GLint k; for (k = 0; k < width; k++) { values[k] = src[k] & 0xff; diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 4e6d4857f4..461705119f 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -44,6 +44,7 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "pipe/p_inlines.h" #define DBG if (0) printf @@ -1150,7 +1151,6 @@ do_copy_texsubimage(GLcontext *ctx, struct st_renderbuffer *strb; struct pipe_context *pipe = ctx->st->pipe; struct pipe_region *src_region, *dest_region; - uint dest_offset, src_offset; uint dest_format, src_format; (void) texImage; @@ -1185,12 +1185,13 @@ do_copy_texsubimage(GLcontext *ctx, ctx->_ImageTransferState == 0x0 && src_region && dest_region && - src_region->cpp == dest_region->cpp) { + strb->surface->cpp == stImage->mt->cpp) { /* do blit-style copy */ - src_offset = 0; - dest_offset = st_miptree_image_offset(stImage->mt, - stImage->face, - stImage->level); + struct pipe_surface *dest_surface = pipe->get_tex_surface(pipe, + stImage->mt, + stImage->face, + stImage->level, + destZ); /* XXX may need to invert image depending on window * vs. user-created FBO @@ -1213,18 +1214,18 @@ do_copy_texsubimage(GLcontext *ctx, GL_COPY); /* ? */ #else - pipe->region_copy(pipe, - /* dest */ - dest_region, - dest_offset, - destX, destY, - /* src */ - src_region, - src_offset, - srcX, srcY, - /* size */ - width, height); + pipe->surface_copy(pipe, + /* dest */ + dest_surface, + destX, destY, + /* src */ + strb->surface, + srcX, srcY, + /* size */ + width, height); #endif + + pipe_surface_reference(&dest_surface, NULL); } else { fallback_copy_texsubimage(ctx, target, level, diff --git a/src/mesa/state_tracker/st_mipmap_tree.c b/src/mesa/state_tracker/st_mipmap_tree.c index d1db590bee..6ccf33105f 100644 --- a/src/mesa/state_tracker/st_mipmap_tree.c +++ b/src/mesa/state_tracker/st_mipmap_tree.c @@ -31,6 +31,8 @@ #include "pipe/p_state.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "pipe/p_util.h" +#include "pipe/p_inlines.h" #include "pipe/p_winsys.h" @@ -87,10 +89,9 @@ st_miptree_create(struct pipe_context *pipe, ok = pipe->mipmap_tree_layout(pipe, mt); if (ok) { - /* note: it's OK to pass 'pitch' as 'width' here: */ - mt->region = pipe->winsys->region_alloc(pipe->winsys, mt->cpp, mt->pitch, - mt->total_height, flags); - mt->pitch = mt->region->pitch; /*XXX NEW */ + mt->region = pipe->winsys->region_alloc(pipe->winsys, + mt->pitch * mt->cpp * + mt->total_height, flags); } if (!mt->region) { @@ -266,24 +267,27 @@ st_miptree_image_data(struct pipe_context *pipe, GLuint src_row_pitch, GLuint src_image_pitch) { GLuint depth = dst->level[level].depth; - GLuint dst_offset = st_miptree_image_offset(dst, face, level); - const GLuint *dst_depth_offset = st_miptree_depth_offsets(dst, level); GLuint i; GLuint height = 0; const GLubyte *srcUB = src; + struct pipe_surface *dst_surface; DBG("%s\n", __FUNCTION__); for (i = 0; i < depth; i++) { height = dst->level[level].height; if(dst->compressed) height /= 4; - pipe->region_data(pipe, dst->region, - dst_offset + dst_depth_offset[i], /* dst_offset */ - 0, 0, /* dstx, dsty */ - srcUB, - src_row_pitch, - 0, 0, /* source x, y */ - dst->level[level].width, height); /* width, height */ + + dst_surface = pipe->get_tex_surface(pipe, dst, face, level, i); + + pipe->surface_data(pipe, dst_surface, + 0, 0, /* dstx, dsty */ + srcUB, + src_row_pitch, + 0, 0, /* source x, y */ + dst->level[level].width, height); /* width, height */ + + pipe_surface_reference(&dst_surface, NULL); srcUB += src_image_pitch * dst->cpp; } @@ -300,21 +304,25 @@ st_miptree_image_copy(struct pipe_context *pipe, GLuint width = src->level[level].width; GLuint height = src->level[level].height; GLuint depth = src->level[level].depth; - GLuint dst_offset = st_miptree_image_offset(dst, face, level); - GLuint src_offset = st_miptree_image_offset(src, face, level); - const GLuint *dst_depth_offset = st_miptree_depth_offsets(dst, level); - const GLuint *src_depth_offset = st_miptree_depth_offsets(src, level); + struct pipe_surface *src_surface; + struct pipe_surface *dst_surface; GLuint i; if (dst->compressed) height /= 4; for (i = 0; i < depth; i++) { - pipe->region_copy(pipe, - dst->region, dst_offset + dst_depth_offset[i], - 0, 0, /* destX, Y */ - src->region, src_offset + src_depth_offset[i], - 0, 0, /* srcX, Y */ - width, height); + dst_surface = pipe->get_tex_surface(pipe, dst, face, level, i); + src_surface = pipe->get_tex_surface(pipe, src, face, level, i); + + pipe->surface_copy(pipe, + dst_surface, + 0, 0, /* destX, Y */ + src_surface, + 0, 0, /* srcX, Y */ + width, height); + + pipe_surface_reference(&dst_surface, NULL); + pipe_surface_reference(&src_surface, NULL); } } -- cgit v1.2.3 From 753db0d8407147393a7b0622ae3fa28f68d0353d Mon Sep 17 00:00:00 2001 From: Michel Dänzer Date: Fri, 30 Nov 2007 20:48:03 +0100 Subject: Hide texture layout details from the state tracker. pipe->get_tex_surface() has to be used for access to texture image data. --- src/mesa/drivers/dri/intel_winsys/intel_screen.c | 4 +- src/mesa/pipe/failover/fo_context.c | 3 +- src/mesa/pipe/failover/fo_context.h | 2 +- src/mesa/pipe/failover/fo_state.c | 2 +- src/mesa/pipe/i915simple/Makefile | 2 +- src/mesa/pipe/i915simple/i915_context.c | 9 +- src/mesa/pipe/i915simple/i915_context.h | 30 +- src/mesa/pipe/i915simple/i915_state.c | 4 +- src/mesa/pipe/i915simple/i915_state_sampler.c | 29 +- src/mesa/pipe/i915simple/i915_surface.c | 25 +- src/mesa/pipe/i915simple/i915_tex_layout.c | 474 -------------------- src/mesa/pipe/i915simple/i915_tex_layout.h | 16 - src/mesa/pipe/i915simple/i915_texture.c | 539 +++++++++++++++++++++++ src/mesa/pipe/i915simple/i915_texture.h | 16 + src/mesa/pipe/llvm/llvm_entry.c | 2 - src/mesa/pipe/p_context.h | 11 +- src/mesa/pipe/p_inlines.h | 20 + src/mesa/pipe/p_state.h | 42 +- src/mesa/pipe/softpipe/Makefile | 2 +- src/mesa/pipe/softpipe/sp_context.c | 17 +- src/mesa/pipe/softpipe/sp_context.h | 2 +- src/mesa/pipe/softpipe/sp_quad_fs.c | 2 +- src/mesa/pipe/softpipe/sp_state.h | 31 +- src/mesa/pipe/softpipe/sp_state_fs.c | 2 + src/mesa/pipe/softpipe/sp_state_sampler.c | 4 +- src/mesa/pipe/softpipe/sp_surface.c | 25 +- src/mesa/pipe/softpipe/sp_surface.h | 2 +- src/mesa/pipe/softpipe/sp_tex_layout.c | 361 --------------- src/mesa/pipe/softpipe/sp_tex_layout.h | 16 - src/mesa/pipe/softpipe/sp_tex_sample.c | 18 +- src/mesa/pipe/softpipe/sp_texture.c | 425 ++++++++++++++++++ src/mesa/pipe/softpipe/sp_texture.h | 18 + src/mesa/pipe/softpipe/sp_tile_cache.c | 4 +- src/mesa/pipe/softpipe/sp_tile_cache.h | 2 +- src/mesa/pipe/tgsi/exec/tgsi_exec.h | 2 +- src/mesa/sources | 2 +- src/mesa/state_tracker/st_atom_texture.c | 14 +- src/mesa/state_tracker/st_cb_drawpixels.c | 214 +++------ src/mesa/state_tracker/st_cb_fbo.c | 24 +- src/mesa/state_tracker/st_cb_texture.c | 427 +++++++++--------- src/mesa/state_tracker/st_cb_texture.h | 10 +- src/mesa/state_tracker/st_context.h | 22 +- src/mesa/state_tracker/st_mipmap_tree.c | 328 -------------- src/mesa/state_tracker/st_mipmap_tree.h | 118 ----- src/mesa/state_tracker/st_texture.c | 276 ++++++++++++ src/mesa/state_tracker/st_texture.h | 109 +++++ 46 files changed, 1877 insertions(+), 1830 deletions(-) delete mode 100644 src/mesa/pipe/i915simple/i915_tex_layout.c delete mode 100644 src/mesa/pipe/i915simple/i915_tex_layout.h create mode 100644 src/mesa/pipe/i915simple/i915_texture.c create mode 100644 src/mesa/pipe/i915simple/i915_texture.h delete mode 100644 src/mesa/pipe/softpipe/sp_tex_layout.c delete mode 100644 src/mesa/pipe/softpipe/sp_tex_layout.h create mode 100644 src/mesa/pipe/softpipe/sp_texture.c create mode 100644 src/mesa/pipe/softpipe/sp_texture.h delete mode 100644 src/mesa/state_tracker/st_mipmap_tree.c delete mode 100644 src/mesa/state_tracker/st_mipmap_tree.h create mode 100644 src/mesa/state_tracker/st_texture.c create mode 100644 src/mesa/state_tracker/st_texture.h (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/drivers/dri/intel_winsys/intel_screen.c b/src/mesa/drivers/dri/intel_winsys/intel_screen.c index 01460e5be3..1b520f7135 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_screen.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_screen.c @@ -328,8 +328,8 @@ intelSetTexOffset(__DRIcontext *pDRICtx, int texname, if (!stObj) return; - if (stObj->mt) - st_miptree_release(intel->st->pipe, &stObj->mt); + if (stObj->pt) + st->pipe->texture_release(intel->st->pipe, &stObj->pt); stObj->imageOverride = GL_TRUE; stObj->depthOverride = depth; diff --git a/src/mesa/pipe/failover/fo_context.c b/src/mesa/pipe/failover/fo_context.c index 0cc9cab408..a25563d451 100644 --- a/src/mesa/pipe/failover/fo_context.c +++ b/src/mesa/pipe/failover/fo_context.c @@ -145,7 +145,8 @@ struct pipe_context *failover_create( struct pipe_context *hw, failover->pipe.surface_data = hw->surface_data; failover->pipe.surface_copy = hw->surface_copy; failover->pipe.surface_fill = hw->surface_fill; - failover->pipe.mipmap_tree_layout = hw->mipmap_tree_layout; + failover->pipe.texture_create = hw->texture_create; + failover->pipe.texture_release = hw->texture_release; failover->pipe.flush = hw->flush; failover->dirty = 0; diff --git a/src/mesa/pipe/failover/fo_context.h b/src/mesa/pipe/failover/fo_context.h index 759b53ccbe..7cf18c9ec1 100644 --- a/src/mesa/pipe/failover/fo_context.h +++ b/src/mesa/pipe/failover/fo_context.h @@ -85,7 +85,7 @@ struct failover_context { struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; uint sampler_units[PIPE_MAX_SAMPLERS]; - struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS]; + struct pipe_texture *texture[PIPE_MAX_SAMPLERS]; struct pipe_viewport_state viewport; struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX]; struct pipe_vertex_element vertex_element[PIPE_ATTRIB_MAX]; diff --git a/src/mesa/pipe/failover/fo_state.c b/src/mesa/pipe/failover/fo_state.c index 2cd1a50b20..fd6137ba66 100644 --- a/src/mesa/pipe/failover/fo_state.c +++ b/src/mesa/pipe/failover/fo_state.c @@ -402,7 +402,7 @@ failover_delete_sampler_state(struct pipe_context *pipe, void *sampler) static void failover_set_texture_state(struct pipe_context *pipe, unsigned unit, - struct pipe_mipmap_tree *texture) + struct pipe_texture *texture) { struct failover_context *failover = failover_context(pipe); diff --git a/src/mesa/pipe/i915simple/Makefile b/src/mesa/pipe/i915simple/Makefile index 391a084915..1223b386a3 100644 --- a/src/mesa/pipe/i915simple/Makefile +++ b/src/mesa/pipe/i915simple/Makefile @@ -22,7 +22,7 @@ DRIVER_SOURCES = \ i915_strings.c \ i915_prim_emit.c \ i915_prim_vbuf.c \ - i915_tex_layout.c \ + i915_texture.c \ i915_fpc_emit.c \ i915_fpc_translate.c \ i915_surface.c diff --git a/src/mesa/pipe/i915simple/i915_context.c b/src/mesa/pipe/i915simple/i915_context.c index a0ed3032b1..94649231cf 100644 --- a/src/mesa/pipe/i915simple/i915_context.c +++ b/src/mesa/pipe/i915simple/i915_context.c @@ -29,7 +29,7 @@ #include "i915_winsys.h" #include "i915_state.h" #include "i915_batch.h" -#include "i915_tex_layout.h" +#include "i915_texture.h" #include "i915_reg.h" #include "pipe/draw/draw_context.h" @@ -357,11 +357,8 @@ struct pipe_context *i915_create( struct pipe_winsys *pipe_winsys, i915->pci_id = pci_id; i915->flags.is_i945 = is_i945; - if (i915->flags.is_i945) - i915->pipe.mipmap_tree_layout = i945_miptree_layout; - else - i915->pipe.mipmap_tree_layout = i915_miptree_layout; - + i915->pipe.texture_create = i915_texture_create; + i915->pipe.texture_release = i915_texture_release; i915->dirty = ~0; i915->hardware_dirty = ~0; diff --git a/src/mesa/pipe/i915simple/i915_context.h b/src/mesa/pipe/i915simple/i915_context.h index ee430ebc90..8ed3465be2 100644 --- a/src/mesa/pipe/i915simple/i915_context.h +++ b/src/mesa/pipe/i915simple/i915_context.h @@ -150,6 +150,34 @@ struct i915_alpha_test_state { unsigned LIS6; }; +struct i915_texture { + struct pipe_texture base; + + /* Derived from the above: + */ + unsigned pitch; + unsigned depth_pitch; /* per-image on i945? */ + unsigned total_height; + + unsigned nr_images[PIPE_MAX_TEXTURE_LEVELS]; + + /* Explicitly store the offset of each image for each cube face or + * depth value. Pretty much have to accept that hardware formats + * are going to be so diverse that there is no unified way to + * compute the offsets of depth/cube images within a mipmap level, + * so have to store them as a lookup table: + */ + unsigned *image_offset[PIPE_MAX_TEXTURE_LEVELS]; /**< array [depth] of offsets */ + + /* Includes image offset tables: + */ + unsigned level_offset[PIPE_MAX_TEXTURE_LEVELS]; + + /* The data is held here: + */ + struct pipe_region *region; +}; + struct i915_context { struct pipe_context pipe; @@ -174,7 +202,7 @@ struct i915_context struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; uint sampler_units[PIPE_MAX_SAMPLERS]; - struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS]; + struct i915_texture *texture[PIPE_MAX_SAMPLERS]; struct pipe_viewport_state viewport; struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX]; diff --git a/src/mesa/pipe/i915simple/i915_state.c b/src/mesa/pipe/i915simple/i915_state.c index 468d0ce91b..038fd623ea 100644 --- a/src/mesa/pipe/i915simple/i915_state.c +++ b/src/mesa/pipe/i915simple/i915_state.c @@ -525,11 +525,11 @@ static void i915_set_constant_buffer(struct pipe_context *pipe, static void i915_set_texture_state(struct pipe_context *pipe, unsigned unit, - struct pipe_mipmap_tree *texture) + struct pipe_texture *texture) { struct i915_context *i915 = i915_context(pipe); - i915->texture[unit] = texture; /* ptr, not struct */ + i915->texture[unit] = (struct i915_texture*)texture; /* ptr, not struct */ i915->dirty |= I915_NEW_TEXTURE; } diff --git a/src/mesa/pipe/i915simple/i915_state_sampler.c b/src/mesa/pipe/i915simple/i915_state_sampler.c index 0991e6ac0d..1816d9abdb 100644 --- a/src/mesa/pipe/i915simple/i915_state_sampler.c +++ b/src/mesa/pipe/i915simple/i915_state_sampler.c @@ -46,9 +46,11 @@ static void update_sampler(struct i915_context *i915, uint unit, const struct i915_sampler_state *sampler, - const struct pipe_mipmap_tree *mt, + const struct i915_texture *tex, unsigned state[3] ) { + const struct pipe_texture *pt = &tex->base; + /* Need to do this after updating the maps, which call the * intel_finalize_mipmap_tree and hence can update firstLevel: */ @@ -56,8 +58,8 @@ static void update_sampler(struct i915_context *i915, state[1] = sampler->state[1]; state[2] = sampler->state[2]; - if (mt->format == PIPE_FORMAT_YCBCR || - mt->format == PIPE_FORMAT_YCBCR_REV) + if (pt->format == PIPE_FORMAT_YCBCR || + pt->format == PIPE_FORMAT_YCBCR_REV) state[0] |= SS2_COLORSPACE_CONVERSION; /* 3D textures don't seem to respect the border color. @@ -75,7 +77,7 @@ static void update_sampler(struct i915_context *i915, const unsigned ws = sampler->templ->wrap_s; const unsigned wt = sampler->templ->wrap_t; const unsigned wr = sampler->templ->wrap_r; - if (mt->target == PIPE_TEXTURE_3D && + if (pt->target == PIPE_TEXTURE_3D && (sampler->templ->min_img_filter != PIPE_TEX_FILTER_NEAREST || sampler->templ->mag_img_filter != PIPE_TEX_FILTER_NEAREST) && (ws == PIPE_TEX_WRAP_CLAMP || @@ -105,13 +107,13 @@ void i915_update_samplers( struct i915_context *i915 ) i915->current.sampler_enable_flags = 0x0; for (unit = 0; unit < I915_TEX_UNITS; unit++) { - /* determine unit enable/disable by looking for a bound mipmap tree */ + /* determine unit enable/disable by looking for a bound texture */ /* could also examine the fragment program? */ if (i915->texture[unit]) { update_sampler( i915, unit, i915->sampler[unit], /* sampler state */ - i915->texture[unit], /* mipmap tree */ + i915->texture[unit], /* texture */ i915->current.sampler[unit] /* the result */ ); @@ -179,18 +181,19 @@ static void i915_update_texture(struct i915_context *i915, uint unit, uint state[6]) { - const struct pipe_mipmap_tree *mt = i915->texture[unit]; + const struct i915_texture *tex = i915->texture[unit]; + const struct pipe_texture *pt = &tex->base; uint format, pitch; - const uint width = mt->width0, height = mt->height0, depth = mt->depth0; - const uint num_levels = mt->last_level - mt->first_level; + const uint width = pt->width[0], height = pt->height[0], depth = pt->depth[0]; + const uint num_levels = pt->last_level - pt->first_level; - assert(mt); + assert(tex); assert(width); assert(height); assert(depth); - format = translate_texture_format(mt->format); - pitch = mt->pitch * mt->cpp; + format = translate_texture_format(pt->format); + pitch = tex->pitch * pt->cpp; assert(format); assert(pitch); @@ -217,7 +220,7 @@ i915_update_textures(struct i915_context *i915) uint unit; for (unit = 0; unit < I915_TEX_UNITS; unit++) { - /* determine unit enable/disable by looking for a bound mipmap tree */ + /* determine unit enable/disable by looking for a bound texture */ /* could also examine the fragment program? */ if (i915->texture[unit]) { i915_update_texture(i915, unit, i915->current.texbuffer[unit]); diff --git a/src/mesa/pipe/i915simple/i915_surface.c b/src/mesa/pipe/i915simple/i915_surface.c index e4a5de00d7..385202507d 100644 --- a/src/mesa/pipe/i915simple/i915_surface.c +++ b/src/mesa/pipe/i915simple/i915_surface.c @@ -187,34 +187,35 @@ i915_put_tile(struct pipe_context *pipe, */ static struct pipe_surface * i915_get_tex_surface(struct pipe_context *pipe, - struct pipe_mipmap_tree *mt, + struct pipe_texture *pt, unsigned face, unsigned level, unsigned zslice) { + struct i915_texture *tex = (struct i915_texture *)pt; struct pipe_surface *ps; unsigned offset; /* in bytes */ - offset = mt->level[level].level_offset; + offset = tex->level_offset[level]; - if (mt->target == PIPE_TEXTURE_CUBE) { - offset += mt->level[level].image_offset[face] * mt->cpp; + if (pt->target == PIPE_TEXTURE_CUBE) { + offset += tex->image_offset[level][face] * pt->cpp; } - else if (mt->target == PIPE_TEXTURE_3D) { - offset += mt->level[level].image_offset[zslice] * mt->cpp; + else if (pt->target == PIPE_TEXTURE_3D) { + offset += tex->image_offset[level][zslice] * pt->cpp; } else { assert(face == 0); assert(zslice == 0); } - ps = pipe->winsys->surface_alloc(pipe->winsys, mt->format); + ps = pipe->winsys->surface_alloc(pipe->winsys, pt->format); if (ps) { assert(ps->format); assert(ps->refcount); - pipe_region_reference(&ps->region, mt->region); - ps->cpp = mt->cpp; - ps->width = mt->level[level].width; - ps->height = mt->level[level].height; - ps->pitch = mt->pitch; + pipe_region_reference(&ps->region, tex->region); + ps->cpp = pt->cpp; + ps->width = pt->width[level]; + ps->height = pt->height[level]; + ps->pitch = tex->pitch; ps->offset = offset; } return ps; diff --git a/src/mesa/pipe/i915simple/i915_tex_layout.c b/src/mesa/pipe/i915simple/i915_tex_layout.c deleted file mode 100644 index cb372a7170..0000000000 --- a/src/mesa/pipe/i915simple/i915_tex_layout.c +++ /dev/null @@ -1,474 +0,0 @@ -/************************************************************************** - * - * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - /* - * Authors: - * Keith Whitwell - * Michel Dänzer - */ - -#include "pipe/p_state.h" -#include "pipe/p_context.h" -#include "pipe/p_defines.h" -#include "pipe/p_util.h" - -#include "i915_tex_layout.h" -#include "i915_debug.h" - - -static unsigned minify( unsigned d ) -{ - return MAX2(1, d>>1); -} - -static int align(int value, int alignment) -{ - return (value + alignment - 1) & ~(alignment - 1); -} - - -static void -i915_miptree_set_level_info(struct pipe_mipmap_tree *mt, - unsigned level, - unsigned nr_images, - unsigned x, unsigned y, unsigned w, unsigned h, unsigned d) -{ - assert(level < PIPE_MAX_TEXTURE_LEVELS); - - mt->level[level].width = w; - mt->level[level].height = h; - mt->level[level].depth = d; - mt->level[level].level_offset = (x + y * mt->pitch) * mt->cpp; - mt->level[level].nr_images = nr_images; - - /* - DBG("%s level %d size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__, - level, w, h, d, x, y, mt->level[level].level_offset); - */ - - /* Not sure when this would happen, but anyway: - */ - if (mt->level[level].image_offset) { - FREE(mt->level[level].image_offset); - mt->level[level].image_offset = NULL; - } - - assert(nr_images); - assert(!mt->level[level].image_offset); - - mt->level[level].image_offset = (unsigned *) MALLOC(nr_images * sizeof(unsigned)); - mt->level[level].image_offset[0] = 0; -} - - -static void -i915_miptree_set_image_offset(struct pipe_mipmap_tree *mt, - unsigned level, unsigned img, unsigned x, unsigned y) -{ - if (img == 0 && level == 0) - assert(x == 0 && y == 0); - - assert(img < mt->level[level].nr_images); - - mt->level[level].image_offset[img] = (x + y * mt->pitch); - - /* - DBG("%s level %d img %d pos %d,%d image_offset %x\n", - __FUNCTION__, level, img, x, y, mt->level[level].image_offset[img]); - */ -} - - -static void -i945_miptree_layout_2d( struct pipe_mipmap_tree *mt ) -{ - int align_h = 2, align_w = 4; - unsigned level; - unsigned x = 0; - unsigned y = 0; - unsigned width = mt->width0; - unsigned height = mt->height0; - - mt->pitch = mt->width0; - - /* May need to adjust pitch to accomodate the placement of - * the 2nd mipmap. This occurs when the alignment - * constraints of mipmap placement push the right edge of the - * 2nd mipmap out past the width of its parent. - */ - if (mt->first_level != mt->last_level) { - unsigned mip1_width = align(minify(mt->width0), align_w) - + minify(minify(mt->width0)); - - if (mip1_width > mt->width0) - mt->pitch = mip1_width; - } - - /* Pitch must be a whole number of dwords, even though we - * express it in texels. - */ - mt->pitch = align(mt->pitch * mt->cpp, 4) / mt->cpp; - mt->total_height = 0; - - for ( level = mt->first_level ; level <= mt->last_level ; level++ ) { - unsigned img_height; - - i915_miptree_set_level_info(mt, level, 1, x, y, width, height, 1); - - if (mt->compressed) - img_height = MAX2(1, height/4); - else - img_height = align(height, align_h); - - - /* Because the images are packed better, the final offset - * might not be the maximal one: - */ - mt->total_height = MAX2(mt->total_height, y + img_height); - - /* Layout_below: step right after second mipmap. - */ - if (level == mt->first_level + 1) { - x += align(width, align_w); - } - else { - y += img_height; - } - - width = minify(width); - height = minify(height); - } -} - - -static const int initial_offsets[6][2] = { - {0, 0}, - {0, 2}, - {1, 0}, - {1, 2}, - {1, 1}, - {1, 3} -}; - -static const int step_offsets[6][2] = { - {0, 2}, - {0, 2}, - {-1, 2}, - {-1, 2}, - {-1, 1}, - {-1, 1} -}; - - -boolean -i915_miptree_layout(struct pipe_context *pipe, struct pipe_mipmap_tree * mt) -{ - unsigned level; - - switch (mt->target) { - case PIPE_TEXTURE_CUBE: { - const unsigned dim = mt->width0; - unsigned face; - unsigned lvlWidth = mt->width0, lvlHeight = mt->height0; - - assert(lvlWidth == lvlHeight); /* cubemap images are square */ - - /* double pitch for cube layouts */ - mt->pitch = ((dim * mt->cpp * 2 + 3) & ~3) / mt->cpp; - mt->total_height = dim * 4; - - for (level = mt->first_level; level <= mt->last_level; level++) { - i915_miptree_set_level_info(mt, level, 6, - 0, 0, - /*OLD: mt->pitch, mt->total_height,*/ - lvlWidth, lvlHeight, - 1); - lvlWidth /= 2; - lvlHeight /= 2; - } - - for (face = 0; face < 6; face++) { - unsigned x = initial_offsets[face][0] * dim; - unsigned y = initial_offsets[face][1] * dim; - unsigned d = dim; - - for (level = mt->first_level; level <= mt->last_level; level++) { - i915_miptree_set_image_offset(mt, level, face, x, y); - d >>= 1; - x += step_offsets[face][0] * d; - y += step_offsets[face][1] * d; - } - } - break; - } - case PIPE_TEXTURE_3D:{ - unsigned width = mt->width0; - unsigned height = mt->height0; - unsigned depth = mt->depth0; - unsigned stack_height = 0; - - /* Calculate the size of a single slice. - */ - mt->pitch = ((mt->width0 * mt->cpp + 3) & ~3) / mt->cpp; - - /* XXX: hardware expects/requires 9 levels at minimum. - */ - for (level = mt->first_level; level <= MAX2(8, mt->last_level); - level++) { - i915_miptree_set_level_info(mt, level, depth, 0, mt->total_height, - width, height, depth); - - - stack_height += MAX2(2, height); - - width = minify(width); - height = minify(height); - depth = minify(depth); - } - - /* Fixup depth image_offsets: - */ - depth = mt->depth0; - for (level = mt->first_level; level <= mt->last_level; level++) { - unsigned i; - for (i = 0; i < depth; i++) - i915_miptree_set_image_offset(mt, level, i, - 0, i * stack_height); - - depth = minify(depth); - } - - - /* Multiply slice size by texture depth for total size. It's - * remarkable how wasteful of memory the i915 texture layouts - * are. They are largely fixed in the i945. - */ - mt->total_height = stack_height * mt->depth0; - break; - } - - default:{ - unsigned width = mt->width0; - unsigned height = mt->height0; - unsigned img_height; - - mt->pitch = ((mt->width0 * mt->cpp + 3) & ~3) / mt->cpp; - mt->total_height = 0; - - for (level = mt->first_level; level <= mt->last_level; level++) { - i915_miptree_set_level_info(mt, level, 1, - 0, mt->total_height, - width, height, 1); - - if (mt->compressed) - img_height = MAX2(1, height / 4); - else - img_height = (MAX2(2, height) + 1) & ~1; - - mt->total_height += img_height; - - width = minify(width); - height = minify(height); - } - break; - } - } - /* - DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__, - mt->pitch, - mt->total_height, mt->cpp, mt->pitch * mt->total_height * mt->cpp); - */ - - return TRUE; -} - - -boolean -i945_miptree_layout(struct pipe_context *pipe, struct pipe_mipmap_tree * mt) -{ - unsigned level; - - switch (mt->target) { - case PIPE_TEXTURE_CUBE:{ - const unsigned dim = mt->width0; - unsigned face; - unsigned lvlWidth = mt->width0, lvlHeight = mt->height0; - - assert(lvlWidth == lvlHeight); /* cubemap images are square */ - - /* Depending on the size of the largest images, pitch can be - * determined either by the old-style packing of cubemap faces, - * or the final row of 4x4, 2x2 and 1x1 faces below this. - */ - if (dim > 32) - mt->pitch = ((dim * mt->cpp * 2 + 3) & ~3) / mt->cpp; - else - mt->pitch = 14 * 8; - - mt->total_height = dim * 4 + 4; - - /* Set all the levels to effectively occupy the whole rectangular region. - */ - for (level = mt->first_level; level <= mt->last_level; level++) { - i915_miptree_set_level_info(mt, level, 6, - 0, 0, - lvlWidth, lvlHeight, 1); - lvlWidth /= 2; - lvlHeight /= 2; - } - - - for (face = 0; face < 6; face++) { - unsigned x = initial_offsets[face][0] * dim; - unsigned y = initial_offsets[face][1] * dim; - unsigned d = dim; - - if (dim == 4 && face >= 4) { - y = mt->total_height - 4; - x = (face - 4) * 8; - } - else if (dim < 4 && (face > 0 || mt->first_level > 0)) { - y = mt->total_height - 4; - x = face * 8; - } - - for (level = mt->first_level; level <= mt->last_level; level++) { - i915_miptree_set_image_offset(mt, level, face, x, y); - - d >>= 1; - - switch (d) { - case 4: - switch (face) { - case PIPE_TEX_FACE_POS_X: - case PIPE_TEX_FACE_NEG_X: - x += step_offsets[face][0] * d; - y += step_offsets[face][1] * d; - break; - case PIPE_TEX_FACE_POS_Y: - case PIPE_TEX_FACE_NEG_Y: - y += 12; - x -= 8; - break; - case PIPE_TEX_FACE_POS_Z: - case PIPE_TEX_FACE_NEG_Z: - y = mt->total_height - 4; - x = (face - 4) * 8; - break; - } - - case 2: - y = mt->total_height - 4; - x = 16 + face * 8; - break; - - case 1: - x += 48; - break; - - default: - x += step_offsets[face][0] * d; - y += step_offsets[face][1] * d; - break; - } - } - } - break; - } - case PIPE_TEXTURE_3D:{ - unsigned width = mt->width0; - unsigned height = mt->height0; - unsigned depth = mt->depth0; - unsigned pack_x_pitch, pack_x_nr; - unsigned pack_y_pitch; - unsigned level; - - mt->pitch = ((mt->width0 * mt->cpp + 3) & ~3) / mt->cpp; - mt->total_height = 0; - - pack_y_pitch = MAX2(mt->height0, 2); - pack_x_pitch = mt->pitch; - pack_x_nr = 1; - - for (level = mt->first_level; level <= mt->last_level; level++) { - unsigned nr_images = mt->target == PIPE_TEXTURE_3D ? depth : 6; - int x = 0; - int y = 0; - unsigned q, j; - - i915_miptree_set_level_info(mt, level, nr_images, - 0, mt->total_height, - width, height, depth); - - for (q = 0; q < nr_images;) { - for (j = 0; j < pack_x_nr && q < nr_images; j++, q++) { - i915_miptree_set_image_offset(mt, level, q, x, y); - x += pack_x_pitch; - } - - x = 0; - y += pack_y_pitch; - } - - - mt->total_height += y; - - if (pack_x_pitch > 4) { - pack_x_pitch >>= 1; - pack_x_nr <<= 1; - assert(pack_x_pitch * pack_x_nr <= mt->pitch); - } - - if (pack_y_pitch > 2) { - pack_y_pitch >>= 1; - } - - width = minify(width); - height = minify(height); - depth = minify(depth); - } - break; - } - - case PIPE_TEXTURE_1D: - case PIPE_TEXTURE_2D: -// case PIPE_TEXTURE_RECTANGLE: - i945_miptree_layout_2d(mt); - break; - default: - assert(0); - return FALSE; - } - - /* - DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__, - mt->pitch, - mt->total_height, mt->cpp, mt->pitch * mt->total_height * mt->cpp); - */ - - return TRUE; -} - diff --git a/src/mesa/pipe/i915simple/i915_tex_layout.h b/src/mesa/pipe/i915simple/i915_tex_layout.h deleted file mode 100644 index e033786381..0000000000 --- a/src/mesa/pipe/i915simple/i915_tex_layout.h +++ /dev/null @@ -1,16 +0,0 @@ - -#ifndef I915_TEX_LAYOUT_H -#define I915_TEX_LAYOUT_H - -struct pipe_context; -struct pipe_mipmap_tree; - - -extern boolean -i915_miptree_layout(struct pipe_context *, struct pipe_mipmap_tree *); - -extern boolean -i945_miptree_layout(struct pipe_context *, struct pipe_mipmap_tree *); - - -#endif /* I915_TEX_LAYOUT_H */ diff --git a/src/mesa/pipe/i915simple/i915_texture.c b/src/mesa/pipe/i915simple/i915_texture.c new file mode 100644 index 0000000000..3bfa806d9e --- /dev/null +++ b/src/mesa/pipe/i915simple/i915_texture.c @@ -0,0 +1,539 @@ +/************************************************************************** + * + * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + /* + * Authors: + * Keith Whitwell + * Michel Dänzer + */ + +#include "pipe/p_state.h" +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_util.h" +#include "pipe/p_winsys.h" + +#include "i915_context.h" +#include "i915_texture.h" +#include "i915_debug.h" + + +static unsigned minify( unsigned d ) +{ + return MAX2(1, d>>1); +} + +static int align(int value, int alignment) +{ + return (value + alignment - 1) & ~(alignment - 1); +} + + +static void +i915_miptree_set_level_info(struct i915_texture *tex, + unsigned level, + unsigned nr_images, + unsigned x, unsigned y, unsigned w, unsigned h, unsigned d) +{ + struct pipe_texture *pt = &tex->base; + + assert(level < PIPE_MAX_TEXTURE_LEVELS); + + pt->width[level] = w; + pt->height[level] = h; + pt->depth[level] = d; + + tex->level_offset[level] = (x + y * tex->pitch) * pt->cpp; + tex->nr_images[level] = nr_images; + + /* + DBG("%s level %d size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__, + level, w, h, d, x, y, tex->level_offset[level]); + */ + + /* Not sure when this would happen, but anyway: + */ + if (tex->image_offset[level]) { + FREE(tex->image_offset[level]); + tex->image_offset[level] = NULL; + } + + assert(nr_images); + assert(!tex->image_offset[level]); + + tex->image_offset[level] = (unsigned *) MALLOC(nr_images * sizeof(unsigned)); + tex->image_offset[level][0] = 0; +} + + +static void +i915_miptree_set_image_offset(struct i915_texture *tex, + unsigned level, unsigned img, unsigned x, unsigned y) +{ + if (img == 0 && level == 0) + assert(x == 0 && y == 0); + + assert(img < tex->nr_images[level]); + + tex->image_offset[level][img] = (x + y * tex->pitch); + + /* + DBG("%s level %d img %d pos %d,%d image_offset %x\n", + __FUNCTION__, level, img, x, y, tex->image_offset[level][img]); + */ +} + + +static void +i945_miptree_layout_2d( struct i915_texture *tex ) +{ + struct pipe_texture *pt = &tex->base; + int align_h = 2, align_w = 4; + unsigned level; + unsigned x = 0; + unsigned y = 0; + unsigned width = pt->width[0]; + unsigned height = pt->height[0]; + + tex->pitch = pt->width[0]; + + /* May need to adjust pitch to accomodate the placement of + * the 2nd mipmap. This occurs when the alignment + * constraints of mipmap placement push the right edge of the + * 2nd mipmap out past the width of its parent. + */ + if (pt->first_level != pt->last_level) { + unsigned mip1_width = align(minify(pt->width[0]), align_w) + + minify(minify(pt->width[0])); + + if (mip1_width > pt->width[0]) + tex->pitch = mip1_width; + } + + /* Pitch must be a whole number of dwords, even though we + * express it in texels. + */ + tex->pitch = align(tex->pitch * pt->cpp, 4) / pt->cpp; + tex->total_height = 0; + + for ( level = pt->first_level ; level <= pt->last_level ; level++ ) { + unsigned img_height; + + i915_miptree_set_level_info(tex, level, 1, x, y, width, height, 1); + + if (pt->compressed) + img_height = MAX2(1, height/4); + else + img_height = align(height, align_h); + + + /* Because the images are packed better, the final offset + * might not be the maximal one: + */ + tex->total_height = MAX2(tex->total_height, y + img_height); + + /* Layout_below: step right after second mipmap. + */ + if (level == pt->first_level + 1) { + x += align(width, align_w); + } + else { + y += img_height; + } + + width = minify(width); + height = minify(height); + } +} + + +static const int initial_offsets[6][2] = { + {0, 0}, + {0, 2}, + {1, 0}, + {1, 2}, + {1, 1}, + {1, 3} +}; + +static const int step_offsets[6][2] = { + {0, 2}, + {0, 2}, + {-1, 2}, + {-1, 2}, + {-1, 1}, + {-1, 1} +}; + + +static boolean +i915_miptree_layout(struct pipe_context *pipe, struct i915_texture * tex) +{ + struct pipe_texture *pt = &tex->base; + unsigned level; + + switch (pt->target) { + case PIPE_TEXTURE_CUBE: { + const unsigned dim = pt->width[0]; + unsigned face; + unsigned lvlWidth = pt->width[0], lvlHeight = pt->height[0]; + + assert(lvlWidth == lvlHeight); /* cubemap images are square */ + + /* double pitch for cube layouts */ + tex->pitch = ((dim * pt->cpp * 2 + 3) & ~3) / pt->cpp; + tex->total_height = dim * 4; + + for (level = pt->first_level; level <= pt->last_level; level++) { + i915_miptree_set_level_info(tex, level, 6, + 0, 0, + /*OLD: tex->pitch, tex->total_height,*/ + lvlWidth, lvlHeight, + 1); + lvlWidth /= 2; + lvlHeight /= 2; + } + + for (face = 0; face < 6; face++) { + unsigned x = initial_offsets[face][0] * dim; + unsigned y = initial_offsets[face][1] * dim; + unsigned d = dim; + + for (level = pt->first_level; level <= pt->last_level; level++) { + i915_miptree_set_image_offset(tex, level, face, x, y); + d >>= 1; + x += step_offsets[face][0] * d; + y += step_offsets[face][1] * d; + } + } + break; + } + case PIPE_TEXTURE_3D:{ + unsigned width = pt->width[0]; + unsigned height = pt->height[0]; + unsigned depth = pt->depth[0]; + unsigned stack_height = 0; + + /* Calculate the size of a single slice. + */ + tex->pitch = ((pt->width[0] * pt->cpp + 3) & ~3) / pt->cpp; + + /* XXX: hardware expects/requires 9 levels at minimum. + */ + for (level = pt->first_level; level <= MAX2(8, pt->last_level); + level++) { + i915_miptree_set_level_info(tex, level, depth, 0, tex->total_height, + width, height, depth); + + + stack_height += MAX2(2, height); + + width = minify(width); + height = minify(height); + depth = minify(depth); + } + + /* Fixup depth image_offsets: + */ + depth = pt->depth[0]; + for (level = pt->first_level; level <= pt->last_level; level++) { + unsigned i; + for (i = 0; i < depth; i++) + i915_miptree_set_image_offset(tex, level, i, + 0, i * stack_height); + + depth = minify(depth); + } + + + /* Multiply slice size by texture depth for total size. It's + * remarkable how wasteful of memory the i915 texture layouts + * are. They are largely fixed in the i945. + */ + tex->total_height = stack_height * pt->depth[0]; + break; + } + + default:{ + unsigned width = pt->width[0]; + unsigned height = pt->height[0]; + unsigned img_height; + + tex->pitch = ((pt->width[0] * pt->cpp + 3) & ~3) / pt->cpp; + tex->total_height = 0; + + for (level = pt->first_level; level <= pt->last_level; level++) { + i915_miptree_set_level_info(tex, level, 1, + 0, tex->total_height, + width, height, 1); + + if (pt->compressed) + img_height = MAX2(1, height / 4); + else + img_height = (MAX2(2, height) + 1) & ~1; + + tex->total_height += img_height; + + width = minify(width); + height = minify(height); + } + break; + } + } + /* + DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__, + tex->pitch, + tex->total_height, pt->cpp, tex->pitch * tex->total_height * pt->cpp); + */ + + return TRUE; +} + + +static boolean +i945_miptree_layout(struct pipe_context *pipe, struct i915_texture * tex) +{ + struct pipe_texture *pt = &tex->base; + unsigned level; + + switch (pt->target) { + case PIPE_TEXTURE_CUBE:{ + const unsigned dim = pt->width[0]; + unsigned face; + unsigned lvlWidth = pt->width[0], lvlHeight = pt->height[0]; + + assert(lvlWidth == lvlHeight); /* cubemap images are square */ + + /* Depending on the size of the largest images, pitch can be + * determined either by the old-style packing of cubemap faces, + * or the final row of 4x4, 2x2 and 1x1 faces below this. + */ + if (dim > 32) + tex->pitch = ((dim * pt->cpp * 2 + 3) & ~3) / pt->cpp; + else + tex->pitch = 14 * 8; + + tex->total_height = dim * 4 + 4; + + /* Set all the levels to effectively occupy the whole rectangular region. + */ + for (level = pt->first_level; level <= pt->last_level; level++) { + i915_miptree_set_level_info(tex, level, 6, + 0, 0, + lvlWidth, lvlHeight, 1); + lvlWidth /= 2; + lvlHeight /= 2; + } + + + for (face = 0; face < 6; face++) { + unsigned x = initial_offsets[face][0] * dim; + unsigned y = initial_offsets[face][1] * dim; + unsigned d = dim; + + if (dim == 4 && face >= 4) { + y = tex->total_height - 4; + x = (face - 4) * 8; + } + else if (dim < 4 && (face > 0 || pt->first_level > 0)) { + y = tex->total_height - 4; + x = face * 8; + } + + for (level = pt->first_level; level <= pt->last_level; level++) { + i915_miptree_set_image_offset(tex, level, face, x, y); + + d >>= 1; + + switch (d) { + case 4: + switch (face) { + case PIPE_TEX_FACE_POS_X: + case PIPE_TEX_FACE_NEG_X: + x += step_offsets[face][0] * d; + y += step_offsets[face][1] * d; + break; + case PIPE_TEX_FACE_POS_Y: + case PIPE_TEX_FACE_NEG_Y: + y += 12; + x -= 8; + break; + case PIPE_TEX_FACE_POS_Z: + case PIPE_TEX_FACE_NEG_Z: + y = tex->total_height - 4; + x = (face - 4) * 8; + break; + } + + case 2: + y = tex->total_height - 4; + x = 16 + face * 8; + break; + + case 1: + x += 48; + break; + + default: + x += step_offsets[face][0] * d; + y += step_offsets[face][1] * d; + break; + } + } + } + break; + } + case PIPE_TEXTURE_3D:{ + unsigned width = pt->width[0]; + unsigned height = pt->height[0]; + unsigned depth = pt->depth[0]; + unsigned pack_x_pitch, pack_x_nr; + unsigned pack_y_pitch; + unsigned level; + + tex->pitch = ((pt->width[0] * pt->cpp + 3) & ~3) / pt->cpp; + tex->total_height = 0; + + pack_y_pitch = MAX2(pt->height[0], 2); + pack_x_pitch = tex->pitch; + pack_x_nr = 1; + + for (level = pt->first_level; level <= pt->last_level; level++) { + unsigned nr_images = pt->target == PIPE_TEXTURE_3D ? depth : 6; + int x = 0; + int y = 0; + unsigned q, j; + + i915_miptree_set_level_info(tex, level, nr_images, + 0, tex->total_height, + width, height, depth); + + for (q = 0; q < nr_images;) { + for (j = 0; j < pack_x_nr && q < nr_images; j++, q++) { + i915_miptree_set_image_offset(tex, level, q, x, y); + x += pack_x_pitch; + } + + x = 0; + y += pack_y_pitch; + } + + + tex->total_height += y; + + if (pack_x_pitch > 4) { + pack_x_pitch >>= 1; + pack_x_nr <<= 1; + assert(pack_x_pitch * pack_x_nr <= tex->pitch); + } + + if (pack_y_pitch > 2) { + pack_y_pitch >>= 1; + } + + width = minify(width); + height = minify(height); + depth = minify(depth); + } + break; + } + + case PIPE_TEXTURE_1D: + case PIPE_TEXTURE_2D: +// case PIPE_TEXTURE_RECTANGLE: + i945_miptree_layout_2d(tex); + break; + default: + assert(0); + return FALSE; + } + + /* + DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__, + tex->pitch, + tex->total_height, pt->cpp, tex->pitch * tex->total_height * pt->cpp); + */ + + return TRUE; +} + +void +i915_texture_create(struct pipe_context *pipe, struct pipe_texture **pt) +{ + struct i915_texture *tex = REALLOC(*pt, sizeof(struct pipe_texture), + sizeof(struct i915_texture)); + + if (tex) { + struct i915_context *i915 = i915_context(pipe); + + memset(&tex->base + 1, 0, + sizeof(struct i915_texture) - sizeof(struct pipe_texture)); + + if (i915->flags.is_i945 ? i945_miptree_layout(pipe, tex) : + i915_miptree_layout(pipe, tex)) { + tex->region = pipe->winsys->region_alloc(pipe->winsys, + tex->pitch * tex->base.cpp * + tex->total_height, + PIPE_SURFACE_FLAG_TEXTURE); + } + + if (!tex->region) { + FREE(tex); + tex = NULL; + } + } + + *pt = &tex->base; +} + +void +i915_texture_release(struct pipe_context *pipe, struct pipe_texture **pt) +{ + if (!*pt) + return; + + /* + DBG("%s %p refcount will be %d\n", + __FUNCTION__, (void *) *pt, (*pt)->refcount - 1); + */ + if (--(*pt)->refcount <= 0) { + struct i915_texture *tex = (struct i915_texture *)*pt; + uint i; + + /* + DBG("%s deleting %p\n", __FUNCTION__, (void *) tex); + */ + + pipe->winsys->region_release(pipe->winsys, &tex->region); + + for (i = 0; i < PIPE_MAX_TEXTURE_LEVELS; i++) + if (tex->image_offset[i]) + free(tex->image_offset[i]); + + free(tex); + } + *pt = NULL; +} diff --git a/src/mesa/pipe/i915simple/i915_texture.h b/src/mesa/pipe/i915simple/i915_texture.h new file mode 100644 index 0000000000..84a0502e81 --- /dev/null +++ b/src/mesa/pipe/i915simple/i915_texture.h @@ -0,0 +1,16 @@ + +#ifndef I915_TEXTURE_H +#define I915_TEXTURE_H + +struct pipe_context; +struct pipe_texture; + + +extern void +i915_texture_create(struct pipe_context *pipe, struct pipe_texture **pt); + +extern void +i915_texture_release(struct pipe_context *pipe, struct pipe_texture **pt); + + +#endif /* I915_TEXTURE_H */ diff --git a/src/mesa/pipe/llvm/llvm_entry.c b/src/mesa/pipe/llvm/llvm_entry.c index 2459d14cb8..fe32e7810d 100644 --- a/src/mesa/pipe/llvm/llvm_entry.c +++ b/src/mesa/pipe/llvm/llvm_entry.c @@ -194,7 +194,6 @@ void run_vertex_shader(float (*ainputs)[16][4], struct pipe_sampler_state; -struct pipe_mipmap_tree; struct softpipe_tile_cache; #define NUM_CHANNELS 4 /* R,G,B,A */ @@ -203,7 +202,6 @@ struct softpipe_tile_cache; struct tgsi_sampler { const struct pipe_sampler_state *state; - struct pipe_mipmap_tree *texture; /** Get samples for four fragments in a quad */ void (*get_samples)(struct tgsi_sampler *sampler, const float s[QUAD_SIZE], diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index e145b22f2f..5033209323 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -155,7 +155,7 @@ struct pipe_context { void (*set_texture_state)( struct pipe_context *, unsigned unit, - struct pipe_mipmap_tree * ); + struct pipe_texture * ); void (*set_viewport_state)( struct pipe_context *, const struct pipe_viewport_state * ); @@ -180,7 +180,7 @@ struct pipe_context { /** Get a surface which is a "view" into a texture */ struct pipe_surface *(*get_tex_surface)(struct pipe_context *pipe, - struct pipe_mipmap_tree *texture, + struct pipe_texture *texture, unsigned face, unsigned level, unsigned zslice); @@ -237,8 +237,11 @@ struct pipe_context { /* * Texture functions */ - boolean (*mipmap_tree_layout)( struct pipe_context *pipe, - struct pipe_mipmap_tree *mt ); + void (*texture_create)(struct pipe_context *pipe, + struct pipe_texture **pt); + + void (*texture_release)(struct pipe_context *pipe, + struct pipe_texture **pt); /* Flush rendering: diff --git a/src/mesa/pipe/p_inlines.h b/src/mesa/pipe/p_inlines.h index 2418d016e1..c04d46dddd 100644 --- a/src/mesa/pipe/p_inlines.h +++ b/src/mesa/pipe/p_inlines.h @@ -80,4 +80,24 @@ pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf) } } + +/** + * \sa pipe_region_reference + */ +static INLINE void +pipe_texture_reference(struct pipe_context *pipe, struct pipe_texture **ptr, + struct pipe_texture *pt) +{ + assert(ptr); + if (*ptr) { + pipe->texture_release(pipe, ptr); + assert(!*ptr); + } + if (pt) { + /* reference the new thing */ + pt->refcount++; + *ptr = pt; + } +} + #endif /* P_INLINES_H */ diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index 642734aeb8..077a8f5a06 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -288,27 +288,11 @@ struct pipe_surface /** - * Describes the location of each texture image within a texture region. + * Texture. Represents one or several texture images on one or several mipmap + * levels. */ -struct pipe_mipmap_level -{ - unsigned level_offset; - unsigned width; - unsigned height; - unsigned depth; - unsigned nr_images; - - /* Explicitly store the offset of each image for each cube face or - * depth value. Pretty much have to accept that hardware formats - * are going to be so diverse that there is no unified way to - * compute the offsets of depth/cube images within a mipmap level, - * so have to store them as a lookup table: - */ - unsigned *image_offset; /**< array [depth] of offsets */ -}; - -struct pipe_mipmap_tree -{ +struct pipe_texture +{ /* Effectively the key: */ unsigned target; /* XXX convert to PIPE_TEXTURE_x */ @@ -318,25 +302,13 @@ struct pipe_mipmap_tree unsigned first_level; unsigned last_level; - unsigned width0, height0, depth0; /**< Level zero image dimensions */ + unsigned width[PIPE_MAX_TEXTURE_LEVELS]; + unsigned height[PIPE_MAX_TEXTURE_LEVELS]; + unsigned depth[PIPE_MAX_TEXTURE_LEVELS]; unsigned cpp; unsigned compressed:1; - /* Derived from the above: - */ - unsigned pitch; - unsigned depth_pitch; /* per-image on i945? */ - unsigned total_height; - - /* Includes image offset tables: - */ - struct pipe_mipmap_level level[PIPE_MAX_TEXTURE_LEVELS]; - - /* The data is held here: - */ - struct pipe_region *region; - /* These are also refcounted: */ unsigned refcount; diff --git a/src/mesa/pipe/softpipe/Makefile b/src/mesa/pipe/softpipe/Makefile index 59628531cc..9978884c9b 100644 --- a/src/mesa/pipe/softpipe/Makefile +++ b/src/mesa/pipe/softpipe/Makefile @@ -34,7 +34,7 @@ DRIVER_SOURCES = \ sp_state_rasterizer.c \ sp_state_surface.c \ sp_state_vertex.c \ - sp_tex_layout.c \ + sp_texture.c \ sp_tex_sample.c \ sp_tile_cache.c \ sp_surface.c diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index d5e68c189d..7a9fccce9a 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -40,7 +40,7 @@ #include "sp_state.h" #include "sp_surface.h" #include "sp_tile_cache.h" -#include "sp_tex_layout.h" +#include "sp_texture.h" #include "sp_winsys.h" @@ -98,9 +98,9 @@ softpipe_map_texture_surfaces(struct softpipe_context *sp) uint i; for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { - struct pipe_mipmap_tree *mt = sp->texture[i]; - if (mt) { - pipe->region_map(pipe, mt->region); + struct softpipe_texture *spt = sp->texture[i]; + if (spt) { + pipe->region_map(pipe, spt->region); } } } @@ -146,9 +146,9 @@ softpipe_unmap_texture_surfaces(struct softpipe_context *sp) struct pipe_context *pipe = &sp->pipe; uint i; for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { - struct pipe_mipmap_tree *mt = sp->texture[i]; - if (mt) { - pipe->region_unmap(pipe, mt->region); + struct softpipe_texture *spt = sp->texture[i]; + if (spt) { + pipe->region_unmap(pipe, spt->region); } } } @@ -351,7 +351,8 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, softpipe->pipe.get_vendor = softpipe_get_vendor; /* textures */ - softpipe->pipe.mipmap_tree_layout = softpipe_mipmap_tree_layout; + softpipe->pipe.texture_create = softpipe_texture_create; + softpipe->pipe.texture_release = softpipe_texture_release; softpipe->pipe.get_tex_surface = softpipe_get_tex_surface; /* diff --git a/src/mesa/pipe/softpipe/sp_context.h b/src/mesa/pipe/softpipe/sp_context.h index 872766101d..d4763a98c6 100644 --- a/src/mesa/pipe/softpipe/sp_context.h +++ b/src/mesa/pipe/softpipe/sp_context.h @@ -89,7 +89,7 @@ struct softpipe_context { struct pipe_framebuffer_state framebuffer; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; - struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS]; + struct softpipe_texture *texture[PIPE_MAX_SAMPLERS]; struct pipe_viewport_state viewport; struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX]; struct pipe_vertex_element vertex_element[PIPE_ATTRIB_MAX]; diff --git a/src/mesa/pipe/softpipe/sp_quad_fs.c b/src/mesa/pipe/softpipe/sp_quad_fs.c index 24c8a44c47..7184fcda52 100644 --- a/src/mesa/pipe/softpipe/sp_quad_fs.c +++ b/src/mesa/pipe/softpipe/sp_quad_fs.c @@ -277,7 +277,7 @@ static void shade_begin(struct quad_stage *qs) /* set TGSI sampler state that varies */ for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { qss->samplers[i].state = softpipe->sampler[i]; - qss->samplers[i].texture = softpipe->texture[i]; + qss->samplers[i].texture = &softpipe->texture[i]->base; } #ifdef MESA_LLVM diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index 2f096a9cc9..a543735b52 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -52,6 +52,35 @@ struct sp_fragment_shader_state { #endif }; +struct softpipe_texture +{ + struct pipe_texture base; + + /* Derived from the above: + */ + unsigned pitch; + unsigned depth_pitch; /* per-image on i945? */ + unsigned total_height; + + unsigned nr_images[PIPE_MAX_TEXTURE_LEVELS]; + + /* Explicitly store the offset of each image for each cube face or + * depth value. Pretty much have to accept that hardware formats + * are going to be so diverse that there is no unified way to + * compute the offsets of depth/cube images within a mipmap level, + * so have to store them as a lookup table: + */ + unsigned *image_offset[PIPE_MAX_TEXTURE_LEVELS]; /**< array [depth] of offsets */ + + /* Includes image offset tables: + */ + unsigned long level_offset[PIPE_MAX_TEXTURE_LEVELS]; + + /* The data is held here: + */ + struct pipe_region *region; +}; + void * softpipe_create_alpha_test_state(struct pipe_context *, const struct pipe_alpha_test_state *); @@ -125,7 +154,7 @@ void softpipe_set_scissor_state( struct pipe_context *, void softpipe_set_texture_state( struct pipe_context *, unsigned unit, - struct pipe_mipmap_tree * ); + struct pipe_texture * ); void softpipe_set_viewport_state( struct pipe_context *, const struct pipe_viewport_state * ); diff --git a/src/mesa/pipe/softpipe/sp_state_fs.c b/src/mesa/pipe/softpipe/sp_state_fs.c index 912f42d568..a360b4f02b 100644 --- a/src/mesa/pipe/softpipe/sp_state_fs.c +++ b/src/mesa/pipe/softpipe/sp_state_fs.c @@ -34,6 +34,8 @@ #include "pipe/draw/draw_context.h" #include "pipe/p_shader_tokens.h" #include "pipe/llvm/gallivm.h" +#include "pipe/tgsi/util/tgsi_dump.h" +#include "pipe/tgsi/exec/tgsi_sse2.h" void * softpipe_create_fs_state(struct pipe_context *pipe, diff --git a/src/mesa/pipe/softpipe/sp_state_sampler.c b/src/mesa/pipe/softpipe/sp_state_sampler.c index 246a7d6eda..e71b9159e3 100644 --- a/src/mesa/pipe/softpipe/sp_state_sampler.c +++ b/src/mesa/pipe/softpipe/sp_state_sampler.c @@ -68,12 +68,12 @@ softpipe_delete_sampler_state(struct pipe_context *pipe, void softpipe_set_texture_state(struct pipe_context *pipe, unsigned unit, - struct pipe_mipmap_tree *texture) + struct pipe_texture *texture) { struct softpipe_context *softpipe = softpipe_context(pipe); assert(unit < PIPE_MAX_SAMPLERS); - softpipe->texture[unit] = texture; /* ptr, not struct */ + softpipe->texture[unit] = (struct softpipe_texture *)texture; /* ptr, not struct */ sp_tile_cache_set_texture(softpipe->tex_cache[unit], texture); diff --git a/src/mesa/pipe/softpipe/sp_surface.c b/src/mesa/pipe/softpipe/sp_surface.c index a6ab404603..c41bbc59b9 100644 --- a/src/mesa/pipe/softpipe/sp_surface.c +++ b/src/mesa/pipe/softpipe/sp_surface.c @@ -565,34 +565,35 @@ z24s8_get_tile(struct pipe_surface *ps, */ struct pipe_surface * softpipe_get_tex_surface(struct pipe_context *pipe, - struct pipe_mipmap_tree *mt, + struct pipe_texture *pt, unsigned face, unsigned level, unsigned zslice) { + struct softpipe_texture *spt = (struct softpipe_texture *)pt; struct pipe_surface *ps; unsigned offset; /* in bytes */ - offset = mt->level[level].level_offset; + offset = spt->level_offset[level]; - if (mt->target == PIPE_TEXTURE_CUBE) { - offset += mt->level[level].image_offset[face] * mt->cpp; + if (pt->target == PIPE_TEXTURE_CUBE) { + offset += spt->image_offset[level][face] * pt->cpp; } - else if (mt->target == PIPE_TEXTURE_3D) { - offset += mt->level[level].image_offset[zslice] * mt->cpp; + else if (pt->target == PIPE_TEXTURE_3D) { + offset += spt->image_offset[level][zslice] * pt->cpp; } else { assert(face == 0); assert(zslice == 0); } - ps = pipe->winsys->surface_alloc(pipe->winsys, mt->format); + ps = pipe->winsys->surface_alloc(pipe->winsys, pt->format); if (ps) { assert(ps->format); assert(ps->refcount); - pipe_region_reference(&ps->region, mt->region); - ps->cpp = mt->cpp; - ps->width = mt->level[level].width; - ps->height = mt->level[level].height; - ps->pitch = mt->pitch; + pipe_region_reference(&ps->region, spt->region); + ps->cpp = pt->cpp; + ps->width = pt->width[level]; + ps->height = pt->height[level]; + ps->pitch = spt->pitch; ps->offset = offset; } return ps; diff --git a/src/mesa/pipe/softpipe/sp_surface.h b/src/mesa/pipe/softpipe/sp_surface.h index cf87e1a92c..b652e7598e 100644 --- a/src/mesa/pipe/softpipe/sp_surface.h +++ b/src/mesa/pipe/softpipe/sp_surface.h @@ -41,7 +41,7 @@ struct softpipe_tile_cache; extern struct pipe_surface * softpipe_get_tex_surface(struct pipe_context *pipe, - struct pipe_mipmap_tree *mt, + struct pipe_texture *pt, unsigned face, unsigned level, unsigned zslice); diff --git a/src/mesa/pipe/softpipe/sp_tex_layout.c b/src/mesa/pipe/softpipe/sp_tex_layout.c deleted file mode 100644 index 8156b00301..0000000000 --- a/src/mesa/pipe/softpipe/sp_tex_layout.c +++ /dev/null @@ -1,361 +0,0 @@ -/************************************************************************** - * - * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - /* - * Authors: - * Keith Whitwell - * Michel Dänzer - */ - -#include "pipe/p_context.h" -#include "pipe/p_defines.h" -#include "pipe/p_util.h" -#include "sp_tex_layout.h" - - -/* At the moment, just make softpipe use the same layout for its - * textures as the i945. Softpipe needs some sort of texture layout, - * this one was handy. May be worthwhile to simplify this code a - * little. - */ - -static unsigned minify( unsigned d ) -{ - return MAX2(1, d>>1); -} - -static int align(int value, int alignment) -{ - return (value + alignment - 1) & ~(alignment - 1); -} - - -static void -sp_miptree_set_level_info(struct pipe_mipmap_tree *mt, - unsigned level, - unsigned nr_images, - unsigned x, unsigned y, unsigned w, unsigned h, unsigned d) -{ - assert(level < PIPE_MAX_TEXTURE_LEVELS); - - mt->level[level].width = w; - mt->level[level].height = h; - mt->level[level].depth = d; - mt->level[level].level_offset = (x + y * mt->pitch) * mt->cpp; - mt->level[level].nr_images = nr_images; - - /* - DBG("%s level %d size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__, - level, w, h, d, x, y, mt->level[level].level_offset); - */ - - /* Not sure when this would happen, but anyway: - */ - if (mt->level[level].image_offset) { - FREE( mt->level[level].image_offset ); - mt->level[level].image_offset = NULL; - } - - assert(nr_images); - assert(!mt->level[level].image_offset); - - mt->level[level].image_offset = (unsigned *) MALLOC( nr_images * sizeof(unsigned) ); - mt->level[level].image_offset[0] = 0; -} - - -static void -sp_miptree_set_image_offset(struct pipe_mipmap_tree *mt, - unsigned level, unsigned img, unsigned x, unsigned y) -{ - if (img == 0 && level == 0) - assert(x == 0 && y == 0); - - assert(img < mt->level[level].nr_images); - - mt->level[level].image_offset[img] = (x + y * mt->pitch); - - /* - DBG("%s level %d img %d pos %d,%d image_offset %x\n", - __FUNCTION__, level, img, x, y, mt->level[level].image_offset[img]); - */ -} - - -static void -sp_miptree_layout_2d( struct pipe_mipmap_tree *mt ) -{ - int align_h = 2, align_w = 4; - unsigned level; - unsigned x = 0; - unsigned y = 0; - unsigned width = mt->width0; - unsigned height = mt->height0; - - mt->pitch = mt->width0; - /* XXX FIX THIS: - * we use alignment=64 bytes in sp_region_alloc(). If we change - * that, change this too. - */ - if (mt->pitch < 16) - mt->pitch = 16; - - /* May need to adjust pitch to accomodate the placement of - * the 2nd mipmap. This occurs when the alignment - * constraints of mipmap placement push the right edge of the - * 2nd mipmap out past the width of its parent. - */ - if (mt->first_level != mt->last_level) { - unsigned mip1_width = align(minify(mt->width0), align_w) - + minify(minify(mt->width0)); - - if (mip1_width > mt->width0) - mt->pitch = mip1_width; - } - - /* Pitch must be a whole number of dwords, even though we - * express it in texels. - */ - mt->pitch = align(mt->pitch * mt->cpp, 4) / mt->cpp; - mt->total_height = 0; - - for ( level = mt->first_level ; level <= mt->last_level ; level++ ) { - unsigned img_height; - - sp_miptree_set_level_info(mt, level, 1, x, y, width, height, 1); - - if (mt->compressed) - img_height = MAX2(1, height/4); - else - img_height = align(height, align_h); - - - /* Because the images are packed better, the final offset - * might not be the maximal one: - */ - mt->total_height = MAX2(mt->total_height, y + img_height); - - /* Layout_below: step right after second mipmap. - */ - if (level == mt->first_level + 1) { - x += align(width, align_w); - } - else { - y += img_height; - } - - width = minify(width); - height = minify(height); - } -} - - -static const int initial_offsets[6][2] = { - {0, 0}, - {0, 2}, - {1, 0}, - {1, 2}, - {1, 1}, - {1, 3} -}; - -static const int step_offsets[6][2] = { - {0, 2}, - {0, 2}, - {-1, 2}, - {-1, 2}, - {-1, 1}, - {-1, 1} -}; - - - -boolean -softpipe_mipmap_tree_layout(struct pipe_context *pipe, struct pipe_mipmap_tree * mt) -{ - unsigned level; - - switch (mt->target) { - case PIPE_TEXTURE_CUBE:{ - const unsigned dim = mt->width0; - unsigned face; - unsigned lvlWidth = mt->width0, lvlHeight = mt->height0; - - assert(lvlWidth == lvlHeight); /* cubemap images are square */ - - /* Depending on the size of the largest images, pitch can be - * determined either by the old-style packing of cubemap faces, - * or the final row of 4x4, 2x2 and 1x1 faces below this. - */ - if (dim > 32) - mt->pitch = ((dim * mt->cpp * 2 + 3) & ~3) / mt->cpp; - else - mt->pitch = 14 * 8; - - mt->total_height = dim * 4 + 4; - - /* Set all the levels to effectively occupy the whole rectangular region. - */ - for (level = mt->first_level; level <= mt->last_level; level++) { - sp_miptree_set_level_info(mt, level, 6, - 0, 0, - lvlWidth, lvlHeight, 1); - lvlWidth /= 2; - lvlHeight /= 2; - } - - - for (face = 0; face < 6; face++) { - unsigned x = initial_offsets[face][0] * dim; - unsigned y = initial_offsets[face][1] * dim; - unsigned d = dim; - - if (dim == 4 && face >= 4) { - y = mt->total_height - 4; - x = (face - 4) * 8; - } - else if (dim < 4 && (face > 0 || mt->first_level > 0)) { - y = mt->total_height - 4; - x = face * 8; - } - - for (level = mt->first_level; level <= mt->last_level; level++) { - sp_miptree_set_image_offset(mt, level, face, x, y); - - d >>= 1; - - switch (d) { - case 4: - switch (face) { - case PIPE_TEX_FACE_POS_X: - case PIPE_TEX_FACE_NEG_X: - x += step_offsets[face][0] * d; - y += step_offsets[face][1] * d; - break; - case PIPE_TEX_FACE_POS_Y: - case PIPE_TEX_FACE_NEG_Y: - y += 12; - x -= 8; - break; - case PIPE_TEX_FACE_POS_Z: - case PIPE_TEX_FACE_NEG_Z: - y = mt->total_height - 4; - x = (face - 4) * 8; - break; - } - - case 2: - y = mt->total_height - 4; - x = 16 + face * 8; - break; - - case 1: - x += 48; - break; - - default: - x += step_offsets[face][0] * d; - y += step_offsets[face][1] * d; - break; - } - } - } - break; - } - case PIPE_TEXTURE_3D:{ - unsigned width = mt->width0; - unsigned height = mt->height0; - unsigned depth = mt->depth0; - unsigned pack_x_pitch, pack_x_nr; - unsigned pack_y_pitch; - unsigned level; - - mt->pitch = ((mt->width0 * mt->cpp + 3) & ~3) / mt->cpp; - mt->total_height = 0; - - pack_y_pitch = MAX2(mt->height0, 2); - pack_x_pitch = mt->pitch; - pack_x_nr = 1; - - for (level = mt->first_level; level <= mt->last_level; level++) { - unsigned nr_images = mt->target == PIPE_TEXTURE_3D ? depth : 6; - int x = 0; - int y = 0; - unsigned q, j; - - sp_miptree_set_level_info(mt, level, nr_images, - 0, mt->total_height, - width, height, depth); - - for (q = 0; q < nr_images;) { - for (j = 0; j < pack_x_nr && q < nr_images; j++, q++) { - sp_miptree_set_image_offset(mt, level, q, x, y); - x += pack_x_pitch; - } - - x = 0; - y += pack_y_pitch; - } - - - mt->total_height += y; - - if (pack_x_pitch > 4) { - pack_x_pitch >>= 1; - pack_x_nr <<= 1; - assert(pack_x_pitch * pack_x_nr <= mt->pitch); - } - - if (pack_y_pitch > 2) { - pack_y_pitch >>= 1; - } - - width = minify(width); - height = minify(height); - depth = minify(depth); - } - break; - } - - case PIPE_TEXTURE_1D: - case PIPE_TEXTURE_2D: -// case PIPE_TEXTURE_RECTANGLE: - sp_miptree_layout_2d(mt); - break; - default: - assert(0); - break; - } - - /* - DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__, - mt->pitch, - mt->total_height, mt->cpp, mt->pitch * mt->total_height * mt->cpp); - */ - - return TRUE; -} - diff --git a/src/mesa/pipe/softpipe/sp_tex_layout.h b/src/mesa/pipe/softpipe/sp_tex_layout.h deleted file mode 100644 index ea19c13b23..0000000000 --- a/src/mesa/pipe/softpipe/sp_tex_layout.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef SP_TEX_LAYOUT_H -#define SP_TEX_LAYOUT_H - - -struct pipe_context; -struct pipe_mipmap_tree; - - -extern boolean -softpipe_mipmap_tree_layout(struct pipe_context *pipe, - struct pipe_mipmap_tree *mt); - - -#endif /* SP_TEX_LAYOUT_H */ - - diff --git a/src/mesa/pipe/softpipe/sp_tex_sample.c b/src/mesa/pipe/softpipe/sp_tex_sample.c index 92958400fc..9e48ed0cd2 100644 --- a/src/mesa/pipe/softpipe/sp_tex_sample.c +++ b/src/mesa/pipe/softpipe/sp_tex_sample.c @@ -422,7 +422,7 @@ compute_lambda(struct tgsi_sampler *sampler, dsdy = FABSF(dsdy); rho = MAX2(dsdx, dsdy); if (sampler->state->normalized_coords) - rho *= sampler->texture->width0; + rho *= sampler->texture->width[0]; } if (t) { float dtdx = t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT]; @@ -432,7 +432,7 @@ compute_lambda(struct tgsi_sampler *sampler, dtdy = FABSF(dtdy); max = MAX2(dtdx, dtdy); if (sampler->state->normalized_coords) - max *= sampler->texture->height0; + max *= sampler->texture->height[0]; rho = MAX2(rho, max); } if (p) { @@ -443,7 +443,7 @@ compute_lambda(struct tgsi_sampler *sampler, dpdy = FABSF(dpdy); max = MAX2(dpdx, dpdy); if (sampler->state->normalized_coords) - max *= sampler->texture->depth0; + max *= sampler->texture->depth[0]; rho = MAX2(rho, max); } @@ -620,8 +620,8 @@ sp_get_samples_2d_common(struct tgsi_sampler *sampler, &level0, &level1, &levelBlend, &imgFilter); if (sampler->state->normalized_coords) { - width = sampler->texture->level[level0].width; - height = sampler->texture->level[level0].height; + width = sampler->texture->width[level0]; + height = sampler->texture->height[level0]; } else { width = height = 1; @@ -757,9 +757,9 @@ sp_get_samples_3d(struct tgsi_sampler *sampler, &level0, &level1, &levelBlend, &imgFilter); if (sampler->state->normalized_coords) { - width = sampler->texture->level[level0].width; - height = sampler->texture->level[level0].height; - depth = sampler->texture->level[level0].depth; + width = sampler->texture->width[level0]; + height = sampler->texture->height[level0]; + depth = sampler->texture->depth[level0]; } else { width = height = depth = 1; @@ -883,7 +883,7 @@ sp_get_samples_cube(struct tgsi_sampler *sampler, /** * Called via tgsi_sampler::get_samples() * Use the sampler's state setting to get a filtered RGBA value - * from the sampler's texture (mipmap tree). + * from the sampler's texture. * * XXX we can implement many versions of this function, each * tightly coded for a specific combination of sampler state diff --git a/src/mesa/pipe/softpipe/sp_texture.c b/src/mesa/pipe/softpipe/sp_texture.c new file mode 100644 index 0000000000..2f9a1e9837 --- /dev/null +++ b/src/mesa/pipe/softpipe/sp_texture.c @@ -0,0 +1,425 @@ +/************************************************************************** + * + * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + /* + * Authors: + * Keith Whitwell + * Michel Dänzer + */ + +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_util.h" +#include "pipe/p_winsys.h" + +#include "sp_context.h" +#include "sp_state.h" +#include "sp_texture.h" + + +/* At the moment, just make softpipe use the same layout for its + * textures as the i945. Softpipe needs some sort of texture layout, + * this one was handy. May be worthwhile to simplify this code a + * little. + */ + +static unsigned minify( unsigned d ) +{ + return MAX2(1, d>>1); +} + +static int align(int value, int alignment) +{ + return (value + alignment - 1) & ~(alignment - 1); +} + + +static void +sp_miptree_set_level_info(struct softpipe_texture *spt, + unsigned level, + unsigned nr_images, + unsigned x, unsigned y, unsigned w, unsigned h, + unsigned d) +{ + struct pipe_texture *pt = &spt->base; + + assert(level < PIPE_MAX_TEXTURE_LEVELS); + + pt->width[level] = w; + pt->height[level] = h; + pt->depth[level] = d; + + spt->nr_images[level] = nr_images; + spt->level_offset[level] = (x + y * spt->pitch) * pt->cpp; + + /* + DBG("%s level %d size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__, + level, w, h, d, x, y, spt->level_offset[level]); + */ + + /* Not sure when this would happen, but anyway: + */ + if (spt->image_offset[level]) { + FREE( spt->image_offset[level] ); + spt->image_offset[level] = NULL; + } + + assert(nr_images); + assert(!spt->image_offset[level]); + + spt->image_offset[level] = (unsigned *) MALLOC( nr_images * sizeof(unsigned) ); + spt->image_offset[level][0] = 0; +} + + +static void +sp_miptree_set_image_offset(struct softpipe_texture *spt, + unsigned level, unsigned img, unsigned x, unsigned y) +{ + if (img == 0 && level == 0) + assert(x == 0 && y == 0); + + assert(img < spt->nr_images[level]); + + spt->image_offset[level][img] = (x + y * spt->pitch); + + /* + DBG("%s level %d img %d pos %d,%d image_offset %x\n", + __FUNCTION__, level, img, x, y, spt->image_offset[level][img]); + */ +} + + +static void +sp_miptree_layout_2d( struct softpipe_texture *spt ) +{ + struct pipe_texture *pt = &spt->base; + int align_h = 2, align_w = 4; + unsigned level; + unsigned x = 0; + unsigned y = 0; + unsigned width = pt->width[0]; + unsigned height = pt->height[0]; + + spt->pitch = pt->width[0]; + /* XXX FIX THIS: + * we use alignment=64 bytes in sp_region_alloc(). If we change + * that, change this too. + */ + if (spt->pitch < 16) + spt->pitch = 16; + + /* May need to adjust pitch to accomodate the placement of + * the 2nd mipmap. This occurs when the alignment + * constraints of mipmap placement push the right edge of the + * 2nd mipmap out past the width of its parent. + */ + if (pt->first_level != pt->last_level) { + unsigned mip1_width = align(minify(pt->width[0]), align_w) + + minify(minify(pt->width[0])); + + if (mip1_width > pt->width[0]) + spt->pitch = mip1_width; + } + + /* Pitch must be a whole number of dwords, even though we + * express it in texels. + */ + spt->pitch = align(spt->pitch * pt->cpp, 4) / pt->cpp; + spt->total_height = 0; + + for ( level = pt->first_level ; level <= pt->last_level ; level++ ) { + unsigned img_height; + + sp_miptree_set_level_info(spt, level, 1, x, y, width, height, 1); + + if (pt->compressed) + img_height = MAX2(1, height/4); + else + img_height = align(height, align_h); + + + /* Because the images are packed better, the final offset + * might not be the maximal one: + */ + spt->total_height = MAX2(spt->total_height, y + img_height); + + /* Layout_below: step right after second mipmap. + */ + if (level == pt->first_level + 1) { + x += align(width, align_w); + } + else { + y += img_height; + } + + width = minify(width); + height = minify(height); + } +} + + +static const int initial_offsets[6][2] = { + {0, 0}, + {0, 2}, + {1, 0}, + {1, 2}, + {1, 1}, + {1, 3} +}; + +static const int step_offsets[6][2] = { + {0, 2}, + {0, 2}, + {-1, 2}, + {-1, 2}, + {-1, 1}, + {-1, 1} +}; + + + +static boolean +softpipe_mipmap_tree_layout(struct pipe_context *pipe, struct softpipe_texture * spt) +{ + struct pipe_texture *pt = &spt->base; + unsigned level; + + switch (pt->target) { + case PIPE_TEXTURE_CUBE:{ + const unsigned dim = pt->width[0]; + unsigned face; + unsigned lvlWidth = pt->width[0], lvlHeight = pt->height[0]; + + assert(lvlWidth == lvlHeight); /* cubemap images are square */ + + /* Depending on the size of the largest images, pitch can be + * determined either by the old-style packing of cubemap faces, + * or the final row of 4x4, 2x2 and 1x1 faces below this. + */ + if (dim > 32) + spt->pitch = ((dim * pt->cpp * 2 + 3) & ~3) / pt->cpp; + else + spt->pitch = 14 * 8; + + spt->total_height = dim * 4 + 4; + + /* Set all the levels to effectively occupy the whole rectangular region. + */ + for (level = pt->first_level; level <= pt->last_level; level++) { + sp_miptree_set_level_info(spt, level, 6, + 0, 0, + lvlWidth, lvlHeight, 1); + lvlWidth /= 2; + lvlHeight /= 2; + } + + + for (face = 0; face < 6; face++) { + unsigned x = initial_offsets[face][0] * dim; + unsigned y = initial_offsets[face][1] * dim; + unsigned d = dim; + + if (dim == 4 && face >= 4) { + y = spt->total_height - 4; + x = (face - 4) * 8; + } + else if (dim < 4 && (face > 0 || pt->first_level > 0)) { + y = spt->total_height - 4; + x = face * 8; + } + + for (level = pt->first_level; level <= pt->last_level; level++) { + sp_miptree_set_image_offset(spt, level, face, x, y); + + d >>= 1; + + switch (d) { + case 4: + switch (face) { + case PIPE_TEX_FACE_POS_X: + case PIPE_TEX_FACE_NEG_X: + x += step_offsets[face][0] * d; + y += step_offsets[face][1] * d; + break; + case PIPE_TEX_FACE_POS_Y: + case PIPE_TEX_FACE_NEG_Y: + y += 12; + x -= 8; + break; + case PIPE_TEX_FACE_POS_Z: + case PIPE_TEX_FACE_NEG_Z: + y = spt->total_height - 4; + x = (face - 4) * 8; + break; + } + + case 2: + y = spt->total_height - 4; + x = 16 + face * 8; + break; + + case 1: + x += 48; + break; + + default: + x += step_offsets[face][0] * d; + y += step_offsets[face][1] * d; + break; + } + } + } + break; + } + case PIPE_TEXTURE_3D:{ + unsigned width = pt->width[0]; + unsigned height = pt->height[0]; + unsigned depth = pt->depth[0]; + unsigned pack_x_pitch, pack_x_nr; + unsigned pack_y_pitch; + unsigned level; + + spt->pitch = ((pt->width[0] * pt->cpp + 3) & ~3) / pt->cpp; + spt->total_height = 0; + + pack_y_pitch = MAX2(pt->height[0], 2); + pack_x_pitch = spt->pitch; + pack_x_nr = 1; + + for (level = pt->first_level; level <= pt->last_level; level++) { + unsigned nr_images = pt->target == PIPE_TEXTURE_3D ? depth : 6; + int x = 0; + int y = 0; + unsigned q, j; + + sp_miptree_set_level_info(spt, level, nr_images, + 0, spt->total_height, + width, height, depth); + + for (q = 0; q < nr_images;) { + for (j = 0; j < pack_x_nr && q < nr_images; j++, q++) { + sp_miptree_set_image_offset(spt, level, q, x, y); + x += pack_x_pitch; + } + + x = 0; + y += pack_y_pitch; + } + + + spt->total_height += y; + + if (pack_x_pitch > 4) { + pack_x_pitch >>= 1; + pack_x_nr <<= 1; + assert(pack_x_pitch * pack_x_nr <= spt->pitch); + } + + if (pack_y_pitch > 2) { + pack_y_pitch >>= 1; + } + + width = minify(width); + height = minify(height); + depth = minify(depth); + } + break; + } + + case PIPE_TEXTURE_1D: + case PIPE_TEXTURE_2D: +// case PIPE_TEXTURE_RECTANGLE: + sp_miptree_layout_2d(spt); + break; + default: + assert(0); + break; + } + + /* + DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__, + spt->pitch, + spt->total_height, pt->cpp, spt->pitch * spt->total_height * pt->cpp); + */ + + return TRUE; +} + +void +softpipe_texture_create(struct pipe_context *pipe, struct pipe_texture **pt) +{ + struct softpipe_texture *spt = REALLOC(*pt, sizeof(struct pipe_texture), + sizeof(struct softpipe_texture)); + + if (spt) { + memset(&spt->base + 1, 0, + sizeof(struct softpipe_texture) - sizeof(struct pipe_texture)); + + if (softpipe_mipmap_tree_layout(pipe, spt)) { + spt->region = pipe->winsys->region_alloc(pipe->winsys, + spt->pitch * (*pt)->cpp * + spt->total_height, + PIPE_SURFACE_FLAG_TEXTURE); + } + + if (!spt->region) { + FREE(spt); + spt = NULL; + } + } + + *pt = &spt->base; +} + +void +softpipe_texture_release(struct pipe_context *pipe, struct pipe_texture **pt) +{ + if (!*pt) + return; + + /* + DBG("%s %p refcount will be %d\n", + __FUNCTION__, (void *) *pt, (*pt)->refcount - 1); + */ + if (--(*pt)->refcount <= 0) { + struct softpipe_texture *spt = (struct softpipe_texture *)*pt; + uint i; + + /* + DBG("%s deleting %p\n", __FUNCTION__, (void *) spt); + */ + + pipe->winsys->region_release(pipe->winsys, &spt->region); + + for (i = 0; i < PIPE_MAX_TEXTURE_LEVELS; i++) + if (spt->image_offset[i]) + free(spt->image_offset[i]); + + free(spt); + } + *pt = NULL; +} diff --git a/src/mesa/pipe/softpipe/sp_texture.h b/src/mesa/pipe/softpipe/sp_texture.h new file mode 100644 index 0000000000..2aca57bd1d --- /dev/null +++ b/src/mesa/pipe/softpipe/sp_texture.h @@ -0,0 +1,18 @@ +#ifndef SP_TEXTURE_H +#define SP_TEXTURE_H + + +struct pipe_context; +struct pipe_texture; + + +extern void +softpipe_texture_create(struct pipe_context *pipe, struct pipe_texture **pt); + +extern void +softpipe_texture_release(struct pipe_context *pipe, struct pipe_texture **pt); + + +#endif /* SP_TEXTURE */ + + diff --git a/src/mesa/pipe/softpipe/sp_tile_cache.c b/src/mesa/pipe/softpipe/sp_tile_cache.c index ea0c8b8f91..62ee6a27c9 100644 --- a/src/mesa/pipe/softpipe/sp_tile_cache.c +++ b/src/mesa/pipe/softpipe/sp_tile_cache.c @@ -51,7 +51,7 @@ struct softpipe_tile_cache { struct pipe_surface *surface; /**< the surface we're caching */ - struct pipe_mipmap_tree *texture; /**< if caching a texture */ + struct pipe_texture *texture; /**< if caching a texture */ struct softpipe_cached_tile entries[NUM_ENTRIES]; uint clear_flags[(MAX_WIDTH / TILE_SIZE) * (MAX_HEIGHT / TILE_SIZE) / 32]; float clear_value[4]; @@ -139,7 +139,7 @@ sp_tile_cache_get_surface(struct softpipe_tile_cache *tc) void sp_tile_cache_set_texture(struct softpipe_tile_cache *tc, - struct pipe_mipmap_tree *texture) + struct pipe_texture *texture) { uint i; diff --git a/src/mesa/pipe/softpipe/sp_tile_cache.h b/src/mesa/pipe/softpipe/sp_tile_cache.h index e66fec2e20..9967aa5044 100644 --- a/src/mesa/pipe/softpipe/sp_tile_cache.h +++ b/src/mesa/pipe/softpipe/sp_tile_cache.h @@ -71,7 +71,7 @@ sp_tile_cache_get_surface(struct softpipe_tile_cache *tc); extern void sp_tile_cache_set_texture(struct softpipe_tile_cache *tc, - struct pipe_mipmap_tree *texture); + struct pipe_texture *texture); extern void sp_flush_tile_cache(struct softpipe_context *softpipe, diff --git a/src/mesa/pipe/tgsi/exec/tgsi_exec.h b/src/mesa/pipe/tgsi/exec/tgsi_exec.h index 1d497e97fb..2c62b30f15 100644 --- a/src/mesa/pipe/tgsi/exec/tgsi_exec.h +++ b/src/mesa/pipe/tgsi/exec/tgsi_exec.h @@ -76,7 +76,7 @@ struct softpipe_tile_cache; /**< Opaque to TGSI */ struct tgsi_sampler { const struct pipe_sampler_state *state; - struct pipe_mipmap_tree *texture; + struct pipe_texture *texture; /** Get samples for four fragments in a quad */ void (*get_samples)(struct tgsi_sampler *sampler, const float s[QUAD_SIZE], diff --git a/src/mesa/sources b/src/mesa/sources index 2df60d1996..596d3b89d5 100644 --- a/src/mesa/sources +++ b/src/mesa/sources @@ -236,7 +236,7 @@ STATETRACKER_SOURCES = \ state_tracker/st_framebuffer.c \ state_tracker/st_mesa_to_tgsi.c \ state_tracker/st_program.c \ - state_tracker/st_mipmap_tree.c + state_tracker/st_texture.c SHADER_SOURCES = \ shader/arbprogparse.c \ diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c index f25cfd386a..c4e5af02d5 100644 --- a/src/mesa/state_tracker/st_atom_texture.c +++ b/src/mesa/state_tracker/st_atom_texture.c @@ -51,24 +51,24 @@ update_textures(struct st_context *st) for (u = 0; u < st->ctx->Const.MaxTextureImageUnits; u++) { struct gl_texture_object *texObj = st->ctx->Texture.Unit[u]._Current; - struct pipe_mipmap_tree *mt; + struct pipe_texture *pt; if (texObj) { GLboolean flush, retval; - retval = st_finalize_mipmap_tree(st->ctx, st->pipe, u, &flush); + retval = st_finalize_texture(st->ctx, st->pipe, u, &flush); #if 0 - printf("finalize_mipmap_tree returned %d, flush = %d\n", + printf("finalize_texture returned %d, flush = %d\n", retval, flush); #endif - mt = st_get_texobj_mipmap_tree(texObj); + pt = st_get_texobj_texture(texObj); } else { - mt = NULL; + pt = NULL; } - st->state.texture[u] = mt; - st->pipe->set_texture_state(st->pipe, u, mt); + st->state.texture[u] = pt; + st->pipe->set_texture_state(st->pipe, u, pt); } } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 39c0cf6b32..c28ad15b29 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -33,6 +33,7 @@ #include "main/imports.h" #include "main/image.h" #include "main/macros.h" +#include "main/texformat.h" #include "shader/program.h" #include "shader/prog_parameter.h" #include "shader/prog_print.h" @@ -50,6 +51,7 @@ #include "st_draw.h" #include "st_format.h" #include "st_mesa_to_tgsi.h" +#include "st_texture.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_inlines.h" @@ -440,63 +442,20 @@ _mesa_base_format(GLenum format) } - -static struct pipe_mipmap_tree * -alloc_mipmap_tree(struct st_context *st, - GLsizei width, GLsizei height, uint pipeFormat) -{ - const GLbitfield flags = PIPE_SURFACE_FLAG_TEXTURE; - struct pipe_mipmap_tree *mt; - GLuint cpp; - - mt = CALLOC_STRUCT(pipe_mipmap_tree); - if (!mt) - return NULL; - - cpp = st_sizeof_format(pipeFormat); - - mt->target = PIPE_TEXTURE_2D; - mt->internal_format = GL_RGBA; - mt->format = pipeFormat; - mt->first_level = 0; - mt->last_level = 0; - mt->width0 = width; - mt->height0 = height; - mt->depth0 = 1; - mt->cpp = cpp; - mt->compressed = 0; - mt->pitch = st->pipe->winsys->surface_pitch(st->pipe->winsys, cpp, width, - flags); - mt->region = st->pipe->winsys->region_alloc(st->pipe->winsys, - mt->pitch * cpp * height, flags); - mt->depth_pitch = 0; - mt->total_height = height; - mt->level[0].level_offset = 0; - mt->level[0].width = width; - mt->level[0].height = height; - mt->level[0].depth = 1; - mt->level[0].nr_images = 1; - mt->level[0].image_offset = NULL; - mt->refcount = 1; - - return mt; -} - - /** - * Make mipmap tree containing an image for glDrawPixels image. + * Make texture containing an image for glDrawPixels image. * If 'pixels' is NULL, leave the texture image data undefined. */ -static struct pipe_mipmap_tree * -make_mipmap_tree(struct st_context *st, - GLsizei width, GLsizei height, GLenum format, GLenum type, - const struct gl_pixelstore_attrib *unpack, - const GLvoid *pixels) +static struct pipe_texture * +make_texture(struct st_context *st, + GLsizei width, GLsizei height, GLenum format, GLenum type, + const struct gl_pixelstore_attrib *unpack, + const GLvoid *pixels) { GLcontext *ctx = st->ctx; struct pipe_context *pipe = st->pipe; const struct gl_texture_format *mformat; - struct pipe_mipmap_tree *mt; + struct pipe_texture *pt; GLuint pipeFormat, cpp; GLenum baseFormat; @@ -509,29 +468,33 @@ make_mipmap_tree(struct st_context *st, assert(pipeFormat); cpp = st_sizeof_format(pipeFormat); - mt = alloc_mipmap_tree(st, width, height, pipeFormat); - if (!mt) + pt = st_texture_create(st, PIPE_TEXTURE_2D, pipeFormat, baseFormat, 0, 0, + width, height, 1, 0); + if (!pt) return NULL; if (unpack->BufferObj && unpack->BufferObj->Name) { /* - mt->region = buffer_object_region(unpack->BufferObj); + pt->region = buffer_object_region(unpack->BufferObj); */ printf("st_DrawPixels (sourcing from PBO not implemented yet)\n"); } { + struct pipe_surface *surface; static const GLuint dstImageOffsets = 0; GLboolean success; - GLuint pitch = mt->pitch; GLubyte *dest; const GLbitfield imageTransferStateSave = ctx->_ImageTransferState; /* we'll do pixel transfer in a fragment shader */ ctx->_ImageTransferState = 0x0; + surface = pipe->get_tex_surface(pipe, pt, 0, 0, 0); + /* map texture region */ - dest = pipe->region_map(pipe, mt->region); + (void) pipe->region_map(pipe, surface->region); + dest = surface->region->map + surface->offset; /* Put image into texture region. * Note that the image is actually going to be upside down in @@ -542,7 +505,7 @@ make_mipmap_tree(struct st_context *st, mformat, /* gl_texture_format */ dest, /* dest */ 0, 0, 0, /* dstX/Y/Zoffset */ - pitch * cpp, /* dstRowStride, bytes */ + surface->pitch * cpp, /* dstRowStride, bytes */ &dstImageOffsets, /* dstImageOffsets */ width, height, 1, /* size */ format, type, /* src format/type */ @@ -550,44 +513,15 @@ make_mipmap_tree(struct st_context *st, unpack); /* unmap */ - pipe->region_unmap(pipe, mt->region); + pipe->region_unmap(pipe, surface->region); + pipe_surface_reference(&surface, NULL); assert(success); /* restore */ ctx->_ImageTransferState = imageTransferStateSave; } -#if 0 - mt->target = PIPE_TEXTURE_2D; - mt->internal_format = GL_RGBA; - mt->format = pipeFormat; - mt->first_level = 0; - mt->last_level = 0; - mt->width0 = width; - mt->height0 = height; - mt->depth0 = 1; - mt->cpp = cpp; - mt->compressed = 0; - mt->pitch = mt->pitch; - mt->depth_pitch = 0; - mt->total_height = height; - mt->level[0].level_offset = 0; - mt->level[0].width = width; - mt->level[0].height = height; - mt->level[0].depth = 1; - mt->level[0].nr_images = 1; - mt->level[0].image_offset = NULL; - mt->refcount = 1; -#endif - return mt; -} - - -static void -free_mipmap_tree(struct pipe_context *pipe, struct pipe_mipmap_tree *mt) -{ - pipe->winsys->region_release(pipe->winsys, &mt->region); - free(mt); + return pt; } @@ -693,7 +627,7 @@ static void draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, GLsizei width, GLsizei height, GLfloat zoomX, GLfloat zoomY, - struct pipe_mipmap_tree *mt, + struct pipe_texture *pt, struct st_vertex_program *stvp, struct st_fragment_program *stfp, const GLfloat *color, @@ -761,9 +695,9 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, pipe->set_viewport_state(pipe, &vp); } - /* mipmap tree state: */ + /* texture state: */ { - pipe->set_texture_state(pipe, unit, mt); + pipe->set_texture_state(pipe, unit, pt); } /* Compute window coords (y=0=bottom) with pixel zoom. @@ -1025,14 +959,13 @@ st_DrawPixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, any_pixel_transfer_ops(st) || !compatible_formats(format, type, ps->format)) { /* textured quad */ - struct pipe_mipmap_tree *mt - = make_mipmap_tree(ctx->st, width, height, format, type, - unpack, pixels); - if (mt) { + struct pipe_texture *pt + = make_texture(ctx->st, width, height, format, type, unpack, pixels); + if (pt) { draw_textured_quad(ctx, x, y, ctx->Current.RasterPos[2], width, height, ctx->Pixel.ZoomX, ctx->Pixel.ZoomY, - mt, stvp, stfp, color, GL_FALSE); - free_mipmap_tree(st->pipe, mt); + pt, stvp, stfp, color, GL_FALSE); + st->pipe->texture_release(st->pipe, &pt); } } else { @@ -1046,26 +979,29 @@ st_DrawPixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, /** * Create a texture which represents a bitmap image. */ -static struct pipe_mipmap_tree * +static struct pipe_texture * make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, const struct gl_pixelstore_attrib *unpack, const GLubyte *bitmap) { struct pipe_context *pipe = ctx->st->pipe; - const uint flags = PIPE_SURFACE_FLAG_TEXTURE; + struct pipe_surface *surface; uint format = 0, cpp, comp; + GLenum internal_format; ubyte *dest; - struct pipe_mipmap_tree *mt; + struct pipe_texture *pt; int row, col; /* find a texture format we know */ if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_I8 )) { format = PIPE_FORMAT_U_I8; + internal_format = GL_INTENSITY8; cpp = 1; comp = 0; } else if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A8_R8_G8_B8 )) { format = PIPE_FORMAT_U_A8_R8_G8_B8; + internal_format = GL_RGBA8; cpp = 4; comp = 3; /* alpha channel */ /*XXX little-endian dependency */ } @@ -1075,31 +1011,25 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, } /** - * Create a mipmap tree. + * Create a texture. */ - mt = CALLOC_STRUCT(pipe_mipmap_tree); - if (!mt) + pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, format, internal_format, + 0, 0, width, height, 1, 0); + if (!pt) return NULL; if (unpack->BufferObj && unpack->BufferObj->Name) { /* - mt->region = buffer_object_region(unpack->BufferObj); + pt->region = buffer_object_region(unpack->BufferObj); */ printf("st_Bitmap (sourcing from PBO not implemented yet)\n"); } - - /* allocate texture region/storage */ - mt->pitch = pipe->winsys->surface_pitch(pipe->winsys, cpp, width, flags); - mt->region = pipe->winsys->region_alloc(pipe->winsys, - mt->pitch * cpp * height, flags); + surface = pipe->get_tex_surface(pipe, pt, 0, 0, 0); /* map texture region */ - dest = pipe->region_map(pipe, mt->region); - if (!dest) { - printf("st_Bitmap region_map() failed!?!"); - return NULL; - } + (void) pipe->region_map(pipe, surface->region); + dest = surface->region->map + surface->offset; /* Put image into texture region. * Note that the image is actually going to be upside down in @@ -1109,7 +1039,7 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, for (row = 0; row < height; row++) { const GLubyte *src = (const GLubyte *) _mesa_image_address2d(unpack, bitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, row, 0); - ubyte *destRow = dest + row * mt->pitch * cpp; + ubyte *destRow = dest + row * surface->pitch * cpp; if (unpack->LsbFirst) { /* Lsb first */ @@ -1158,30 +1088,13 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, } /* row */ - /* unmap */ - pipe->region_unmap(pipe, mt->region); - - mt->target = PIPE_TEXTURE_2D; - mt->internal_format = GL_RGBA; - mt->format = format; - mt->first_level = 0; - mt->last_level = 0; - mt->width0 = width; - mt->height0 = height; - mt->depth0 = 1; - mt->cpp = cpp; - mt->compressed = 0; - mt->depth_pitch = 0; - mt->total_height = height; - mt->level[0].level_offset = 0; - mt->level[0].width = width; - mt->level[0].height = height; - mt->level[0].depth = 1; - mt->level[0].nr_images = 1; - mt->level[0].image_offset = NULL; - mt->refcount = 1; - - return mt; + /* Release surface */ + pipe->region_unmap(pipe, surface->region); + pipe_surface_reference(&surface, NULL); + + pt->format = format; + + return pt; } @@ -1193,21 +1106,21 @@ st_Bitmap(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, struct st_fragment_program *stfp; struct st_vertex_program *stvp; struct st_context *st = ctx->st; - struct pipe_mipmap_tree *mt; + struct pipe_texture *pt; stvp = make_vertex_shader(ctx->st, GL_TRUE); stfp = combined_bitmap_fragment_program(ctx); st_validate_state(st); - mt = make_bitmap_texture(ctx, width, height, unpack, bitmap); - if (mt) { + pt = make_bitmap_texture(ctx, width, height, unpack, bitmap); + if (pt) { draw_textured_quad(ctx, x, y, ctx->Current.RasterPos[2], width, height, 1.0, 1.0, - mt, stvp, stfp, + pt, stvp, stfp, ctx->Current.RasterColor, GL_FALSE); - free_mipmap_tree(st->pipe, mt); + st->pipe->texture_release(st->pipe, &pt); } } @@ -1296,7 +1209,7 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, struct st_fragment_program *stfp; struct pipe_surface *psRead; struct pipe_surface *psTex; - struct pipe_mipmap_tree *mt; + struct pipe_texture *pt; GLfloat *color; uint format; @@ -1327,11 +1240,12 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, psRead = rbRead->surface; format = psRead->format; - mt = alloc_mipmap_tree(ctx->st, width, height, format); - if (!mt) + pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, format, + rbRead->Base.InternalFormat, 0, 0, width, height, 1, 0); + if (!pt) return; - psTex = pipe->get_tex_surface(pipe, mt, 0, 0, 0); + psTex = pipe->get_tex_surface(pipe, pt, 0, 0, 0); if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) { srcy = ctx->DrawBuffer->Height - srcy - height; @@ -1368,10 +1282,10 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, /* draw textured quad */ draw_textured_quad(ctx, dstx, dsty, ctx->Current.RasterPos[2], width, height, ctx->Pixel.ZoomX, ctx->Pixel.ZoomY, - mt, stvp, stfp, color, GL_TRUE); + pt, stvp, stfp, color, GL_TRUE); pipe_surface_reference(&psTex, NULL); - free_mipmap_tree(st->pipe, mt); + st->pipe->texture_release(st->pipe, &pt); } diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 80c92e8b7a..43681b7f8a 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -286,7 +286,7 @@ st_render_texture(GLcontext *ctx, struct st_renderbuffer *strb; struct gl_renderbuffer *rb; struct pipe_context *pipe = st->pipe; - struct pipe_mipmap_tree *mt; + struct pipe_texture *pt; assert(!att->Renderbuffer); @@ -302,26 +302,26 @@ st_render_texture(GLcontext *ctx, rb->AllocStorage = NULL; /* should not get called */ strb = st_renderbuffer(rb); - /* get the mipmap tree for the texture */ - mt = st_get_texobj_mipmap_tree(att->Texture); - assert(mt); - assert(mt->level[att->TextureLevel].width); + /* get the texture for the texture object */ + pt = st_get_texobj_texture(att->Texture); + assert(pt); + assert(pt->width[att->TextureLevel]); - rb->Width = mt->level[att->TextureLevel].width; - rb->Height = mt->level[att->TextureLevel].height; + rb->Width = pt->width[att->TextureLevel]; + rb->Height = pt->height[att->TextureLevel]; - /* the renderbuffer's surface is inside the mipmap_tree: */ - strb->surface = pipe->get_tex_surface(pipe, mt, + /* the renderbuffer's surface is inside the texture */ + strb->surface = pipe->get_tex_surface(pipe, pt, att->CubeMapFace, att->TextureLevel, att->Zoffset); assert(strb->surface); - init_renderbuffer_bits(strb, mt->format); + init_renderbuffer_bits(strb, pt->format); /* - printf("RENDER TO TEXTURE obj=%p mt=%p surf=%p %d x %d\n", - att->Texture, mt, strb->surface, rb->Width, rb->Height); + printf("RENDER TO TEXTURE obj=%p pt=%p surf=%p %d x %d\n", + att->Texture, pt, strb->surface, rb->Width, rb->Height); */ /* Invalidate buffer state so that the pipe's framebuffer state diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 461705119f..f45d7e4275 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -40,7 +40,7 @@ #include "state_tracker/st_cb_fbo.h" #include "state_tracker/st_cb_texture.h" #include "state_tracker/st_format.h" -#include "state_tracker/st_mipmap_tree.h" +#include "state_tracker/st_texture.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" @@ -54,8 +54,7 @@ struct st_texture_object { struct gl_texture_object base; /* The "parent" object */ - /* The mipmap tree must include at least these levels once - * validated: + /* The texture must include at least these levels once validated: */ GLuint firstLevel; GLuint lastLevel; @@ -67,7 +66,7 @@ struct st_texture_object /* On validation any active images held in main memory or in other * regions will be copied to this region and the old storage freed. */ - struct pipe_mipmap_tree *mt; + struct pipe_texture *pt; GLboolean imageOverride; GLint depthOverride; @@ -76,24 +75,6 @@ struct st_texture_object -struct st_texture_image -{ - struct gl_texture_image base; - - /* These aren't stored in gl_texture_image - */ - GLuint level; - GLuint face; - - /* If stImage->mt != NULL, image data is stored here. - * Else if stImage->base.Data != NULL, image is stored there. - * Else there is no image data. - */ - struct pipe_mipmap_tree *mt; -}; - - - static INLINE struct st_texture_object * st_texture_object(struct gl_texture_object *obj) @@ -108,11 +89,11 @@ st_texture_image(struct gl_texture_image *img) } -struct pipe_mipmap_tree * -st_get_texobj_mipmap_tree(struct gl_texture_object *texObj) +struct pipe_texture * +st_get_texobj_texture(struct gl_texture_object *texObj) { struct st_texture_object *stObj = st_texture_object(texObj); - return stObj->mt; + return stObj->pt; } @@ -174,9 +155,9 @@ st_IsTextureResident(GLcontext * ctx, struct gl_texture_object *texObj) struct st_texture_object *stObj = st_texture_object(texObj); return - stObj->mt && - stObj->mt->region && - intel_is_region_resident(intel, stObj->mt->region); + stObj->pt && + stObj->pt->region && + intel_is_region_resident(intel, stObj->pt->region); #endif return 1; } @@ -207,11 +188,10 @@ static void st_DeleteTextureObject(GLcontext *ctx, struct gl_texture_object *texObj) { - struct pipe_context *pipe = ctx->st->pipe; struct st_texture_object *stObj = st_texture_object(texObj); - if (stObj->mt) - st_miptree_release(pipe, &stObj->mt); + if (stObj->pt) + ctx->st->pipe->texture_release(ctx->st->pipe, &stObj->pt); _mesa_delete_texture_object(ctx, texObj); } @@ -220,13 +200,12 @@ st_DeleteTextureObject(GLcontext *ctx, static void st_FreeTextureImageData(GLcontext * ctx, struct gl_texture_image *texImage) { - struct pipe_context *pipe = ctx->st->pipe; struct st_texture_image *stImage = st_texture_image(texImage); DBG("%s\n", __FUNCTION__); - if (stImage->mt) { - st_miptree_release(pipe, &stImage->mt); + if (stImage->pt) { + ctx->st->pipe->texture_release(ctx->st->pipe, &stImage->pt); } if (texImage->Data) { @@ -287,10 +266,10 @@ do_memcpy(void *dest, const void *src, size_t n) } -/* Functions to store texture images. Where possible, mipmap_tree's +/* Functions to store texture images. Where possible, textures * will be created or further instantiated with image data, otherwise * images will be stored in malloc'd memory. A validation step is - * required to pull those images into a mipmap tree, or otherwise + * required to pull those images into a texture, or otherwise * decide a fallback is required. */ @@ -313,17 +292,16 @@ logbase2(int n) /* Otherwise, store it in memory if (Border != 0) or (any dimension == * 1). * - * Otherwise, if max_level >= level >= min_level, create tree with - * space for textures from min_level down to max_level. + * Otherwise, if max_level >= level >= min_level, create texture with + * space for images from min_level down to max_level. * - * Otherwise, create tree with space for textures from (level - * 0)..(1x1). Consider pruning this tree at a validation if the - * saving is worth it. + * Otherwise, create texture with space for images from (level 0)..(1x1). + * Consider pruning this texture at a validation if the saving is worth it. */ static void -guess_and_alloc_mipmap_tree(struct pipe_context *pipe, - struct st_texture_object *stObj, - struct st_texture_image *stImage) +guess_and_alloc_texture(struct st_context *st, + struct st_texture_object *stObj, + struct st_texture_image *stImage) { GLuint firstLevel; GLuint lastLevel; @@ -382,23 +360,20 @@ guess_and_alloc_mipmap_tree(struct pipe_context *pipe, lastLevel = firstLevel + MAX2(MAX2(l2width, l2height), l2depth); } - assert(!stObj->mt); + assert(!stObj->pt); if (stImage->base.IsCompressed) comp_byte = compressed_num_bytes(stImage->base.TexFormat->MesaFormat); - stObj->mt = st_miptree_create(pipe, + stObj->pt = st_texture_create(st, gl_target_to_pipe(stObj->base.Target), - stImage->base.InternalFormat, + st_mesa_format_to_pipe_format(stImage->base.TexFormat->MesaFormat), + stImage->base.InternalFormat, firstLevel, lastLevel, width, height, depth, - stImage->base.TexFormat->TexelBytes, comp_byte); - stObj->mt->format - = st_mesa_format_to_pipe_format(stImage->base.TexFormat->MesaFormat); - DBG("%s - success\n", __FUNCTION__); } @@ -482,11 +457,11 @@ try_pbo_upload(GLcontext *ctx, else src_stride = width; - dst_offset = st_miptree_image_offset(stImage->mt, + dst_offset = st_texture_image_offset(stImage->pt, stImage->face, stImage->level); - dst_stride = stImage->mt->pitch; + dst_stride = stImage->pt->pitch; { struct _DriBufferObject *src_buffer = @@ -495,11 +470,11 @@ try_pbo_upload(GLcontext *ctx, /* Temporary hack: cast to _DriBufferObject: */ struct _DriBufferObject *dst_buffer = - (struct _DriBufferObject *)stImage->mt->region->buffer; + (struct _DriBufferObject *)stImage->pt->region->buffer; intelEmitCopyBlit(intel, - stImage->mt->cpp, + stImage->pt->cpp, src_stride, src_buffer, src_offset, dst_stride, dst_buffer, dst_offset, 0, 0, 0, 0, width, height, @@ -540,7 +515,6 @@ st_TexImage(GLcontext * ctx, struct gl_texture_object *texObj, struct gl_texture_image *texImage, GLsizei imageSize, int compressed) { - struct pipe_context *pipe = ctx->st->pipe; struct st_texture_object *stObj = st_texture_object(texObj); struct st_texture_image *stImage = st_texture_image(texImage); GLint postConvWidth = width; @@ -589,58 +563,58 @@ st_TexImage(GLcontext * ctx, /* Release the reference to a potentially orphaned buffer. * Release any old malloced memory. */ - if (stImage->mt) { - st_miptree_release(pipe, &stImage->mt); + if (stImage->pt) { + ctx->st->pipe->texture_release(ctx->st->pipe, &stImage->pt); assert(!texImage->Data); } else if (texImage->Data) { _mesa_align_free(texImage->Data); } - /* If this is the only texture image in the tree, could call + /* If this is the only texture image in the texture, could call * bmBufferData with NULL data to free the old block and avoid * waiting on any outstanding fences. */ - if (stObj->mt && - stObj->mt->first_level == level && - stObj->mt->last_level == level && - stObj->mt->target != PIPE_TEXTURE_CUBE && - !st_miptree_match_image(stObj->mt, &stImage->base, + if (stObj->pt && + stObj->pt->first_level == level && + stObj->pt->last_level == level && + stObj->pt->target != PIPE_TEXTURE_CUBE && + !st_texture_match_image(stObj->pt, &stImage->base, stImage->face, stImage->level)) { DBG("release it\n"); - st_miptree_release(pipe, &stObj->mt); - assert(!stObj->mt); + ctx->st->pipe->texture_release(ctx->st->pipe, &stObj->pt); + assert(!stObj->pt); } - if (!stObj->mt) { - guess_and_alloc_mipmap_tree(pipe, stObj, stImage); - if (!stObj->mt) { - DBG("guess_and_alloc_mipmap_tree: failed\n"); + if (!stObj->pt) { + guess_and_alloc_texture(ctx->st, stObj, stImage); + if (!stObj->pt) { + DBG("guess_and_alloc_texture: failed\n"); } } - assert(!stImage->mt); + assert(!stImage->pt); - if (stObj->mt && - st_miptree_match_image(stObj->mt, &stImage->base, + if (stObj->pt && + st_texture_match_image(stObj->pt, &stImage->base, stImage->face, stImage->level)) { - st_miptree_reference(&stImage->mt, stObj->mt); - assert(stImage->mt); + pipe_texture_reference(ctx->st->pipe, &stImage->pt, stObj->pt); + assert(stImage->pt); } - if (!stImage->mt) - DBG("XXX: Image did not fit into tree - storing in local memory!\n"); + if (!stImage->pt) + DBG("XXX: Image did not fit into texture - storing in local memory!\n"); #if 0 /* XXX FIX when st_buffer_objects are in place */ /* PBO fastpaths: */ if (dims <= 2 && - stImage->mt && + stImage->pt && intel_buffer_object(unpack->BufferObj) && check_pbo_format(internalFormat, format, - type, stImage->base.TexFormat)) { + type, texImage->TexFormat)) { DBG("trying pbo upload\n"); @@ -650,9 +624,9 @@ st_TexImage(GLcontext * ctx, * performance (in particular when pipe_region_cow() is * required). */ - if (stObj->mt == stImage->mt && - stObj->mt->first_level == level && - stObj->mt->last_level == level) { + if (stObj->pt == stImage->pt && + stObj->pt->first_level == level && + stObj->pt->last_level == level) { if (try_pbo_zcopy(intel, stImage, unpack, internalFormat, @@ -683,7 +657,7 @@ st_TexImage(GLcontext * ctx, /* intelCopyTexImage calls this function with pixels == NULL, with - * the expectation that the mipmap tree will be set up but nothing + * the expectation that the texture will be set up but nothing * more will be done. This is where those calls return: */ if (compressed) { @@ -698,13 +672,9 @@ st_TexImage(GLcontext * ctx, if (!pixels) return; - if (stImage->mt) { - texImage->Data = st_miptree_image_map(pipe, - stImage->mt, - stImage->face, - stImage->level, - &dstRowStride, - stImage->base.ImageOffsets); + if (stImage->pt) { + texImage->Data = st_texture_image_map(ctx->st, stImage, 0); + dstRowStride = stImage->surface->pitch * stImage->surface->cpp; } else { /* Allocate regular memory and store the image there temporarily. */ @@ -732,22 +702,36 @@ st_TexImage(GLcontext * ctx, if (compressed) { memcpy(texImage->Data, pixels, imageSize); } - else if (!texImage->TexFormat->StoreImage(ctx, dims, - texImage->_BaseFormat, - texImage->TexFormat, - texImage->Data, - 0, 0, 0, /* dstX/Y/Zoffset */ - dstRowStride, - texImage->ImageOffsets, - width, height, depth, - format, type, pixels, unpack)) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage"); + else { + GLuint srcImageStride = _mesa_image_image_stride(unpack, width, height, + format, type); + int i; + + for (i = 0; i++ < depth;) { + if (!texImage->TexFormat->StoreImage(ctx, dims, + texImage->_BaseFormat, + texImage->TexFormat, + texImage->Data, + 0, 0, 0, /* dstX/Y/Zoffset */ + dstRowStride, + texImage->ImageOffsets, + width, height, 1, + format, type, pixels, unpack)) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage"); + } + + if (stImage->pt && i < depth) { + st_texture_image_unmap(ctx->st, stImage); + texImage->Data = st_texture_image_map(ctx->st, stImage, i); + pixels += srcImageStride; + } + } } _mesa_unmap_teximage_pbo(ctx, unpack); - if (stImage->mt) { - st_miptree_image_unmap(pipe, stImage->mt); + if (stImage->pt) { + st_texture_image_unmap(ctx->st, stImage); texImage->Data = NULL; } @@ -839,49 +823,58 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level, /* struct intel_context *intel = intel_context(ctx); */ - struct pipe_context *pipe = ctx->st->pipe; struct st_texture_image *stImage = st_texture_image(texImage); + GLuint dstImageStride = _mesa_image_image_stride(&ctx->Pack, texImage->Width, + texImage->Height, format, + type); + GLuint depth; + int i; /* Map */ - if (stImage->mt) { + if (stImage->pt) { /* Image is stored in hardware format in a buffer managed by the * kernel. Need to explicitly map and unmap it. */ - stImage->base.Data = - st_miptree_image_map(pipe, - stImage->mt, - stImage->face, - stImage->level, - &stImage->base.RowStride, - stImage->base.ImageOffsets); - stImage->base.RowStride /= stImage->mt->cpp; + texImage->Data = st_texture_image_map(ctx->st, stImage, 0); + texImage->RowStride = stImage->surface->pitch; } else { /* Otherwise, the image should actually be stored in - * stImage->base.Data. This is pretty confusing for + * texImage->Data. This is pretty confusing for * everybody, I'd much prefer to separate the two functions of * texImage->Data - storage for texture images in main memory * and access (ie mappings) of images. In other words, we'd * create a new texImage->Map field and leave Data simply for * storage. */ - assert(stImage->base.Data); + assert(texImage->Data); } + depth = texImage->Depth; + texImage->Depth = 1; - if (compressed) { - _mesa_get_compressed_teximage(ctx, target, level, pixels, - texObj, texImage); - } else { - _mesa_get_teximage(ctx, target, level, format, type, pixels, - texObj, texImage); + for (i = 0; i++ < depth;) { + if (compressed) { + _mesa_get_compressed_teximage(ctx, target, level, pixels, + texObj, texImage); + } else { + _mesa_get_teximage(ctx, target, level, format, type, pixels, + texObj, texImage); + } + + if (stImage->pt && i < depth) { + st_texture_image_unmap(ctx->st, stImage); + texImage->Data = st_texture_image_map(ctx->st, stImage, i); + pixels += dstImageStride; + } } - + + texImage->Depth = depth; /* Unmap */ - if (stImage->mt) { - st_miptree_image_unmap(pipe, stImage->mt); - stImage->base.Data = NULL; + if (stImage->pt) { + st_texture_image_unmap(ctx->st, stImage); + texImage->Data = NULL; } } @@ -921,9 +914,11 @@ st_TexSubimage(GLcontext * ctx, struct gl_texture_object *texObj, struct gl_texture_image *texImage) { - struct pipe_context *pipe = ctx->st->pipe; struct st_texture_image *stImage = st_texture_image(texImage); GLuint dstRowStride; + GLuint srcImageStride = _mesa_image_image_stride(packing, width, height, + format, type); + int i; DBG("%s target %s level %d offset %d,%d %dx%d\n", __FUNCTION__, _mesa_lookup_enum_by_nr(target), @@ -938,25 +933,28 @@ st_TexSubimage(GLcontext * ctx, /* Map buffer if necessary. Need to lock to prevent other contexts * from uploading the buffer under us. */ - if (stImage->mt) - texImage->Data = st_miptree_image_map(pipe, - stImage->mt, - stImage->face, - stImage->level, - &dstRowStride, - texImage->ImageOffsets); - - assert(dstRowStride); - - if (!texImage->TexFormat->StoreImage(ctx, dims, texImage->_BaseFormat, - texImage->TexFormat, - texImage->Data, - xoffset, yoffset, zoffset, - dstRowStride, - texImage->ImageOffsets, - width, height, depth, - format, type, pixels, packing)) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "intelTexSubImage"); + if (stImage->pt) { + texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset); + dstRowStride = stImage->surface->pitch * stImage->surface->cpp; + } + + for (i = 0; i++ < depth;) { + if (!texImage->TexFormat->StoreImage(ctx, dims, texImage->_BaseFormat, + texImage->TexFormat, + texImage->Data, + xoffset, yoffset, 0, + dstRowStride, + texImage->ImageOffsets, + width, height, 1, + format, type, pixels, packing)) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "intelTexSubImage"); + } + + if (stImage->pt && i < depth) { + st_texture_image_unmap(ctx->st, stImage); + texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset + i); + pixels += srcImageStride; + } } #if 0 @@ -970,8 +968,8 @@ st_TexSubimage(GLcontext * ctx, _mesa_unmap_teximage_pbo(ctx, packing); - if (stImage->mt) { - st_miptree_image_unmap(pipe, stImage->mt); + if (stImage->pt) { + st_texture_image_unmap(ctx->st, stImage); texImage->Data = NULL; } } @@ -1074,7 +1072,7 @@ fallback_copy_texsubimage(GLcontext *ctx, { struct pipe_context *pipe = ctx->st->pipe; const uint face = texture_face(target); - struct pipe_mipmap_tree *mt = stImage->mt; + struct pipe_texture *pt = stImage->pt; struct pipe_surface *src_surf, *dest_surf; GLfloat *data; GLint row, yStep; @@ -1090,7 +1088,7 @@ fallback_copy_texsubimage(GLcontext *ctx, src_surf = strb->surface; - dest_surf = pipe->get_tex_surface(pipe, mt, + dest_surf = pipe->get_tex_surface(pipe, pt, face, level, destZ); (void) pipe->region_map(pipe, dest_surf->region); @@ -1150,7 +1148,7 @@ do_copy_texsubimage(GLcontext *ctx, struct gl_framebuffer *fb = ctx->ReadBuffer; struct st_renderbuffer *strb; struct pipe_context *pipe = ctx->st->pipe; - struct pipe_region *src_region, *dest_region; + struct pipe_surface *dest_surface; uint dest_format, src_format; (void) texImage; @@ -1169,29 +1167,24 @@ do_copy_texsubimage(GLcontext *ctx, assert(strb); assert(strb->surface); - assert(stImage->mt); + assert(stImage->pt); if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) { srcY = strb->Base.Height - srcY - height; } src_format = strb->surface->format; - dest_format = stImage->mt->format; + dest_format = stImage->pt->format; - src_region = strb->surface->region; - dest_region = stImage->mt->region; + dest_surface = pipe->get_tex_surface(pipe, stImage->pt, stImage->face, + stImage->level, destZ); if (src_format == dest_format && ctx->_ImageTransferState == 0x0 && - src_region && - dest_region && - strb->surface->cpp == stImage->mt->cpp) { + strb->surface->region && + dest_surface->region && + strb->surface->cpp == stImage->pt->cpp) { /* do blit-style copy */ - struct pipe_surface *dest_surface = pipe->get_tex_surface(pipe, - stImage->mt, - stImage->face, - stImage->level, - destZ); /* XXX may need to invert image depending on window * vs. user-created FBO @@ -1203,12 +1196,12 @@ do_copy_texsubimage(GLcontext *ctx, * worth it: */ intelEmitCopyBlit(intel, - stImage->mt->cpp, + stImage->pt->cpp, -src->pitch, src->buffer, src->height * src->pitch * src->cpp, - stImage->mt->pitch, - stImage->mt->region->buffer, + stImage->pt->pitch, + stImage->pt->region->buffer, dest_offset, x, y + height, dstx, dsty, width, height, GL_COPY); /* ? */ @@ -1224,8 +1217,6 @@ do_copy_texsubimage(GLcontext *ctx, /* size */ width, height); #endif - - pipe_surface_reference(&dest_surface, NULL); } else { fallback_copy_texsubimage(ctx, target, level, @@ -1234,6 +1225,7 @@ do_copy_texsubimage(GLcontext *ctx, srcX, srcY, width, height); } + pipe_surface_reference(&dest_surface, NULL); #if 0 /* GL_SGIS_generate_mipmap -- this can be accelerated now. @@ -1267,7 +1259,7 @@ st_CopyTexImage1D(GLcontext * ctx, GLenum target, GLint level, goto fail; #endif - /* Setup or redefine the texture object, mipmap tree and texture + /* Setup or redefine the texture object, texture and texture * image. Don't populate yet. */ ctx->Driver.TexImage1D(ctx, target, level, internalFormat, @@ -1299,7 +1291,7 @@ st_CopyTexImage2D(GLcontext * ctx, GLenum target, GLint level, goto fail; #endif - /* Setup or redefine the texture object, mipmap tree and texture + /* Setup or redefine the texture object, texture and texture * image. Don't populate yet. */ ctx->Driver.TexImage2D(ctx, target, level, internalFormat, @@ -1407,28 +1399,28 @@ calculate_first_last_level(struct st_texture_object *stObj) static void -copy_image_data_to_tree(struct pipe_context *pipe, - struct st_texture_object *stObj, - struct st_texture_image *stImage) +copy_image_data_to_texture(struct st_context *st, + struct st_texture_object *stObj, + struct st_texture_image *stImage) { - if (stImage->mt) { + if (stImage->pt) { /* Copy potentially with the blitter: */ - st_miptree_image_copy(pipe, - stObj->mt, /* dest miptree */ + st_texture_image_copy(st->pipe, + stObj->pt, /* dest texture */ stImage->face, stImage->level, - stImage->mt /* src miptree */ + stImage->pt /* src texture */ ); - st_miptree_release(pipe, &stImage->mt); + st->pipe->texture_release(st->pipe, &stImage->pt); } else { assert(stImage->base.Data != NULL); /* More straightforward upload. */ - st_miptree_image_data(pipe, - stObj->mt, + st_texture_image_data(st->pipe, + stObj->pt, stImage->face, stImage->level, stImage->base.Data, @@ -1439,16 +1431,16 @@ copy_image_data_to_tree(struct pipe_context *pipe, stImage->base.Data = NULL; } - st_miptree_reference(&stImage->mt, stObj->mt); + pipe_texture_reference(st->pipe, &stImage->pt, stObj->pt); } /* */ GLboolean -st_finalize_mipmap_tree(GLcontext *ctx, - struct pipe_context *pipe, GLuint unit, - GLboolean *needFlush) +st_finalize_texture(GLcontext *ctx, + struct pipe_context *pipe, GLuint unit, + GLboolean *needFlush) { struct gl_texture_object *tObj = ctx->Texture.Unit[unit]._Current; struct st_texture_object *stObj = st_texture_object(tObj); @@ -1465,7 +1457,7 @@ st_finalize_mipmap_tree(GLcontext *ctx, */ assert(stObj->base._Complete); - /* What levels must the tree include at a minimum? + /* What levels must the texture include at a minimum? */ calculate_first_last_level(stObj); firstImage = @@ -1474,27 +1466,27 @@ st_finalize_mipmap_tree(GLcontext *ctx, /* Fallback case: */ if (firstImage->base.Border) { - if (stObj->mt) { - st_miptree_release(pipe, &stObj->mt); + if (stObj->pt) { + ctx->st->pipe->texture_release(ctx->st->pipe, &stObj->pt); } return GL_FALSE; } - /* If both firstImage and stObj have a tree which can contain + /* If both firstImage and stObj point to a texture which can contain * all active images, favour firstImage. Note that because of the * completeness requirement, we know that the image dimensions * will match. */ - if (firstImage->mt && - firstImage->mt != stObj->mt && - firstImage->mt->first_level <= stObj->firstLevel && - firstImage->mt->last_level >= stObj->lastLevel) { + if (firstImage->pt && + firstImage->pt != stObj->pt && + firstImage->pt->first_level <= stObj->firstLevel && + firstImage->pt->last_level >= stObj->lastLevel) { - if (stObj->mt) - st_miptree_release(pipe, &stObj->mt); + if (stObj->pt) + ctx->st->pipe->texture_release(ctx->st->pipe, &stObj->pt); - st_miptree_reference(&stObj->mt, firstImage->mt); + pipe_texture_reference(ctx->st->pipe, &stObj->pt, firstImage->pt); } if (firstImage->base.IsCompressed) { @@ -1505,48 +1497,45 @@ st_finalize_mipmap_tree(GLcontext *ctx, cpp = firstImage->base.TexFormat->TexelBytes; } - /* Check tree can hold all active levels. Check tree matches + /* Check texture can hold all active levels. Check texture matches * target, imageFormat, etc. * * XXX: For some layouts (eg i945?), the test might have to be - * first_level == firstLevel, as the tree isn't valid except at the + * first_level == firstLevel, as the texture isn't valid except at the * original start level. Hope to get around this by * programming minLod, maxLod, baseLevel into the hardware and - * leaving the tree alone. + * leaving the texture alone. */ - if (stObj->mt && - (stObj->mt->target != gl_target_to_pipe(stObj->base.Target) || - stObj->mt->internal_format != firstImage->base.InternalFormat || - stObj->mt->first_level != stObj->firstLevel || - stObj->mt->last_level != stObj->lastLevel || - stObj->mt->width0 != firstImage->base.Width || - stObj->mt->height0 != firstImage->base.Height || - stObj->mt->depth0 != firstImage->base.Depth || - stObj->mt->cpp != cpp || - stObj->mt->compressed != firstImage->base.IsCompressed)) { - st_miptree_release(pipe, &stObj->mt); + if (stObj->pt && + (stObj->pt->target != gl_target_to_pipe(stObj->base.Target) || + stObj->pt->internal_format != firstImage->base.InternalFormat || + stObj->pt->first_level != stObj->firstLevel || + stObj->pt->last_level != stObj->lastLevel || + stObj->pt->width[0] != firstImage->base.Width || + stObj->pt->height[0] != firstImage->base.Height || + stObj->pt->depth[0] != firstImage->base.Depth || + stObj->pt->cpp != cpp || + stObj->pt->compressed != firstImage->base.IsCompressed)) { + ctx->st->pipe->texture_release(ctx->st->pipe, &stObj->pt); } - /* May need to create a new tree: + /* May need to create a new texture: */ - if (!stObj->mt) { - stObj->mt = st_miptree_create(pipe, + if (!stObj->pt) { + stObj->pt = st_texture_create(ctx->st, gl_target_to_pipe(stObj->base.Target), - firstImage->base.InternalFormat, + st_mesa_format_to_pipe_format(firstImage->base.TexFormat->MesaFormat), + firstImage->base.InternalFormat, stObj->firstLevel, stObj->lastLevel, firstImage->base.Width, firstImage->base.Height, firstImage->base.Depth, - cpp, comp_byte); - - stObj->mt->format - = st_mesa_format_to_pipe_format(firstImage->base.TexFormat->MesaFormat); } - /* Pull in any images not in the object's tree: + /* Pull in any images not in the object's texture: */ nr_faces = (stObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1; for (face = 0; face < nr_faces; face++) { @@ -1554,10 +1543,10 @@ st_finalize_mipmap_tree(GLcontext *ctx, struct st_texture_image *stImage = st_texture_image(stObj->base.Image[face][i]); - /* Need to import images in main memory or held in other trees. + /* Need to import images in main memory or held in other textures. */ - if (stObj->mt != stImage->mt) { - copy_image_data_to_tree(pipe, stObj, stImage); + if (stObj->pt != stImage->pt) { + copy_image_data_to_texture(ctx->st, stObj, stImage); *needFlush = GL_TRUE; } } diff --git a/src/mesa/state_tracker/st_cb_texture.h b/src/mesa/state_tracker/st_cb_texture.h index 7a1867dc58..7f8082b029 100644 --- a/src/mesa/state_tracker/st_cb_texture.h +++ b/src/mesa/state_tracker/st_cb_texture.h @@ -2,14 +2,14 @@ #define ST_CB_TEXTURE_H -extern struct pipe_mipmap_tree * -st_get_texobj_mipmap_tree(struct gl_texture_object *texObj); +extern struct pipe_texture * +st_get_texobj_texture(struct gl_texture_object *texObj); extern GLboolean -st_finalize_mipmap_tree(GLcontext *ctx, - struct pipe_context *pipe, GLuint unit, - GLboolean *needFlush); +st_finalize_texture(GLcontext *ctx, + struct pipe_context *pipe, GLuint unit, + GLboolean *needFlush); extern void diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index a6045230a0..db97014c5a 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -36,7 +36,6 @@ struct st_context; struct st_region; struct st_texture_object; -struct st_texture_image; struct st_fragment_program; struct draw_context; struct draw_stage; @@ -61,6 +60,25 @@ struct st_tracked_state { +struct st_texture_image +{ + struct gl_texture_image base; + + /* These aren't stored in gl_texture_image + */ + GLuint level; + GLuint face; + + /* If stImage->pt != NULL, image data is stored here. + * Else if stImage->base.Data != NULL, image is stored there. + * Else there is no image data. + */ + struct pipe_texture *pt; + + struct pipe_surface *surface; +}; + + struct st_context { @@ -91,7 +109,7 @@ struct st_context struct pipe_constant_buffer constants[2]; struct pipe_feedback_state feedback; struct pipe_framebuffer_state framebuffer; - struct pipe_mipmap_tree *texture[PIPE_MAX_SAMPLERS]; + struct pipe_texture *texture[PIPE_MAX_SAMPLERS]; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; struct pipe_viewport_state viewport; diff --git a/src/mesa/state_tracker/st_mipmap_tree.c b/src/mesa/state_tracker/st_mipmap_tree.c deleted file mode 100644 index 6ccf33105f..0000000000 --- a/src/mesa/state_tracker/st_mipmap_tree.c +++ /dev/null @@ -1,328 +0,0 @@ -/************************************************************************** - * - * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#include "st_mipmap_tree.h" -#include "enums.h" - -#include "pipe/p_state.h" -#include "pipe/p_context.h" -#include "pipe/p_defines.h" -#include "pipe/p_util.h" -#include "pipe/p_inlines.h" -#include "pipe/p_winsys.h" - - -#define DBG if(0) printf - -#if 0 -static GLenum -target_to_target(GLenum target) -{ - switch (target) { - case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: - case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: - case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: - return GL_TEXTURE_CUBE_MAP_ARB; - default: - return target; - } -} -#endif - -struct pipe_mipmap_tree * -st_miptree_create(struct pipe_context *pipe, - unsigned target, - GLenum internal_format, - GLuint first_level, - GLuint last_level, - GLuint width0, - GLuint height0, - GLuint depth0, GLuint cpp, GLuint compress_byte) -{ - GLboolean ok; - struct pipe_mipmap_tree *mt = calloc(sizeof(*mt), 1); - GLbitfield flags = 0x0; - - assert(target <= PIPE_TEXTURE_CUBE); - - DBG("%s target %s format %s level %d..%d\n", __FUNCTION__, - _mesa_lookup_enum_by_nr(target), - _mesa_lookup_enum_by_nr(internal_format), first_level, last_level); - - mt->target = target; - mt->internal_format = internal_format; - mt->first_level = first_level; - mt->last_level = last_level; - mt->width0 = width0; - mt->height0 = height0; - mt->depth0 = depth0; - mt->cpp = compress_byte ? compress_byte : cpp; - mt->compressed = compress_byte ? 1 : 0; - mt->refcount = 1; - - ok = pipe->mipmap_tree_layout(pipe, mt); - if (ok) { - mt->region = pipe->winsys->region_alloc(pipe->winsys, - mt->pitch * mt->cpp * - mt->total_height, flags); - } - - if (!mt->region) { - free(mt); - return NULL; - } - - return mt; -} - - -void -st_miptree_reference(struct pipe_mipmap_tree **dst, - struct pipe_mipmap_tree *src) -{ - src->refcount++; - *dst = src; - DBG("%s %p refcount now %d\n", __FUNCTION__, (void *) src, src->refcount); -} - -void -st_miptree_release(struct pipe_context *pipe, - struct pipe_mipmap_tree **mt) -{ - if (!*mt) - return; - - DBG("%s %p refcount will be %d\n", - __FUNCTION__, (void *) *mt, (*mt)->refcount - 1); - if (--(*mt)->refcount <= 0) { - GLuint i; - - DBG("%s deleting %p\n", __FUNCTION__, (void *) *mt); - - pipe->winsys->region_release(pipe->winsys, &((*mt)->region)); - - for (i = 0; i < MAX_TEXTURE_LEVELS; i++) - if ((*mt)->level[i].image_offset) - free((*mt)->level[i].image_offset); - - free(*mt); - } - *mt = NULL; -} - - - - -/* Can the image be pulled into a unified mipmap tree. This mirrors - * the completeness test in a lot of ways. - * - * Not sure whether I want to pass gl_texture_image here. - */ -GLboolean -st_miptree_match_image(struct pipe_mipmap_tree *mt, - struct gl_texture_image *image, - GLuint face, GLuint level) -{ - /* Images with borders are never pulled into mipmap trees. - */ - if (image->Border) - return GL_FALSE; - - if (image->InternalFormat != mt->internal_format || - image->IsCompressed != mt->compressed) - return GL_FALSE; - - /* Test image dimensions against the base level image adjusted for - * minification. This will also catch images not present in the - * tree, changed targets, etc. - */ - if (image->Width != mt->level[level].width || - image->Height != mt->level[level].height || - image->Depth != mt->level[level].depth) - return GL_FALSE; - - return GL_TRUE; -} - - -/* Although we use the image_offset[] array to store relative offsets - * to cube faces, Mesa doesn't know anything about this and expects - * each cube face to be treated as a separate image. - * - * These functions present that view to mesa: - */ -const GLuint * -st_miptree_depth_offsets(struct pipe_mipmap_tree *mt, GLuint level) -{ - static const GLuint zero = 0; - - if (mt->target != PIPE_TEXTURE_3D || mt->level[level].nr_images == 1) - return &zero; - else - return mt->level[level].image_offset; -} - - -/** - * Return the offset to the given mipmap texture image within the - * texture memory buffer, in bytes. - */ -GLuint -st_miptree_image_offset(const struct pipe_mipmap_tree * mt, - GLuint face, GLuint level) -{ - if (mt->target == PIPE_TEXTURE_CUBE) - return (mt->level[level].level_offset + - mt->level[level].image_offset[face] * mt->cpp); - else - return mt->level[level].level_offset; -} - - -GLuint -st_miptree_texel_offset(const struct pipe_mipmap_tree * mt, - GLuint face, GLuint level, - GLuint col, GLuint row, GLuint img) -{ - GLuint imgOffset = st_miptree_image_offset(mt, face, level); - - return imgOffset + row * (mt->pitch + col) * mt->cpp; -} - - - -/** - * Map a teximage in a mipmap tree. - * \param row_stride returns row stride in bytes - * \param image_stride returns image stride in bytes (for 3D textures). - * \return address of mapping - */ -GLubyte * -st_miptree_image_map(struct pipe_context *pipe, - struct pipe_mipmap_tree * mt, - GLuint face, - GLuint level, - GLuint * row_stride, GLuint * image_offsets) -{ - GLubyte *ptr; - DBG("%s \n", __FUNCTION__); - - if (row_stride) - *row_stride = mt->pitch * mt->cpp; - - if (image_offsets) - memcpy(image_offsets, mt->level[level].image_offset, - mt->level[level].depth * sizeof(GLuint)); - - ptr = pipe->region_map(pipe, mt->region); - - return ptr + st_miptree_image_offset(mt, face, level); -} - -void -st_miptree_image_unmap(struct pipe_context *pipe, - struct pipe_mipmap_tree *mt) -{ - DBG("%s\n", __FUNCTION__); - pipe->region_unmap(pipe, mt->region); -} - - - -/* Upload data for a particular image. - */ -void -st_miptree_image_data(struct pipe_context *pipe, - struct pipe_mipmap_tree *dst, - GLuint face, - GLuint level, - void *src, - GLuint src_row_pitch, GLuint src_image_pitch) -{ - GLuint depth = dst->level[level].depth; - GLuint i; - GLuint height = 0; - const GLubyte *srcUB = src; - struct pipe_surface *dst_surface; - - DBG("%s\n", __FUNCTION__); - for (i = 0; i < depth; i++) { - height = dst->level[level].height; - if(dst->compressed) - height /= 4; - - dst_surface = pipe->get_tex_surface(pipe, dst, face, level, i); - - pipe->surface_data(pipe, dst_surface, - 0, 0, /* dstx, dsty */ - srcUB, - src_row_pitch, - 0, 0, /* source x, y */ - dst->level[level].width, height); /* width, height */ - - pipe_surface_reference(&dst_surface, NULL); - - srcUB += src_image_pitch * dst->cpp; - } -} - -/* Copy mipmap image between trees - */ -void -st_miptree_image_copy(struct pipe_context *pipe, - struct pipe_mipmap_tree *dst, - GLuint face, GLuint level, - struct pipe_mipmap_tree *src) -{ - GLuint width = src->level[level].width; - GLuint height = src->level[level].height; - GLuint depth = src->level[level].depth; - struct pipe_surface *src_surface; - struct pipe_surface *dst_surface; - GLuint i; - - if (dst->compressed) - height /= 4; - for (i = 0; i < depth; i++) { - dst_surface = pipe->get_tex_surface(pipe, dst, face, level, i); - src_surface = pipe->get_tex_surface(pipe, src, face, level, i); - - pipe->surface_copy(pipe, - dst_surface, - 0, 0, /* destX, Y */ - src_surface, - 0, 0, /* srcX, Y */ - width, height); - - pipe_surface_reference(&dst_surface, NULL); - pipe_surface_reference(&src_surface, NULL); - } - -} diff --git a/src/mesa/state_tracker/st_mipmap_tree.h b/src/mesa/state_tracker/st_mipmap_tree.h deleted file mode 100644 index 3e7fd7fa0c..0000000000 --- a/src/mesa/state_tracker/st_mipmap_tree.h +++ /dev/null @@ -1,118 +0,0 @@ -/************************************************************************** - * - * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#ifndef ST_MIPMAP_TREE_H -#define ST_MIPMAP_TREE_H - - -#include "main/mtypes.h" - -struct pipe_context; -struct pipe_mipmap_tree; -struct pipe_region; - - -extern struct pipe_mipmap_tree * -st_miptree_create(struct pipe_context *pipe, - GLenum target, - GLenum internal_format, - GLuint first_level, - GLuint last_level, - GLuint width0, - GLuint height0, - GLuint depth0, - GLuint cpp, - GLuint compress_byte); - -extern void -st_miptree_reference(struct pipe_mipmap_tree **dst, - struct pipe_mipmap_tree *src); - -extern void -st_miptree_release(struct pipe_context *pipe, struct pipe_mipmap_tree **mt); - - -/* Check if an image fits an existing mipmap tree layout - */ -extern GLboolean -st_miptree_match_image(struct pipe_mipmap_tree *mt, - struct gl_texture_image *image, - GLuint face, GLuint level); - -/* Return a pointer to an image within a tree. Return image stride as - * well. - */ -extern GLubyte * -st_miptree_image_map(struct pipe_context *pipe, - struct pipe_mipmap_tree *mt, - GLuint face, GLuint level, - GLuint * row_stride, GLuint * image_stride); - -extern void -st_miptree_image_unmap(struct pipe_context *pipe, - struct pipe_mipmap_tree *mt); - - -/* Return pointers to each 2d slice within an image. Indexed by depth - * value. - */ -extern const GLuint * -st_miptree_depth_offsets(struct pipe_mipmap_tree *mt, GLuint level); - - -/* Return the linear offset of an image relative to the start of the - * tree: - */ -extern GLuint -st_miptree_image_offset(const struct pipe_mipmap_tree *mt, - GLuint face, GLuint level); - -extern GLuint -st_miptree_texel_offset(const struct pipe_mipmap_tree * mt, - GLuint face, GLuint level, - GLuint col, GLuint row, GLuint img); - - -/* Upload an image into a tree - */ -extern void -st_miptree_image_data(struct pipe_context *pipe, - struct pipe_mipmap_tree *dst, - GLuint face, GLuint level, void *src, - GLuint src_row_pitch, GLuint src_image_pitch); - - -/* Copy an image between two trees - */ -extern void -st_miptree_image_copy(struct pipe_context *pipe, - struct pipe_mipmap_tree *dst, - GLuint face, GLuint level, - struct pipe_mipmap_tree *src); - - -#endif diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c new file mode 100644 index 0000000000..a5582c31c0 --- /dev/null +++ b/src/mesa/state_tracker/st_texture.c @@ -0,0 +1,276 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "st_context.h" +#include "st_format.h" +#include "st_texture.h" +#include "enums.h" + +#include "pipe/p_state.h" +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "pipe/p_util.h" +#include "pipe/p_inlines.h" +#include "pipe/p_winsys.h" + + +#define DBG if(0) printf + +#if 0 +static GLenum +target_to_target(GLenum target) +{ + switch (target) { + case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: + case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: + case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: + return GL_TEXTURE_CUBE_MAP_ARB; + default: + return target; + } +} +#endif + +struct pipe_texture * +st_texture_create(struct st_context *st, + unsigned target, + unsigned format, + GLenum internal_format, + GLuint first_level, + GLuint last_level, + GLuint width0, + GLuint height0, + GLuint depth0, + GLuint compress_byte) +{ + struct pipe_texture *pt = CALLOC_STRUCT(pipe_texture); + + assert(target <= PIPE_TEXTURE_CUBE); + + DBG("%s target %s format %s level %d..%d\n", __FUNCTION__, + _mesa_lookup_enum_by_nr(target), + _mesa_lookup_enum_by_nr(internal_format), first_level, last_level); + + if (!pt) + return NULL; + + assert(format); + + pt->target = target; + pt->format = format; + pt->internal_format = internal_format; + pt->first_level = first_level; + pt->last_level = last_level; + pt->width[0] = width0; + pt->height[0] = height0; + pt->depth[0] = depth0; + pt->compressed = compress_byte ? 1 : 0; + pt->cpp = pt->compressed ? compress_byte : st_sizeof_format(format); + pt->refcount = 1; + + st->pipe->texture_create(st->pipe, &pt); + + return pt; +} + + + + +/* Can the image be pulled into a unified mipmap texture. This mirrors + * the completeness test in a lot of ways. + * + * Not sure whether I want to pass gl_texture_image here. + */ +GLboolean +st_texture_match_image(struct pipe_texture *pt, + struct gl_texture_image *image, + GLuint face, GLuint level) +{ + /* Images with borders are never pulled into mipmap textures. + */ + if (image->Border) + return GL_FALSE; + + if (image->InternalFormat != pt->internal_format || + image->IsCompressed != pt->compressed) + return GL_FALSE; + + /* Test image dimensions against the base level image adjusted for + * minification. This will also catch images not present in the + * texture, changed targets, etc. + */ + if (image->Width != pt->width[level] || + image->Height != pt->height[level] || + image->Depth != pt->depth[level]) + return GL_FALSE; + + return GL_TRUE; +} + + +#if 000 +/* Although we use the image_offset[] array to store relative offsets + * to cube faces, Mesa doesn't know anything about this and expects + * each cube face to be treated as a separate image. + * + * These functions present that view to mesa: + */ +const GLuint * +st_texture_depth_offsets(struct pipe_texture *pt, GLuint level) +{ + static const GLuint zero = 0; + + if (pt->target != PIPE_TEXTURE_3D || pt->level[level].nr_images == 1) + return &zero; + else + return pt->level[level].image_offset; +} + + +/** + * Return the offset to the given mipmap texture image within the + * texture memory buffer, in bytes. + */ +GLuint +st_texture_image_offset(const struct pipe_texture * pt, + GLuint face, GLuint level) +{ + if (pt->target == PIPE_TEXTURE_CUBE) + return (pt->level[level].level_offset + + pt->level[level].image_offset[face] * pt->cpp); + else + return pt->level[level].level_offset; +} +#endif + + +/** + * Map a teximage in a mipmap texture. + * \param row_stride returns row stride in bytes + * \param image_stride returns image stride in bytes (for 3D textures). + * \return address of mapping + */ +GLubyte * +st_texture_image_map(struct st_context *st, struct st_texture_image *stImage, + GLuint zoffset) +{ + struct pipe_texture *pt = stImage->pt; + DBG("%s \n", __FUNCTION__); + + stImage->surface = st->pipe->get_tex_surface(st->pipe, pt, stImage->face, + stImage->level, zoffset); + + (void) st->pipe->region_map(st->pipe, stImage->surface->region); + + return stImage->surface->region->map + stImage->surface->offset; +} + +void +st_texture_image_unmap(struct st_context *st, struct st_texture_image *stImage) +{ + DBG("%s\n", __FUNCTION__); + + st->pipe->region_unmap(st->pipe, stImage->surface->region); + + pipe_surface_reference(&stImage->surface, NULL); +} + + + +/* Upload data for a particular image. + */ +void +st_texture_image_data(struct pipe_context *pipe, + struct pipe_texture *dst, + GLuint face, + GLuint level, + void *src, + GLuint src_row_pitch, GLuint src_image_pitch) +{ + GLuint depth = dst->depth[level]; + GLuint i; + GLuint height = 0; + const GLubyte *srcUB = src; + struct pipe_surface *dst_surface; + + DBG("%s\n", __FUNCTION__); + for (i = 0; i < depth; i++) { + height = dst->height[level]; + if(dst->compressed) + height /= 4; + + dst_surface = pipe->get_tex_surface(pipe, dst, face, level, i); + + pipe->surface_data(pipe, dst_surface, + 0, 0, /* dstx, dsty */ + srcUB, + src_row_pitch, + 0, 0, /* source x, y */ + dst->width[level], height); /* width, height */ + + pipe_surface_reference(&dst_surface, NULL); + + srcUB += src_image_pitch * dst->cpp; + } +} + +/* Copy mipmap image between textures + */ +void +st_texture_image_copy(struct pipe_context *pipe, + struct pipe_texture *dst, + GLuint face, GLuint level, + struct pipe_texture *src) +{ + GLuint width = src->width[level]; + GLuint height = src->height[level]; + GLuint depth = src->depth[level]; + struct pipe_surface *src_surface; + struct pipe_surface *dst_surface; + GLuint i; + + if (dst->compressed) + height /= 4; + for (i = 0; i < depth; i++) { + dst_surface = pipe->get_tex_surface(pipe, dst, face, level, i); + src_surface = pipe->get_tex_surface(pipe, src, face, level, i); + + pipe->surface_copy(pipe, + dst_surface, + 0, 0, /* destX, Y */ + src_surface, + 0, 0, /* srcX, Y */ + width, height); + + pipe_surface_reference(&dst_surface, NULL); + pipe_surface_reference(&src_surface, NULL); + } + +} diff --git a/src/mesa/state_tracker/st_texture.h b/src/mesa/state_tracker/st_texture.h new file mode 100644 index 0000000000..b25e3f3f3b --- /dev/null +++ b/src/mesa/state_tracker/st_texture.h @@ -0,0 +1,109 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef ST_TEXTURE_H +#define ST_TEXTURE_H + + +#include "main/mtypes.h" + +struct pipe_context; +struct pipe_texture; +struct pipe_region; + + +extern struct pipe_texture * +st_texture_create(struct st_context *st, + unsigned target, + unsigned format, + GLenum internal_format, + GLuint first_level, + GLuint last_level, + GLuint width0, + GLuint height0, + GLuint depth0, + GLuint compress_byte); + + +/* Check if an image fits an existing texture + */ +extern GLboolean +st_texture_match_image(struct pipe_texture *pt, + struct gl_texture_image *image, + GLuint face, GLuint level); + +/* Return a pointer to an image within a texture. Return image stride as + * well. + */ +extern GLubyte * +st_texture_image_map(struct st_context *st, + struct st_texture_image *stImage, + GLuint zoffset); + +extern void +st_texture_image_unmap(struct st_context *st, + struct st_texture_image *stImage); + + +/* Return pointers to each 2d slice within an image. Indexed by depth + * value. + */ +extern const GLuint * +st_texture_depth_offsets(struct pipe_texture *pt, GLuint level); + + +/* Return the linear offset of an image relative to the start of its region: + */ +extern GLuint +st_texture_image_offset(const struct pipe_texture *pt, + GLuint face, GLuint level); + +extern GLuint +st_texture_texel_offset(const struct pipe_texture * pt, + GLuint face, GLuint level, + GLuint col, GLuint row, GLuint img); + + +/* Upload an image into a texture + */ +extern void +st_texture_image_data(struct pipe_context *pipe, + struct pipe_texture *dst, + GLuint face, GLuint level, void *src, + GLuint src_row_pitch, GLuint src_image_pitch); + + +/* Copy an image between two textures + */ +extern void +st_texture_image_copy(struct pipe_context *pipe, + struct pipe_texture *dst, + GLuint face, GLuint level, + struct pipe_texture *src); + + +#endif -- cgit v1.2.3 From b859cdf6f191b4d8b56537c8dc30082a7e2d94b3 Mon Sep 17 00:00:00 2001 From: Michel Dänzer Date: Fri, 7 Dec 2007 12:30:35 +0100 Subject: Eliminate struct pipe_region. Directly use struct pipe_buffer_handle for storage and struct pipe_surface for (un)mapping. --- .../drivers/dri/intel_winsys/intel_swapbuffers.c | 7 +- .../drivers/dri/intel_winsys/intel_winsys_pipe.c | 51 ++----------- src/mesa/pipe/failover/fo_context.c | 2 - src/mesa/pipe/i915simple/Makefile | 1 - src/mesa/pipe/i915simple/i915_context.c | 1 - src/mesa/pipe/i915simple/i915_context.h | 6 +- src/mesa/pipe/i915simple/i915_regions.c | 78 -------------------- src/mesa/pipe/i915simple/i915_state_emit.c | 6 +- src/mesa/pipe/i915simple/i915_surface.c | 35 ++++----- src/mesa/pipe/i915simple/i915_texture.c | 17 +++-- src/mesa/pipe/p_context.h | 10 +-- src/mesa/pipe/p_inlines.h | 53 +++++++------- src/mesa/pipe/p_state.h | 22 ++---- src/mesa/pipe/softpipe/Makefile | 1 - src/mesa/pipe/softpipe/sp_clear.c | 4 +- src/mesa/pipe/softpipe/sp_context.c | 84 ++++++---------------- src/mesa/pipe/softpipe/sp_draw_arrays.c | 2 - src/mesa/pipe/softpipe/sp_region.c | 79 -------------------- src/mesa/pipe/softpipe/sp_region.h | 40 ----------- src/mesa/pipe/softpipe/sp_state.h | 2 +- src/mesa/pipe/softpipe/sp_state_surface.c | 28 ++++---- src/mesa/pipe/softpipe/sp_surface.c | 61 ++++++++-------- src/mesa/pipe/softpipe/sp_texture.c | 18 +++-- src/mesa/pipe/softpipe/sp_tile_cache.c | 24 ++++++- src/mesa/pipe/softpipe/sp_tile_cache.h | 6 +- src/mesa/pipe/xlib/xm_api.c | 2 +- src/mesa/pipe/xlib/xm_buffer.c | 9 ++- src/mesa/pipe/xlib/xm_surface.c | 8 +-- src/mesa/pipe/xlib/xm_winsys.c | 50 +------------ src/mesa/state_tracker/st_cb_accum.c | 33 ++++----- src/mesa/state_tracker/st_cb_drawpixels.c | 48 ++++++------- src/mesa/state_tracker/st_cb_fbo.c | 28 ++++---- src/mesa/state_tracker/st_cb_readpixels.c | 13 ++-- src/mesa/state_tracker/st_cb_texture.c | 30 ++++---- src/mesa/state_tracker/st_context.c | 2 +- src/mesa/state_tracker/st_context.h | 5 +- src/mesa/state_tracker/st_texture.c | 9 ++- src/mesa/state_tracker/st_texture.h | 3 +- 38 files changed, 275 insertions(+), 603 deletions(-) delete mode 100644 src/mesa/pipe/i915simple/i915_regions.c delete mode 100644 src/mesa/pipe/softpipe/sp_region.c delete mode 100644 src/mesa/pipe/softpipe/sp_region.h (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/drivers/dri/intel_winsys/intel_swapbuffers.c b/src/mesa/drivers/dri/intel_winsys/intel_swapbuffers.c index f96209d1b0..454cd71f6c 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_swapbuffers.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_swapbuffers.c @@ -88,12 +88,11 @@ intelDisplaySurface(__DRIdrawablePrivate *dPriv, const drm_clip_rect_t *pbox = dPriv->pClipRects; const int pitch = intelScreen->front.pitch / intelScreen->front.cpp; const int cpp = intelScreen->front.cpp; - const struct pipe_region *srcRegion = surf->region; const int srcpitch = surf->pitch; int BR13, CMD; int i; - ASSERT(srcRegion); + ASSERT(surf->buffer); ASSERT(surf->cpp == cpp); DBG(SWAP, "screen pitch %d src surface pitch %d\n", @@ -159,7 +158,7 @@ intelDisplaySurface(__DRIdrawablePrivate *dPriv, assert(box.x1 < box.x2); assert(box.y1 < box.y2); - /* XXX this could be done with pipe->region_copy() */ + /* XXX this could be done with pipe->surface_copy() */ BEGIN_BATCH(8, INTEL_BATCH_NO_CLIPRECTS); OUT_BATCH(CMD); OUT_BATCH(BR13); @@ -171,7 +170,7 @@ intelDisplaySurface(__DRIdrawablePrivate *dPriv, DRM_BO_MASK_MEM | DRM_BO_FLAG_WRITE, 0); OUT_BATCH((sbox.y1 << 16) | sbox.x1); OUT_BATCH((srcpitch * cpp) & 0xffff); - OUT_RELOC(dri_bo(srcRegion->buffer), + OUT_RELOC(dri_bo(surf->buffer), DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_READ, DRM_BO_MASK_MEM | DRM_BO_FLAG_READ, 0); diff --git a/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c b/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c index 7b3aa99482..1b71d0ac10 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c @@ -135,13 +135,12 @@ static void intel_buffer_get_subdata(struct pipe_winsys *winsys, * for all buffers. */ static struct pipe_buffer_handle * -intel_buffer_create(struct pipe_winsys *winsys, - unsigned alignment) +intel_buffer_create(struct pipe_winsys *winsys, unsigned flags) { struct _DriBufferObject *buffer; struct intel_pipe_winsys *iws = intel_pipe_winsys(winsys); driGenBuffers( iws->regionPool, - "pipe buffer", 1, &buffer, alignment, 0, 0 ); + "pipe buffer", 1, &buffer, 64, 0, 0 ); return pipe_bo(buffer); } @@ -193,46 +192,6 @@ intel_i915_surface_pitch(struct pipe_winsys *winsys, } -static struct pipe_region * -intel_i915_region_alloc(struct pipe_winsys *winsys, - unsigned size, unsigned flags) -{ - struct pipe_region *region = calloc(sizeof(*region), 1); - const unsigned alignment = 64; - - region->refcount = 1; - - region->buffer = winsys->buffer_create( winsys, alignment ); - - winsys->buffer_data( winsys, - region->buffer, - size, - NULL, - PIPE_BUFFER_USAGE_PIXEL ); - - return region; -} - -static void -intel_i915_region_release(struct pipe_winsys *winsys, - struct pipe_region **region) -{ - if (!*region) - return; - - assert((*region)->refcount > 0); - (*region)->refcount--; - - if ((*region)->refcount == 0) { - assert((*region)->map_refcount == 0); - - winsys->buffer_reference( winsys, &((*region)->buffer), NULL ); - free(*region); - } - *region = NULL; -} - - static struct pipe_surface * intel_i915_surface_alloc(struct pipe_winsys *winsys, unsigned format) { @@ -252,8 +211,8 @@ intel_i915_surface_release(struct pipe_winsys *winsys, struct pipe_surface **s) struct pipe_surface *surf = *s; surf->refcount--; if (surf->refcount == 0) { - if (surf->region) - winsys->region_release(winsys, &surf->region); + if (surf->buffer) + winsys->buffer_reference(winsys, &surf->buffer, NULL); free(surf); } *s = NULL; @@ -300,8 +259,6 @@ intel_create_pipe_winsys( int fd ) iws->winsys.flush_frontbuffer = intel_flush_frontbuffer; iws->winsys.printf = intel_printf; iws->winsys.get_name = intel_get_name; - iws->winsys.region_alloc = intel_i915_region_alloc; - iws->winsys.region_release = intel_i915_region_release; iws->winsys.surface_pitch = intel_i915_surface_pitch; iws->winsys.surface_alloc = intel_i915_surface_alloc; iws->winsys.surface_release = intel_i915_surface_release; diff --git a/src/mesa/pipe/failover/fo_context.c b/src/mesa/pipe/failover/fo_context.c index a25563d451..a1291f583b 100644 --- a/src/mesa/pipe/failover/fo_context.c +++ b/src/mesa/pipe/failover/fo_context.c @@ -140,8 +140,6 @@ struct pipe_context *failover_create( struct pipe_context *hw, #endif failover->pipe.get_tex_surface = hw->get_tex_surface; - failover->pipe.region_map = hw->region_map; - failover->pipe.region_unmap = hw->region_unmap; failover->pipe.surface_data = hw->surface_data; failover->pipe.surface_copy = hw->surface_copy; failover->pipe.surface_fill = hw->surface_fill; diff --git a/src/mesa/pipe/i915simple/Makefile b/src/mesa/pipe/i915simple/Makefile index 1223b386a3..2f91de3afc 100644 --- a/src/mesa/pipe/i915simple/Makefile +++ b/src/mesa/pipe/i915simple/Makefile @@ -12,7 +12,6 @@ DRIVER_SOURCES = \ i915_context.c \ i915_debug.c \ i915_debug_fp.c \ - i915_regions.c \ i915_state.c \ i915_state_immediate.c \ i915_state_dynamic.c \ diff --git a/src/mesa/pipe/i915simple/i915_context.c b/src/mesa/pipe/i915simple/i915_context.c index 94649231cf..07b331c528 100644 --- a/src/mesa/pipe/i915simple/i915_context.c +++ b/src/mesa/pipe/i915simple/i915_context.c @@ -348,7 +348,6 @@ struct pipe_context *i915_create( struct pipe_winsys *pipe_winsys, draw_set_rasterize_stage(i915->draw, i915_draw_render_stage(i915)); } - i915_init_region_functions(i915); i915_init_surface_functions(i915); i915_init_state_functions(i915); i915_init_flush_functions(i915); diff --git a/src/mesa/pipe/i915simple/i915_context.h b/src/mesa/pipe/i915simple/i915_context.h index 8ed3465be2..dbf0c885cc 100644 --- a/src/mesa/pipe/i915simple/i915_context.h +++ b/src/mesa/pipe/i915simple/i915_context.h @@ -175,7 +175,7 @@ struct i915_texture { /* The data is held here: */ - struct pipe_region *region; + struct pipe_buffer_handle *buffer; }; struct i915_context @@ -289,10 +289,10 @@ void i915_clear(struct pipe_context *pipe, struct pipe_surface *ps, /*********************************************************************** - * i915_region.c: + * i915_surface.c: */ -void i915_init_region_functions( struct i915_context *i915 ); void i915_init_surface_functions( struct i915_context *i915 ); + void i915_init_state_functions( struct i915_context *i915 ); void i915_init_flush_functions( struct i915_context *i915 ); void i915_init_string_functions( struct i915_context *i915 ); diff --git a/src/mesa/pipe/i915simple/i915_regions.c b/src/mesa/pipe/i915simple/i915_regions.c deleted file mode 100644 index 82fdec83d0..0000000000 --- a/src/mesa/pipe/i915simple/i915_regions.c +++ /dev/null @@ -1,78 +0,0 @@ -/************************************************************************** - * - * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -/* Provide additional functionality on top of bufmgr buffers: - * - 2d semantics and blit operations (XXX: remove/simplify blits??) - * - refcounting of buffers for multiple images in a buffer. - * - refcounting of buffer mappings. - */ - -#include "pipe/p_defines.h" -#include "pipe/p_winsys.h" -#include "i915_context.h" - - - - -static ubyte * -i915_region_map(struct pipe_context *pipe, struct pipe_region *region) -{ - struct i915_context *i915 = i915_context( pipe ); - - if (!region->map_refcount++) { - region->map = i915->pipe.winsys->buffer_map( i915->pipe.winsys, - region->buffer, - PIPE_BUFFER_FLAG_WRITE | - PIPE_BUFFER_FLAG_READ); - } - - return region->map; -} - -static void -i915_region_unmap(struct pipe_context *pipe, struct pipe_region *region) -{ - struct i915_context *i915 = i915_context( pipe ); - - if (region->map_refcount > 0) { - assert(region->map); - if (!--region->map_refcount) { - i915->pipe.winsys->buffer_unmap( i915->pipe.winsys, - region->buffer ); - region->map = NULL; - } - } -} - - -void -i915_init_region_functions(struct i915_context *i915) -{ - i915->pipe.region_map = i915_region_map; - i915->pipe.region_unmap = i915_region_unmap; -} - diff --git a/src/mesa/pipe/i915simple/i915_state_emit.c b/src/mesa/pipe/i915simple/i915_state_emit.c index 900a91d896..eda40d7c76 100644 --- a/src/mesa/pipe/i915simple/i915_state_emit.c +++ b/src/mesa/pipe/i915simple/i915_state_emit.c @@ -220,7 +220,7 @@ i915_emit_hardware_state(struct i915_context *i915 ) BUF_3D_PITCH(pitch) | /* pitch in bytes */ BUF_3D_USE_FENCE); - OUT_RELOC(cbuf_surface->region->buffer, + OUT_RELOC(cbuf_surface->buffer, I915_BUFFER_ACCESS_WRITE, 0); } @@ -236,7 +236,7 @@ i915_emit_hardware_state(struct i915_context *i915 ) BUF_3D_PITCH(zpitch) | /* pitch in bytes */ BUF_3D_USE_FENCE); - OUT_RELOC(depth_surface->region->buffer, + OUT_RELOC(depth_surface->buffer, I915_BUFFER_ACCESS_WRITE, 0); } @@ -284,7 +284,7 @@ i915_emit_hardware_state(struct i915_context *i915 ) for (unit = 0; unit < I915_TEX_UNITS; unit++) { if (enabled & (1 << unit)) { struct pipe_buffer_handle *buf = - i915->texture[unit]->region->buffer; + i915->texture[unit]->buffer; uint offset = 0; assert(buf); diff --git a/src/mesa/pipe/i915simple/i915_surface.c b/src/mesa/pipe/i915simple/i915_surface.c index 385202507d..ecbabe50eb 100644 --- a/src/mesa/pipe/i915simple/i915_surface.c +++ b/src/mesa/pipe/i915simple/i915_surface.c @@ -29,6 +29,7 @@ #include "i915_blit.h" #include "i915_state.h" #include "pipe/p_defines.h" +#include "pipe/p_inlines.h" #include "pipe/p_util.h" #include "pipe/p_inlines.h" #include "pipe/p_winsys.h" @@ -57,7 +58,7 @@ i915_get_tile_rgba(struct pipe_context *pipe, uint x, uint y, uint w, uint h, float *p) { const unsigned *src - = ((const unsigned *) (ps->region->map + ps->offset)) + = ((const unsigned *) (ps->map)) + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -129,7 +130,7 @@ i915_get_tile(struct pipe_context *pipe, ubyte *pDest; uint i; - assert(ps->region->map); + assert(ps->map); CLIP_TILE; @@ -137,7 +138,7 @@ i915_get_tile(struct pipe_context *pipe, dst_stride = w0 * cpp; } - pSrc = ps->region->map + ps->offset + (y * ps->pitch + x) * cpp; + pSrc = ps->map + (y * ps->pitch + x) * cpp; pDest = (ubyte *) p; for (i = 0; i < h; i++) { @@ -163,7 +164,7 @@ i915_put_tile(struct pipe_context *pipe, ubyte *pDest; uint i; - assert(ps->region->map); + assert(ps->map); CLIP_TILE; @@ -172,7 +173,7 @@ i915_put_tile(struct pipe_context *pipe, } pSrc = (const ubyte *) p; - pDest = ps->region->map + ps->offset + (y * ps->pitch + x) * cpp; + pDest = ps->map + (y * ps->pitch + x) * cpp; for (i = 0; i < h; i++) { memcpy(pDest, pSrc, w0 * cpp); @@ -211,7 +212,7 @@ i915_get_tex_surface(struct pipe_context *pipe, if (ps) { assert(ps->format); assert(ps->refcount); - pipe_region_reference(&ps->region, tex->region); + pipe->winsys->buffer_reference(pipe->winsys, &ps->buffer, tex->buffer); ps->cpp = pt->cpp; ps->width = pt->width[level]; ps->height = pt->height[level]; @@ -274,12 +275,12 @@ i915_surface_data(struct pipe_context *pipe, const void *src, unsigned src_pitch, unsigned srcx, unsigned srcy, unsigned width, unsigned height) { - _mesa_copy_rect(pipe->region_map(pipe, dst->region) + dst->offset, + _mesa_copy_rect(pipe_surface_map(dst), dst->cpp, dst->pitch, dstx, dsty, width, height, src, src_pitch, srcx, srcy); - pipe->region_unmap(pipe, dst->region); + pipe_surface_unmap(dst); } @@ -297,23 +298,23 @@ i915_surface_copy(struct pipe_context *pipe, assert( dst->cpp == src->cpp ); if (0) { - _mesa_copy_rect(pipe->region_map(pipe, dst->region) + dst->offset, + _mesa_copy_rect(pipe_surface_map(dst), dst->cpp, dst->pitch, dstx, dsty, width, height, - pipe->region_map(pipe, src->region) + src->offset, + pipe_surface_map(src), src->pitch, srcx, srcy); - pipe->region_unmap(pipe, src->region); - pipe->region_unmap(pipe, dst->region); + pipe_surface_unmap(src); + pipe_surface_unmap(dst); } else { i915_copy_blit( i915_context(pipe), dst->cpp, - (short) src->pitch, src->region->buffer, src->offset, - (short) dst->pitch, dst->region->buffer, dst->offset, + (short) src->pitch, src->buffer, src->offset, + (short) dst->pitch, dst->buffer, dst->offset, (short) srcx, (short) srcy, (short) dstx, (short) dsty, (short) width, (short) height ); } } @@ -324,7 +325,7 @@ i915_surface_copy(struct pipe_context *pipe, static ubyte * get_pointer(struct pipe_surface *dst, unsigned x, unsigned y) { - return dst->region->map + (y * dst->pitch + x) * dst->cpp; + return dst->map + (y * dst->pitch + x) * dst->cpp; } @@ -337,7 +338,7 @@ i915_surface_fill(struct pipe_context *pipe, if (0) { unsigned i, j; - (void)pipe->region_map(pipe, dst->region); + (void)pipe_surface_map(dst); switch (dst->cpp) { case 1: { @@ -375,7 +376,7 @@ i915_surface_fill(struct pipe_context *pipe, i915_fill_blit( i915_context(pipe), dst->cpp, (short) dst->pitch, - dst->region->buffer, dst->offset, + dst->buffer, dst->offset, (short) dstx, (short) dsty, (short) width, (short) height, value ); diff --git a/src/mesa/pipe/i915simple/i915_texture.c b/src/mesa/pipe/i915simple/i915_texture.c index 3bfa806d9e..1ca2815dfb 100644 --- a/src/mesa/pipe/i915simple/i915_texture.c +++ b/src/mesa/pipe/i915simple/i915_texture.c @@ -33,6 +33,7 @@ #include "pipe/p_state.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "pipe/p_inlines.h" #include "pipe/p_util.h" #include "pipe/p_winsys.h" @@ -494,13 +495,17 @@ i915_texture_create(struct pipe_context *pipe, struct pipe_texture **pt) if (i915->flags.is_i945 ? i945_miptree_layout(pipe, tex) : i915_miptree_layout(pipe, tex)) { - tex->region = pipe->winsys->region_alloc(pipe->winsys, - tex->pitch * tex->base.cpp * - tex->total_height, - PIPE_SURFACE_FLAG_TEXTURE); + tex->buffer = pipe->winsys->buffer_create(pipe->winsys, + PIPE_SURFACE_FLAG_TEXTURE); + + if (tex->buffer) + pipe->winsys->buffer_data(pipe->winsys, tex->buffer, + tex->pitch * tex->base.cpp * + tex->total_height, NULL, + PIPE_BUFFER_USAGE_PIXEL); } - if (!tex->region) { + if (!tex->buffer) { FREE(tex); tex = NULL; } @@ -527,7 +532,7 @@ i915_texture_release(struct pipe_context *pipe, struct pipe_texture **pt) DBG("%s deleting %p\n", __FUNCTION__, (void *) tex); */ - pipe->winsys->region_release(pipe->winsys, &tex->region); + pipe->winsys->buffer_reference(pipe->winsys, &tex->buffer, NULL); for (i = 0; i < PIPE_MAX_TEXTURE_LEVELS; i++) if (tex->image_offset[i]) diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 5033209323..2420d02213 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -37,7 +37,7 @@ struct pipe_state_cache; * Gallium rendering context. Basically: * - state setting functions * - VBO drawing functions - * - memory region function + * - surface functions * - device queries */ struct pipe_context { @@ -201,14 +201,6 @@ struct pipe_context { uint x, uint y, uint w, uint h, const float *p); - /* - * Memory region functions - */ - ubyte *(*region_map)(struct pipe_context *pipe, struct pipe_region *r); - - void (*region_unmap)(struct pipe_context *pipe, struct pipe_region *r); - - /* * Surface functions */ diff --git a/src/mesa/pipe/p_inlines.h b/src/mesa/pipe/p_inlines.h index c04d46dddd..1697284b04 100644 --- a/src/mesa/pipe/p_inlines.h +++ b/src/mesa/pipe/p_inlines.h @@ -29,40 +29,42 @@ #define P_INLINES_H #include "p_context.h" +#include "p_defines.h" #include "p_winsys.h" -/** - * Set 'ptr' to point to 'region' and update reference counting. - * The old thing pointed to, if any, will be unreferenced first. - * 'region' may be NULL. - */ +static INLINE ubyte * +pipe_surface_map(struct pipe_surface *surface) +{ + if (!surface->map_refcount++) { + surface->map = surface->winsys->buffer_map( surface->winsys, + surface->buffer, + PIPE_BUFFER_FLAG_WRITE | + PIPE_BUFFER_FLAG_READ ) + + surface->offset; + } + + return surface->map; +} + static INLINE void -pipe_region_reference(struct pipe_region **ptr, struct pipe_region *region) +pipe_surface_unmap(struct pipe_surface *surface) { - assert(ptr); - if (*ptr) { - /* unreference the old thing */ - struct pipe_region *oldReg = *ptr; - assert(oldReg->refcount > 0); - oldReg->refcount--; - if (oldReg->refcount == 0) { - /* free the old region */ - assert(oldReg->map_refcount == 0); - /* XXX dereference the region->buffer */ - FREE( oldReg ); + if (surface->map_refcount > 0) { + assert(surface->map); + if (!--surface->map_refcount) { + surface->winsys->buffer_unmap( surface->winsys, + surface->buffer ); + surface->map = NULL; } - *ptr = NULL; - } - if (region) { - /* reference the new thing */ - region->refcount++; - *ptr = region; } } + /** - * \sa pipe_region_reference + * Set 'ptr' to point to 'surf' and update reference counting. + * The old thing pointed to, if any, will be unreferenced first. + * 'surf' may be NULL. */ static INLINE void pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf) @@ -82,7 +84,7 @@ pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf) /** - * \sa pipe_region_reference + * \sa pipe_surface_reference */ static INLINE void pipe_texture_reference(struct pipe_context *pipe, struct pipe_texture **ptr, @@ -100,4 +102,5 @@ pipe_texture_reference(struct pipe_context *pipe, struct pipe_texture **ptr, } } + #endif /* P_INLINES_H */ diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index 077a8f5a06..44dec9b773 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -256,32 +256,20 @@ struct pipe_sampler_state }; -/*** - *** Resource Objects - ***/ - -struct pipe_region -{ - struct pipe_buffer_handle *buffer; /**< driver private buffer handle */ - - unsigned refcount; /**< Reference count for region */ - ubyte *map; /**< only non-NULL when region is actually mapped */ - unsigned map_refcount; /**< Reference count for mapping */ -}; - - /** - * 2D surface. This is basically a view into a pipe_region (memory buffer). + * 2D surface. This is basically a view into a memory buffer. * May be a renderbuffer, texture mipmap level, etc. */ struct pipe_surface { - struct pipe_region *region; + struct pipe_buffer_handle *buffer; /**< driver private buffer handle */ + ubyte *map; /**< only non-NULL when surface is actually mapped */ + unsigned map_refcount; /**< Reference count for mapping */ unsigned format; /**< PIPE_FORMAT_x */ unsigned cpp; /**< bytes per pixel */ unsigned width, height; unsigned pitch; /**< in pixels */ - unsigned offset; /**< offset from start of region, in bytes */ + unsigned offset; /**< offset from start of buffer, in bytes */ unsigned refcount; struct pipe_winsys *winsys; /**< winsys which owns/created the surface */ }; diff --git a/src/mesa/pipe/softpipe/Makefile b/src/mesa/pipe/softpipe/Makefile index 9978884c9b..647cc05373 100644 --- a/src/mesa/pipe/softpipe/Makefile +++ b/src/mesa/pipe/softpipe/Makefile @@ -24,7 +24,6 @@ DRIVER_SOURCES = \ sp_quad_output.c \ sp_quad_stencil.c \ sp_quad_stipple.c \ - sp_region.c \ sp_state_blend.c \ sp_state_clip.c \ sp_state_derived.c \ diff --git a/src/mesa/pipe/softpipe/sp_clear.c b/src/mesa/pipe/softpipe/sp_clear.c index a4276362b9..496b38fd5f 100644 --- a/src/mesa/pipe/softpipe/sp_clear.c +++ b/src/mesa/pipe/softpipe/sp_clear.c @@ -50,12 +50,12 @@ softpipe_clear(struct pipe_context *pipe, struct pipe_surface *ps, softpipe_update_derived(softpipe); /* not needed?? */ - if (ps == sp_tile_cache_get_surface(softpipe->zbuf_cache)) { + if (ps == sp_tile_cache_get_surface(softpipe, softpipe->zbuf_cache)) { float clear[4]; clear[0] = 1.0; /* XXX hack */ sp_tile_cache_clear(softpipe->zbuf_cache, clear); } - else if (ps == sp_tile_cache_get_surface(softpipe->cbuf_cache[0])) { + else if (ps == sp_tile_cache_get_surface(softpipe, softpipe->cbuf_cache[0])) { float clear[4]; clear[0] = 0.2f; /* XXX hack */ clear[1] = 0.2f; /* XXX hack */ diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index 7a9fccce9a..f7f0316cf2 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -31,12 +31,12 @@ #include "pipe/draw/draw_context.h" #include "pipe/p_defines.h" +#include "pipe/p_inlines.h" #include "pipe/p_util.h" #include "sp_clear.h" #include "sp_context.h" #include "sp_flush.h" #include "sp_prim_setup.h" -#include "sp_region.h" #include "sp_state.h" #include "sp_surface.h" #include "sp_tile_cache.h" @@ -65,44 +65,22 @@ softpipe_is_format_supported( struct pipe_context *pipe, uint format ) void softpipe_map_surfaces(struct softpipe_context *sp) { - struct pipe_context *pipe = &sp->pipe; + struct pipe_surface *ps; unsigned i; for (i = 0; i < sp->framebuffer.num_cbufs; i++) { - struct pipe_surface *ps = sp->framebuffer.cbufs[i]; - if (ps->region && !ps->region->map) { - pipe->region_map(pipe, ps->region); - } + ps = sp->framebuffer.cbufs[i]; + if (ps->buffer) + pipe_surface_map(ps); } - if (sp->framebuffer.zbuf) { - struct pipe_surface *ps = sp->framebuffer.zbuf; - if (ps->region && !ps->region->map) { - pipe->region_map(pipe, ps->region); - } - } - - if (sp->framebuffer.sbuf) { - struct pipe_surface *ps = sp->framebuffer.sbuf; - if (ps->region && !ps->region->map) { - pipe->region_map(pipe, ps->region); - } - } -} - + ps = sp->framebuffer.zbuf; + if (ps && ps->buffer) + pipe_surface_map(ps); -void -softpipe_map_texture_surfaces(struct softpipe_context *sp) -{ - struct pipe_context *pipe = &sp->pipe; - uint i; - - for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { - struct softpipe_texture *spt = sp->texture[i]; - if (spt) { - pipe->region_map(pipe, spt->region); - } - } + ps = sp->framebuffer.sbuf; + if (ps && ps->buffer) + pipe_surface_map(ps); } @@ -112,7 +90,7 @@ softpipe_map_texture_surfaces(struct softpipe_context *sp) void softpipe_unmap_surfaces(struct softpipe_context *sp) { - struct pipe_context *pipe = &sp->pipe; + struct pipe_surface *ps; uint i; for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) @@ -121,36 +99,18 @@ softpipe_unmap_surfaces(struct softpipe_context *sp) sp_flush_tile_cache(sp, sp->sbuf_cache); for (i = 0; i < sp->framebuffer.num_cbufs; i++) { - struct pipe_surface *ps = sp->framebuffer.cbufs[i]; - if (ps->region) - pipe->region_unmap(pipe, ps->region); + ps = sp->framebuffer.cbufs[i]; + if (ps->map) + pipe_surface_unmap(ps); } - if (sp->framebuffer.zbuf) { - struct pipe_surface *ps = sp->framebuffer.zbuf; - if (ps->region) - pipe->region_unmap(pipe, ps->region); - } - - if (sp->framebuffer.sbuf && sp->framebuffer.sbuf != sp->framebuffer.zbuf) { - struct pipe_surface *ps = sp->framebuffer.sbuf; - if (ps->region) - pipe->region_unmap(pipe, ps->region); - } -} - + ps = sp->framebuffer.zbuf; + if (ps && ps->map) + pipe_surface_unmap(ps); -void -softpipe_unmap_texture_surfaces(struct softpipe_context *sp) -{ - struct pipe_context *pipe = &sp->pipe; - uint i; - for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { - struct softpipe_texture *spt = sp->texture[i]; - if (spt) { - pipe->region_unmap(pipe, spt->region); - } - } + ps = sp->framebuffer.sbuf; + if (ps && ps->map) + pipe_surface_unmap(ps); } @@ -403,8 +363,6 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys, draw_set_rasterize_stage(softpipe->draw, softpipe->setup); } - - sp_init_region_functions(softpipe); sp_init_surface_functions(softpipe); return &softpipe->pipe; diff --git a/src/mesa/pipe/softpipe/sp_draw_arrays.c b/src/mesa/pipe/softpipe/sp_draw_arrays.c index 8a82cdfe1a..93eb68405d 100644 --- a/src/mesa/pipe/softpipe/sp_draw_arrays.c +++ b/src/mesa/pipe/softpipe/sp_draw_arrays.c @@ -112,7 +112,6 @@ softpipe_draw_elements(struct pipe_context *pipe, softpipe_update_derived( sp ); softpipe_map_surfaces(sp); - softpipe_map_texture_surfaces(sp); softpipe_map_constant_buffers(sp); /* @@ -184,7 +183,6 @@ softpipe_draw_elements(struct pipe_context *pipe, /* Note: leave drawing surfaces mapped */ - softpipe_unmap_texture_surfaces(sp); softpipe_unmap_constant_buffers(sp); return TRUE; diff --git a/src/mesa/pipe/softpipe/sp_region.c b/src/mesa/pipe/softpipe/sp_region.c deleted file mode 100644 index 58dc6bb96e..0000000000 --- a/src/mesa/pipe/softpipe/sp_region.c +++ /dev/null @@ -1,79 +0,0 @@ -/************************************************************************** - * - * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -/* Provide additional functionality on top of bufmgr buffers: - * - 2d semantics and blit operations (XXX: remove/simplify blits??) - * - refcounting of buffers for multiple images in a buffer. - * - refcounting of buffer mappings. - */ - -#include "sp_context.h" -#include "sp_region.h" -#include "pipe/p_util.h" -#include "pipe/p_winsys.h" -#include "pipe/p_defines.h" - - - -static ubyte * -sp_region_map(struct pipe_context *pipe, struct pipe_region *region) -{ - struct softpipe_context *sp = softpipe_context( pipe ); - - if (!region->map_refcount++) { - region->map = sp->pipe.winsys->buffer_map( sp->pipe.winsys, - region->buffer, - PIPE_BUFFER_FLAG_WRITE | - PIPE_BUFFER_FLAG_READ); - } - - return region->map; -} - -static void -sp_region_unmap(struct pipe_context *pipe, struct pipe_region *region) -{ - struct softpipe_context *sp = softpipe_context( pipe ); - - if (region->map_refcount > 0) { - assert(region->map); - if (!--region->map_refcount) { - sp->pipe.winsys->buffer_unmap( sp->pipe.winsys, - region->buffer ); - region->map = NULL; - } - } -} - - -void -sp_init_region_functions(struct softpipe_context *sp) -{ - sp->pipe.region_map = sp_region_map; - sp->pipe.region_unmap = sp_region_unmap; -} - diff --git a/src/mesa/pipe/softpipe/sp_region.h b/src/mesa/pipe/softpipe/sp_region.h deleted file mode 100644 index 432746b27f..0000000000 --- a/src/mesa/pipe/softpipe/sp_region.h +++ /dev/null @@ -1,40 +0,0 @@ -/************************************************************************** - * - * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - - -#ifndef SP_REGION_H -#define SP_REGION_H - - -struct softpipe_context; - - -extern void -sp_init_region_functions(struct softpipe_context *sp); - - -#endif /* SP_REGION_H */ diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index a543735b52..daf9955ca5 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -78,7 +78,7 @@ struct softpipe_texture /* The data is held here: */ - struct pipe_region *region; + struct pipe_buffer_handle *buffer; }; void * diff --git a/src/mesa/pipe/softpipe/sp_state_surface.c b/src/mesa/pipe/softpipe/sp_state_surface.c index d4e0bd1e15..9470ef485f 100644 --- a/src/mesa/pipe/softpipe/sp_state_surface.c +++ b/src/mesa/pipe/softpipe/sp_state_surface.c @@ -27,6 +27,8 @@ /* Authors: Keith Whitwell */ +#include "p_inlines.h" + #include "sp_context.h" #include "sp_state.h" #include "sp_surface.h" @@ -54,17 +56,17 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe, sp_flush_tile_cache(sp, sp->cbuf_cache[i]); /* unmap old */ ps = sp->framebuffer.cbufs[i]; - if (ps && ps->region) - pipe->region_unmap(pipe, ps->region); + if (ps && ps->map) + pipe_surface_unmap(ps); /* map new */ ps = fb->cbufs[i]; if (ps) - pipe->region_map(pipe, ps->region); + pipe_surface_map(ps); /* assign new */ sp->framebuffer.cbufs[i] = fb->cbufs[i]; /* update cache */ - sp_tile_cache_set_surface(sp->cbuf_cache[i], ps); + sp_tile_cache_set_surface(sp, sp->cbuf_cache[i], ps); } } @@ -76,8 +78,8 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe, sp_flush_tile_cache(sp, sp->zbuf_cache); /* unmap old */ ps = sp->framebuffer.zbuf; - if (ps && ps->region) - pipe->region_unmap(pipe, ps->region); + if (ps && ps->map) + pipe_surface_unmap(ps); if (sp->framebuffer.sbuf == sp->framebuffer.zbuf) { /* combined z/stencil */ sp->framebuffer.sbuf = NULL; @@ -85,12 +87,12 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe, /* map new */ ps = fb->zbuf; if (ps) - pipe->region_map(pipe, ps->region); + pipe_surface_map(ps); /* assign new */ sp->framebuffer.zbuf = fb->zbuf; /* update cache */ - sp_tile_cache_set_surface(sp->zbuf_cache, ps); + sp_tile_cache_set_surface(sp, sp->zbuf_cache, ps); } /* XXX combined depth/stencil here */ @@ -101,12 +103,12 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe, sp_flush_tile_cache(sp, sp->sbuf_cache_sep); /* unmap old */ ps = sp->framebuffer.sbuf; - if (ps && ps->region) - pipe->region_unmap(pipe, ps->region); + if (ps && ps->map) + pipe_surface_unmap(ps); /* map new */ ps = fb->sbuf; if (ps && fb->sbuf != fb->zbuf) - pipe->region_map(pipe, ps->region); + pipe_surface_map(ps); /* assign new */ sp->framebuffer.sbuf = fb->sbuf; @@ -114,12 +116,12 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe, if (fb->sbuf != fb->zbuf) { /* separate stencil buf */ sp->sbuf_cache = sp->sbuf_cache_sep; - sp_tile_cache_set_surface(sp->sbuf_cache, ps); + sp_tile_cache_set_surface(sp, sp->sbuf_cache, ps); } else { /* combined depth/stencil */ sp->sbuf_cache = sp->zbuf_cache; - sp_tile_cache_set_surface(sp->sbuf_cache, ps); + sp_tile_cache_set_surface(sp, sp->sbuf_cache, ps); } } diff --git a/src/mesa/pipe/softpipe/sp_surface.c b/src/mesa/pipe/softpipe/sp_surface.c index c41bbc59b9..c61e0842fc 100644 --- a/src/mesa/pipe/softpipe/sp_surface.c +++ b/src/mesa/pipe/softpipe/sp_surface.c @@ -76,7 +76,7 @@ a8r8g8b8_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const unsigned *src - = ((const unsigned *) (ps->region->map + ps->offset)) + = ((const unsigned *) (ps->map)) + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -107,7 +107,7 @@ a8r8g8b8_put_tile(struct pipe_surface *ps, const float *p) { unsigned *dst - = ((unsigned *) (ps->region->map + ps->offset)) + = ((unsigned *) (ps->map)) + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -140,7 +140,7 @@ b8g8r8a8_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const unsigned *src - = ((const unsigned *) (ps->region->map + ps->offset)) + = ((const unsigned *) (ps->map)) + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -171,7 +171,7 @@ b8g8r8a8_put_tile(struct pipe_surface *ps, const float *p) { unsigned *dst - = ((unsigned *) (ps->region->map + ps->offset)) + = ((unsigned *) (ps->map)) + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -204,7 +204,7 @@ a1r5g5b5_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const ushort *src - = ((const ushort *) (ps->region->map + ps->offset)) + = ((const ushort *) (ps->map)) + y * ps->pitch + x; unsigned i, j; @@ -235,7 +235,7 @@ z16_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const ushort *src - = ((const ushort *) (ps->region->map + ps->offset)) + = ((const ushort *) (ps->map)) + y * ps->pitch + x; const float scale = 1.0f / 65535.0f; unsigned i, j; @@ -268,7 +268,7 @@ l8_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const ubyte *src - = ((const ubyte *) (ps->region->map + ps->offset)) + = ((const ubyte *) (ps->map)) + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -299,7 +299,7 @@ a8_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const ubyte *src - = ((const ubyte *) (ps->region->map + ps->offset)) + = ((const ubyte *) (ps->map)) + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -330,7 +330,7 @@ r16g16b16a16_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const short *src - = ((const short *) (ps->region->map + ps->offset)) + = ((const short *) (ps->map)) + (y * ps->pitch + x) * 4; unsigned i, j; unsigned w0 = w; @@ -362,7 +362,7 @@ r16g16b16a16_put_tile(struct pipe_surface *ps, const float *p) { short *dst - = ((short *) (ps->region->map + ps->offset)) + = ((short *) (ps->map)) + (y * ps->pitch + x) * 4; unsigned i, j; unsigned w0 = w; @@ -399,7 +399,7 @@ i8_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const ubyte *src - = ((const ubyte *) (ps->region->map + ps->offset)) + = ((const ubyte *) (ps->map)) + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -430,7 +430,7 @@ a8_l8_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const ushort *src - = ((const ushort *) (ps->region->map + ps->offset)) + = ((const ushort *) (ps->map)) + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -467,7 +467,7 @@ z32_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const uint *src - = ((const uint *) (ps->region->map + ps->offset)) + = ((const uint *) (ps->map)) + y * ps->pitch + x; const double scale = 1.0 / (double) 0xffffffff; unsigned i, j; @@ -501,7 +501,7 @@ s8z24_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const uint *src - = ((const uint *) (ps->region->map + ps->offset)) + = ((const uint *) (ps->map)) + y * ps->pitch + x; const double scale = 1.0 / ((1 << 24) - 1); unsigned i, j; @@ -535,7 +535,7 @@ z24s8_get_tile(struct pipe_surface *ps, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const uint *src - = ((const uint *) (ps->region->map + ps->offset)) + = ((const uint *) (ps->map)) + y * ps->pitch + x; const double scale = 1.0 / ((1 << 24) - 1); unsigned i, j; @@ -589,7 +589,7 @@ softpipe_get_tex_surface(struct pipe_context *pipe, if (ps) { assert(ps->format); assert(ps->refcount); - pipe_region_reference(&ps->region, spt->region); + pipe->winsys->buffer_reference(pipe->winsys, &ps->buffer, spt->buffer); ps->cpp = pt->cpp; ps->width = pt->width[level]; ps->height = pt->height[level]; @@ -613,7 +613,7 @@ softpipe_get_tile(struct pipe_context *pipe, struct pipe_surface *ps, ubyte *pDest; uint i; - assert(ps->region->map); + assert(ps->map); if (dst_stride == 0) { dst_stride = w * cpp; @@ -621,7 +621,7 @@ softpipe_get_tile(struct pipe_context *pipe, struct pipe_surface *ps, CLIP_TILE; - pSrc = ps->region->map + ps->offset + (y * ps->pitch + x) * cpp; + pSrc = ps->map + (y * ps->pitch + x) * cpp; pDest = (ubyte *) p; for (i = 0; i < h; i++) { @@ -645,7 +645,7 @@ softpipe_put_tile(struct pipe_context *pipe, struct pipe_surface *ps, ubyte *pDest; uint i; - assert(ps->region->map); + assert(ps->map); if (src_stride == 0) { src_stride = w * cpp; @@ -654,7 +654,7 @@ softpipe_put_tile(struct pipe_context *pipe, struct pipe_surface *ps, CLIP_TILE; pSrc = (const ubyte *) p; - pDest = ps->region->map + ps->offset + (y * ps->pitch + x) * cpp; + pDest = ps->map + (y * ps->pitch + x) * cpp; for (i = 0; i < h; i++) { memcpy(pDest, pSrc, w * cpp); @@ -817,12 +817,12 @@ sp_surface_data(struct pipe_context *pipe, const void *src, unsigned src_pitch, unsigned srcx, unsigned srcy, unsigned width, unsigned height) { - copy_rect(pipe->region_map(pipe, dst->region) + dst->offset, + copy_rect(pipe_surface_map(dst), dst->cpp, dst->pitch, dstx, dsty, width, height, src, src_pitch, srcx, srcy); - pipe->region_unmap(pipe, dst->region); + pipe_surface_unmap(dst); } /* Assumes all values are within bounds -- no checking at this level - @@ -835,29 +835,26 @@ sp_surface_copy(struct pipe_context *pipe, struct pipe_surface *src, unsigned srcx, unsigned srcy, unsigned width, unsigned height) { - ubyte *src_map, *dst_map; assert( dst->cpp == src->cpp ); - dst_map = pipe->region_map(pipe, dst->region); - src_map = pipe->region_map(pipe, src->region); - copy_rect(dst_map + dst->offset, + copy_rect(pipe_surface_map(dst), dst->cpp, dst->pitch, dstx, dsty, width, height, - src_map + src->offset, + pipe_surface_map(src), src->pitch, srcx, srcy); - pipe->region_unmap(pipe, src->region); - pipe->region_unmap(pipe, dst->region); + pipe_surface_unmap(src); + pipe_surface_unmap(dst); } static ubyte * get_pointer(struct pipe_surface *dst, unsigned x, unsigned y) { - return dst->region->map + (y * dst->pitch + x) * dst->cpp; + return dst->map + (y * dst->pitch + x) * dst->cpp; } @@ -879,7 +876,7 @@ sp_surface_fill(struct pipe_context *pipe, assert(dst->pitch > 0); assert(width <= dst->pitch); - (void)pipe->region_map(pipe, dst->region); + (void)pipe_surface_map(dst); switch (dst->cpp) { case 1: @@ -935,7 +932,7 @@ sp_surface_fill(struct pipe_context *pipe, break; } - pipe->region_unmap( pipe, dst->region ); + pipe_surface_unmap( dst ); } diff --git a/src/mesa/pipe/softpipe/sp_texture.c b/src/mesa/pipe/softpipe/sp_texture.c index 2f9a1e9837..53486f9bba 100644 --- a/src/mesa/pipe/softpipe/sp_texture.c +++ b/src/mesa/pipe/softpipe/sp_texture.c @@ -32,6 +32,7 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "pipe/p_inlines.h" #include "pipe/p_util.h" #include "pipe/p_winsys.h" @@ -380,13 +381,18 @@ softpipe_texture_create(struct pipe_context *pipe, struct pipe_texture **pt) sizeof(struct softpipe_texture) - sizeof(struct pipe_texture)); if (softpipe_mipmap_tree_layout(pipe, spt)) { - spt->region = pipe->winsys->region_alloc(pipe->winsys, - spt->pitch * (*pt)->cpp * - spt->total_height, - PIPE_SURFACE_FLAG_TEXTURE); + spt->buffer = pipe->winsys->buffer_create(pipe->winsys, + PIPE_SURFACE_FLAG_TEXTURE); + + if (spt->buffer) { + pipe->winsys->buffer_data(pipe->winsys, spt->buffer, + spt->pitch * (*pt)->cpp * + spt->total_height, NULL, + PIPE_BUFFER_USAGE_PIXEL); + } } - if (!spt->region) { + if (!spt->buffer) { FREE(spt); spt = NULL; } @@ -413,7 +419,7 @@ softpipe_texture_release(struct pipe_context *pipe, struct pipe_texture **pt) DBG("%s deleting %p\n", __FUNCTION__, (void *) spt); */ - pipe->winsys->region_release(pipe->winsys, &spt->region); + pipe->winsys->buffer_reference(pipe->winsys, &spt->buffer, NULL); for (i = 0; i < PIPE_MAX_TEXTURE_LEVELS; i++) if (spt->image_offset[i]) diff --git a/src/mesa/pipe/softpipe/sp_tile_cache.c b/src/mesa/pipe/softpipe/sp_tile_cache.c index 62ee6a27c9..08cd39cc55 100644 --- a/src/mesa/pipe/softpipe/sp_tile_cache.c +++ b/src/mesa/pipe/softpipe/sp_tile_cache.c @@ -123,16 +123,24 @@ sp_destroy_tile_cache(struct softpipe_tile_cache *tc) void -sp_tile_cache_set_surface(struct softpipe_tile_cache *tc, +sp_tile_cache_set_surface(struct softpipe_context *sp, + struct softpipe_tile_cache *tc, struct pipe_surface *ps) { + if (tc->surface && tc->surface->map) + pipe_surface_unmap(tc->surface); + pipe_surface_reference(&tc->surface, ps); } struct pipe_surface * -sp_tile_cache_get_surface(struct softpipe_tile_cache *tc) +sp_tile_cache_get_surface(struct softpipe_context *sp, + struct softpipe_tile_cache *tc) { + if (tc->surface && !tc->surface->map) + pipe_surface_map(tc->surface); + return tc->surface; } @@ -162,7 +170,7 @@ sp_flush_tile_cache(struct softpipe_context *softpipe, boolean is_depth_stencil; int inuse = 0, pos; - if (!ps || !ps->region || !ps->region->map) + if (!ps || !ps->buffer) return; is_depth_stencil = (ps->format == PIPE_FORMAT_S8_Z24 || @@ -367,6 +375,16 @@ sp_get_cached_tile_tex(struct pipe_context *pipe, struct pipe_surface *ps = pipe->get_tex_surface(pipe, tc->texture, face, level, z); + if (ps != tc->surface) { + if (tc->surface && tc->surface->map) + pipe_surface_unmap(tc->surface); + + pipe_surface_reference(&tc->surface, ps); + + if (!tc->surface->map) + pipe_surface_map(tc->surface); + } + pipe->get_tile_rgba(pipe, ps, tile_x, tile_y, TILE_SIZE, TILE_SIZE, (float *) tile->data.color); diff --git a/src/mesa/pipe/softpipe/sp_tile_cache.h b/src/mesa/pipe/softpipe/sp_tile_cache.h index 9967aa5044..de5ff2c498 100644 --- a/src/mesa/pipe/softpipe/sp_tile_cache.h +++ b/src/mesa/pipe/softpipe/sp_tile_cache.h @@ -63,11 +63,13 @@ extern void sp_destroy_tile_cache(struct softpipe_tile_cache *tc); extern void -sp_tile_cache_set_surface(struct softpipe_tile_cache *tc, +sp_tile_cache_set_surface(struct softpipe_context *sp, + struct softpipe_tile_cache *tc, struct pipe_surface *sps); extern struct pipe_surface * -sp_tile_cache_get_surface(struct softpipe_tile_cache *tc); +sp_tile_cache_get_surface(struct softpipe_context *sp, + struct softpipe_tile_cache *tc); extern void sp_tile_cache_set_texture(struct softpipe_tile_cache *tc, diff --git a/src/mesa/pipe/xlib/xm_api.c b/src/mesa/pipe/xlib/xm_api.c index f87d72d0c8..542b4aca49 100644 --- a/src/mesa/pipe/xlib/xm_api.c +++ b/src/mesa/pipe/xlib/xm_api.c @@ -1512,7 +1512,7 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) pipe->get_tile_rgba = xmesa_get_tile_rgba; pipe->put_tile_rgba = xmesa_put_tile_rgba; - c->st->haveFramebufferRegions = GL_FALSE; + c->st->haveFramebufferSurfaces = GL_FALSE; /* special pipe->clear function */ pipe->clear = xmesa_clear; diff --git a/src/mesa/pipe/xlib/xm_buffer.c b/src/mesa/pipe/xlib/xm_buffer.c index 449e90184b..6fc2f4ba63 100644 --- a/src/mesa/pipe/xlib/xm_buffer.c +++ b/src/mesa/pipe/xlib/xm_buffer.c @@ -269,9 +269,8 @@ static void finish_surface_init(GLcontext *ctx, struct xmesa_renderbuffer *xrb) { struct pipe_context *pipe = ctx->st->pipe; - if (!xrb->St.surface->region) { - xrb->St.surface->region = pipe->winsys->region_alloc(pipe->winsys, 1, - 0x0); + if (!xrb->St.surface->buffer) { + xrb->St.surface->buffer = pipe->winsys->buffer_create(pipe->winsys, 0x0); } } @@ -301,7 +300,7 @@ xmesa_alloc_front_storage(GLcontext *ctx, struct gl_renderbuffer *rb, rb->Height = height; rb->InternalFormat = internalFormat; - if (!xrb->St.surface || !xrb->St.surface->region) + if (!xrb->St.surface || !xrb->St.surface->buffer) finish_surface_init(ctx, xrb); /* surface info */ @@ -363,7 +362,7 @@ xmesa_alloc_back_storage(GLcontext *ctx, struct gl_renderbuffer *rb, xrb->origin4 = NULL; } - if (!xrb->St.surface || !xrb->St.surface->region) + if (!xrb->St.surface || !xrb->St.surface->buffer) finish_surface_init(ctx, xrb); xrb->St.surface->width = width; diff --git a/src/mesa/pipe/xlib/xm_surface.c b/src/mesa/pipe/xlib/xm_surface.c index 58ca2e7fb3..4a54b5c7e1 100644 --- a/src/mesa/pipe/xlib/xm_surface.c +++ b/src/mesa/pipe/xlib/xm_surface.c @@ -665,12 +665,12 @@ xmesa_new_color_surface(struct pipe_winsys *winsys, GLuint pipeFormat) xms->surface.refcount = 1; xms->surface.winsys = winsys; - /* Note, the region we allocate doesn't actually have any storage + /* Note, the buffer we allocate doesn't actually have any storage * since we're drawing into an XImage or Pixmap. - * The region's size will get set in the xmesa_alloc_front/back_storage() + * The surface's size will get set in the xmesa_alloc_front/back_storage() * functions. */ - xms->surface.region = winsys->region_alloc(winsys, 1, 0x0); + xms->surface.buffer = winsys->buffer_create(winsys, 0x0); return &xms->surface; } @@ -713,7 +713,7 @@ xmesa_clear(struct pipe_context *pipe, struct pipe_surface *ps, uint value) { struct softpipe_context *sp = softpipe_context(pipe); - if (ps == sp_tile_cache_get_surface(sp->cbuf_cache[0])) { + if (ps == sp_tile_cache_get_surface(sp, sp->cbuf_cache[0])) { float clear[4]; clear[0] = 0.2; /* XXX hack */ clear[1] = 0.2; diff --git a/src/mesa/pipe/xlib/xm_winsys.c b/src/mesa/pipe/xlib/xm_winsys.c index 99816a811d..295174d4bb 100644 --- a/src/mesa/pipe/xlib/xm_winsys.c +++ b/src/mesa/pipe/xlib/xm_winsys.c @@ -186,7 +186,7 @@ xm_get_name(struct pipe_winsys *pws) static struct pipe_buffer_handle * -xm_buffer_create(struct pipe_winsys *pws, unsigned alignment) +xm_buffer_create(struct pipe_winsys *pws, unsigned flags) { struct xm_buffer *buffer = CALLOC_STRUCT(xm_buffer); buffer->refcount = 1; @@ -228,47 +228,6 @@ xm_surface_pitch(struct pipe_winsys *winsys, unsigned cpp, unsigned width, } -static struct pipe_region * -xm_region_alloc(struct pipe_winsys *winsys, unsigned size, unsigned flags) -{ - struct pipe_region *region = CALLOC_STRUCT(pipe_region); - const unsigned alignment = 64; - - region->refcount = 1; - - assert(size > 0); - - region->buffer = winsys->buffer_create( winsys, alignment ); - - /* NULL data --> just allocate the space */ - winsys->buffer_data( winsys, - region->buffer, - size, - NULL, - PIPE_BUFFER_USAGE_PIXEL ); - return region; -} - - -static void -xm_region_release(struct pipe_winsys *winsys, struct pipe_region **region) -{ - if (!*region) - return; - - assert((*region)->refcount > 0); - (*region)->refcount--; - - if ((*region)->refcount == 0) { - assert((*region)->map_refcount == 0); - - winsys->buffer_reference( winsys, &((*region)->buffer), NULL ); - free(*region); - } - *region = NULL; -} - - /** * Called via pipe->surface_alloc() to create new surfaces (textures, * renderbuffers, etc. @@ -301,8 +260,8 @@ xm_surface_release(struct pipe_winsys *winsys, struct pipe_surface **s) struct pipe_surface *surf = *s; surf->refcount--; if (surf->refcount == 0) { - if (surf->region) - winsys->region_release(winsys, &surf->region); + if (surf->buffer) + winsys->buffer_reference(winsys, &surf->buffer, NULL); free(surf); } *s = NULL; @@ -335,9 +294,6 @@ xmesa_get_pipe_winsys(void) ws->buffer_subdata = xm_buffer_subdata; ws->buffer_get_subdata = xm_buffer_get_subdata; - ws->region_alloc = xm_region_alloc; - ws->region_release = xm_region_release; - ws->surface_pitch = xm_surface_pitch; ws->surface_alloc = xm_surface_alloc; ws->surface_release = xm_surface_release; diff --git a/src/mesa/state_tracker/st_cb_accum.c b/src/mesa/state_tracker/st_cb_accum.c index 7a245b0ed6..c8d9cba12f 100644 --- a/src/mesa/state_tracker/st_cb_accum.c +++ b/src/mesa/state_tracker/st_cb_accum.c @@ -42,6 +42,7 @@ #include "st_format.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "pipe/p_inlines.h" /** @@ -68,7 +69,7 @@ st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) GLfloat *accBuf; GLint i; - (void) pipe->region_map(pipe, acc_ps->region); + (void) pipe_surface_map(acc_ps); accBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); @@ -83,7 +84,7 @@ st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) free(accBuf); - pipe->region_unmap(pipe, acc_ps->region); + pipe_surface_unmap(acc_ps); } @@ -99,7 +100,7 @@ accum_mad(struct pipe_context *pipe, GLfloat scale, GLfloat bias, accBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - (void) pipe->region_map(pipe, acc_ps->region); + (void) pipe_surface_map(acc_ps); pipe->get_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf); @@ -111,7 +112,7 @@ accum_mad(struct pipe_context *pipe, GLfloat scale, GLfloat bias, free(accBuf); - pipe->region_unmap(pipe, acc_ps->region); + pipe_surface_unmap(acc_ps); } @@ -128,8 +129,8 @@ accum_accum(struct pipe_context *pipe, GLfloat value, colorBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); accBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - colorMap = pipe->region_map(pipe, color_ps->region); - accMap = pipe->region_map(pipe, acc_ps->region); + colorMap = pipe_surface_map(color_ps); + accMap = pipe_surface_map(acc_ps); pipe->get_tile_rgba(pipe, color_ps, xpos, ypos, width, height, colorBuf); pipe->get_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf); @@ -143,8 +144,8 @@ accum_accum(struct pipe_context *pipe, GLfloat value, free(colorBuf); free(accBuf); - pipe->region_unmap(pipe, color_ps->region); - pipe->region_unmap(pipe, acc_ps->region); + pipe_surface_unmap(color_ps); + pipe_surface_unmap(acc_ps); } @@ -159,8 +160,8 @@ accum_load(struct pipe_context *pipe, GLfloat value, buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - (void) pipe->region_map(pipe, color_ps->region); - (void) pipe->region_map(pipe, acc_ps->region); + (void) pipe_surface_map(color_ps); + (void) pipe_surface_map(acc_ps); pipe->get_tile_rgba(pipe, color_ps, xpos, ypos, width, height, buf); @@ -172,8 +173,8 @@ accum_load(struct pipe_context *pipe, GLfloat value, free(buf); - pipe->region_unmap(pipe, color_ps->region); - pipe->region_unmap(pipe, acc_ps->region); + pipe_surface_unmap(color_ps); + pipe_surface_unmap(acc_ps); } @@ -190,8 +191,8 @@ accum_return(GLcontext *ctx, GLfloat value, abuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - (void) pipe->region_map(pipe, color_ps->region); - (void) pipe->region_map(pipe, acc_ps->region); + (void) pipe_surface_map(color_ps); + (void) pipe_surface_map(acc_ps); pipe->get_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, abuf); @@ -218,8 +219,8 @@ accum_return(GLcontext *ctx, GLfloat value, if (cbuf) free(cbuf); - pipe->region_unmap(pipe, color_ps->region); - pipe->region_unmap(pipe, acc_ps->region); + pipe_surface_unmap(color_ps); + pipe_surface_unmap(acc_ps); } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index c28ad15b29..a61daffb20 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -492,11 +492,10 @@ make_texture(struct st_context *st, surface = pipe->get_tex_surface(pipe, pt, 0, 0, 0); - /* map texture region */ - (void) pipe->region_map(pipe, surface->region); - dest = surface->region->map + surface->offset; + /* map texture surface */ + dest = pipe_surface_map(surface); - /* Put image into texture region. + /* Put image into texture surface. * Note that the image is actually going to be upside down in * the texture. We deal with that with texcoords. */ @@ -513,7 +512,7 @@ make_texture(struct st_context *st, unpack); /* unmap */ - pipe->region_unmap(pipe, surface->region); + pipe_surface_unmap(surface); pipe_surface_reference(&surface, NULL); assert(success); @@ -852,7 +851,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, pipe->flush(pipe, 0); /* map the stencil buffer */ - stmap = pipe->region_map(pipe, ps->region); + stmap = pipe_surface_map(ps); /* if width > MAX_WIDTH, have to process image in chunks */ skipPixels = 0; @@ -909,7 +908,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, } /* unmap the stencil buffer */ - pipe->region_unmap(pipe, ps->region); + pipe_surface_unmap(ps); } @@ -1027,11 +1026,10 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, surface = pipe->get_tex_surface(pipe, pt, 0, 0, 0); - /* map texture region */ - (void) pipe->region_map(pipe, surface->region); - dest = surface->region->map + surface->offset; + /* map texture surface */ + dest = pipe_surface_map(surface); - /* Put image into texture region. + /* Put image into texture surface. * Note that the image is actually going to be upside down in * the texture. We deal with that with texcoords. */ @@ -1089,7 +1087,7 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, } /* row */ /* Release surface */ - pipe->region_unmap(pipe, surface->region); + pipe_surface_unmap(surface); pipe_surface_reference(&surface, NULL); pt->format = format; @@ -1130,8 +1128,6 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, GLsizei width, GLsizei height, GLint dstx, GLint dsty) { - struct st_context *st = ctx->st; - struct pipe_context *pipe = st->pipe; struct st_renderbuffer *rbRead = st_renderbuffer(ctx->ReadBuffer->_StencilBuffer); struct st_renderbuffer *rbDraw = st_renderbuffer(ctx->DrawBuffer->_StencilBuffer); struct pipe_surface *psRead = rbRead->surface; @@ -1147,8 +1143,8 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, } /* map the stencil buffers */ - readMap = pipe->region_map(pipe, psRead->region); - drawMap = pipe->region_map(pipe, psDraw->region); + readMap = pipe_surface_map(psRead); + drawMap = pipe_surface_map(psDraw); /* this will do stencil pixel transfer ops */ st_read_stencil_pixels(ctx, srcx, srcy, width, height, GL_UNSIGNED_BYTE, @@ -1192,8 +1188,8 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, free(buffer); /* unmap the stencil buffers */ - pipe->region_unmap(pipe, psRead->region); - pipe->region_unmap(pipe, psDraw->region); + pipe_surface_unmap(psRead); + pipe_surface_unmap(psDraw); } @@ -1252,11 +1248,11 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, } /* For some drivers (like Xlib) it's not possible to treat the - * front/back color buffers as regions (they're XImages and Pixmaps). - * So, this var tells us if we can use region_copy here... + * front/back color buffers as surfaces (they're XImages and Pixmaps). + * So, this var tells us if we can use surface_copy here... */ - if (st->haveFramebufferRegions) { - /* copy source framebuffer region into mipmap/texture */ + if (st->haveFramebufferSurfaces) { + /* copy source framebuffer surface into mipmap/texture */ pipe->surface_copy(pipe, psTex, /* dest */ 0, 0, /* destx/y */ @@ -1267,14 +1263,14 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, /* alternate path using get/put_tile() */ GLfloat *buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - (void) pipe->region_map(pipe, psRead->region); - (void) pipe->region_map(pipe, psTex->region); + (void) pipe_surface_map(psRead); + (void) pipe_surface_map(psTex); pipe->get_tile_rgba(pipe, psRead, srcx, srcy, width, height, buf); pipe->put_tile_rgba(pipe, psTex, 0, 0, width, height, buf); - pipe->region_unmap(pipe, psRead->region); - pipe->region_unmap(pipe, psTex->region); + pipe_surface_unmap(psRead); + pipe_surface_unmap(psTex); free(buf); } diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 43681b7f8a..6b9023c410 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -109,22 +109,22 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, width, flags); } - /* free old region */ - if (strb->surface->region) { - /* loop here since mapping is refcounted */ - struct pipe_region *r = strb->surface->region; - while (r->map) - pipe->region_unmap(pipe, r); - pipe->winsys->region_release(pipe->winsys, &strb->surface->region); - } - - strb->surface->region = pipe->winsys->region_alloc(pipe->winsys, - strb->surface->pitch * - cpp * height, flags); - if (!strb->surface->region) + /* loop here since mapping is refcounted */ + while (strb->surface->map) + pipe_surface_unmap(strb->surface); + if (strb->surface->buffer) + pipe->winsys->buffer_reference(pipe->winsys, &strb->surface->buffer, + NULL); + + strb->surface->buffer = pipe->winsys->buffer_create(pipe->winsys, flags); + if (!strb->surface->buffer) return GL_FALSE; /* out of memory, try s/w buffer? */ - ASSERT(strb->surface->region->buffer); + pipe->winsys->buffer_data(pipe->winsys, strb->surface->buffer, + strb->surface->pitch * cpp * height, NULL, + PIPE_BUFFER_USAGE_PIXEL); + + ASSERT(strb->surface->buffer); ASSERT(strb->surface->format); strb->Base.Width = strb->surface->width = width; diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c index 83fe480af8..e2243e7de4 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -39,6 +39,7 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "pipe/p_inlines.h" #include "st_context.h" #include "st_cb_readpixels.h" #include "st_cb_fbo.h" @@ -56,8 +57,6 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, const struct gl_pixelstore_attrib *packing, GLvoid *pixels) { - struct st_context *st = ctx->st; - struct pipe_context *pipe = st->pipe; struct gl_framebuffer *fb = ctx->ReadBuffer; struct st_renderbuffer *strb = st_renderbuffer(fb->_StencilBuffer); struct pipe_surface *ps = strb->surface; @@ -65,7 +64,7 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, GLint j; /* map the stencil buffer */ - stmap = pipe->region_map(pipe, ps->region); + stmap = pipe_surface_map(ps); /* width should never be > MAX_WIDTH since we did clipping earlier */ ASSERT(width <= MAX_WIDTH); @@ -122,7 +121,7 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, /* unmap the stencil buffer */ - pipe->region_unmap(pipe, ps->region); + pipe_surface_unmap(ps); } @@ -151,7 +150,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, /* Do all needed clipping here, so that we can forget about it later */ if (!_mesa_clip_readpixels(ctx, &x, &y, &width, &height, &clippedPacking)) { - /* The ReadPixels region is totally outside the window bounds */ + /* The ReadPixels surface is totally outside the window bounds */ return; } @@ -180,7 +179,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, if (!strb) return; - pipe->region_map(pipe, strb->surface->region); + pipe_surface_map(strb->surface); if (format == GL_RGBA && type == GL_FLOAT) { /* write tile(row) directly into user's buffer */ @@ -231,7 +230,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, } } - pipe->region_unmap(pipe, strb->surface->region); + pipe_surface_unmap(strb->surface); } diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index acc97df2e7..1fcef746c1 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -64,7 +64,7 @@ struct st_texture_object GLuint textureOffset; /* On validation any active images held in main memory or in other - * regions will be copied to this region and the old storage freed. + * textures will be copied to this texture and the old storage freed. */ struct pipe_texture *pt; @@ -721,7 +721,7 @@ st_TexImage(GLcontext * ctx, } if (stImage->pt && i < depth) { - st_texture_image_unmap(ctx->st, stImage); + st_texture_image_unmap(stImage); texImage->Data = st_texture_image_map(ctx->st, stImage, i); pixels += srcImageStride; } @@ -731,7 +731,7 @@ st_TexImage(GLcontext * ctx, _mesa_unmap_teximage_pbo(ctx, unpack); if (stImage->pt) { - st_texture_image_unmap(ctx->st, stImage); + st_texture_image_unmap(stImage); texImage->Data = NULL; } @@ -860,7 +860,7 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level, } if (stImage->pt && i < depth) { - st_texture_image_unmap(ctx->st, stImage); + st_texture_image_unmap(stImage); texImage->Data = st_texture_image_map(ctx->st, stImage, i); pixels += dstImageStride; } @@ -870,7 +870,7 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level, /* Unmap */ if (stImage->pt) { - st_texture_image_unmap(ctx->st, stImage); + st_texture_image_unmap(stImage); texImage->Data = NULL; } } @@ -948,7 +948,7 @@ st_TexSubimage(GLcontext * ctx, } if (stImage->pt && i < depth) { - st_texture_image_unmap(ctx->st, stImage); + st_texture_image_unmap(stImage); texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset + i); pixels += srcImageStride; } @@ -966,7 +966,7 @@ st_TexSubimage(GLcontext * ctx, _mesa_unmap_teximage_pbo(ctx, packing); if (stImage->pt) { - st_texture_image_unmap(ctx->st, stImage); + st_texture_image_unmap(stImage); texImage->Data = NULL; } } @@ -1051,8 +1051,8 @@ texture_face(GLenum target) /** - * Do a CopyTexSubImage operation by mapping the source region and - * dest region and using get_tile()/put_tile() to access the pixels/texels. + * Do a CopyTexSubImage operation by mapping the source surface and + * dest surface and using get_tile()/put_tile() to access the pixels/texels. * * Note: srcY=0=TOP of renderbuffer */ @@ -1088,8 +1088,8 @@ fallback_copy_texsubimage(GLcontext *ctx, dest_surf = pipe->get_tex_surface(pipe, pt, face, level, destZ); - (void) pipe->region_map(pipe, dest_surf->region); - (void) pipe->region_map(pipe, src_surf->region); + (void) pipe_surface_map(dest_surf); + (void) pipe_surface_map(src_surf); /* buffer for one row */ data = (GLfloat *) malloc(width * 4 * sizeof(GLfloat)); @@ -1110,8 +1110,8 @@ fallback_copy_texsubimage(GLcontext *ctx, } - (void) pipe->region_unmap(pipe, dest_surf->region); - (void) pipe->region_unmap(pipe, src_surf->region); + (void) pipe_surface_unmap(dest_surf); + (void) pipe_surface_unmap(src_surf); free(data); } @@ -1178,8 +1178,8 @@ do_copy_texsubimage(GLcontext *ctx, if (src_format == dest_format && ctx->_ImageTransferState == 0x0 && - strb->surface->region && - dest_surface->region && + strb->surface->buffer && + dest_surface->buffer && strb->surface->cpp == stImage->pt->cpp) { /* do blit-style copy */ diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index a4ec3721be..abde6d64b0 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -103,7 +103,7 @@ st_create_context_priv( GLcontext *ctx, struct pipe_context *pipe ) st->ctx->VertexProgram._MaintainTnlProgram = GL_TRUE; - st->haveFramebufferRegions = GL_TRUE; + st->haveFramebufferSurfaces = GL_TRUE; st->pixel_xfer.cache = _mesa_new_program_cache(); diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index db97014c5a..c31b76c63f 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -34,7 +34,6 @@ struct st_context; -struct st_region; struct st_texture_object; struct st_fragment_program; struct draw_context; @@ -131,11 +130,11 @@ struct st_context char vendor[100]; char renderer[100]; - /** Can we access the front/back color buffers as pipe_regions? + /** Can we access the front/back color buffers as pipe_surfaces? * We can't with the Xlib driver... * This is a hack that should be fixed someday. */ - GLboolean haveFramebufferRegions; + GLboolean haveFramebufferSurfaces; /* State to be validated: */ diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c index a5582c31c0..1ec4514873 100644 --- a/src/mesa/state_tracker/st_texture.c +++ b/src/mesa/state_tracker/st_texture.c @@ -33,6 +33,7 @@ #include "pipe/p_state.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" +#include "pipe/p_inlines.h" #include "pipe/p_util.h" #include "pipe/p_inlines.h" #include "pipe/p_winsys.h" @@ -187,17 +188,15 @@ st_texture_image_map(struct st_context *st, struct st_texture_image *stImage, stImage->surface = st->pipe->get_tex_surface(st->pipe, pt, stImage->face, stImage->level, zoffset); - (void) st->pipe->region_map(st->pipe, stImage->surface->region); - - return stImage->surface->region->map + stImage->surface->offset; + return pipe_surface_map(stImage->surface); } void -st_texture_image_unmap(struct st_context *st, struct st_texture_image *stImage) +st_texture_image_unmap(struct st_texture_image *stImage) { DBG("%s\n", __FUNCTION__); - st->pipe->region_unmap(st->pipe, stImage->surface->region); + pipe_surface_unmap(stImage->surface); pipe_surface_reference(&stImage->surface, NULL); } diff --git a/src/mesa/state_tracker/st_texture.h b/src/mesa/state_tracker/st_texture.h index b25e3f3f3b..f49d91a069 100644 --- a/src/mesa/state_tracker/st_texture.h +++ b/src/mesa/state_tracker/st_texture.h @@ -65,8 +65,7 @@ st_texture_image_map(struct st_context *st, GLuint zoffset); extern void -st_texture_image_unmap(struct st_context *st, - struct st_texture_image *stImage); +st_texture_image_unmap(struct st_texture_image *stImage); /* Return pointers to each 2d slice within an image. Indexed by depth -- cgit v1.2.3 From ee6b39cfe602bd88a88bedc5af672832d9157105 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 7 Dec 2007 07:53:06 -0700 Subject: move surface pitch calculation so it always gets updated --- src/mesa/state_tracker/st_cb_fbo.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 6b9023c410..0ee5f45aae 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -105,10 +105,11 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, if (!strb->surface) return GL_FALSE; strb->surface->cpp = cpp; - strb->surface->pitch = pipe->winsys->surface_pitch(pipe->winsys, cpp, - width, flags); } + strb->surface->pitch = pipe->winsys->surface_pitch(pipe->winsys, cpp, + width, flags); + /* loop here since mapping is refcounted */ while (strb->surface->map) pipe_surface_unmap(strb->surface); -- cgit v1.2.3 From 54fc80ab31f89520d3119196bfa9c6332b35fe2f Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 7 Dec 2007 16:46:30 -0700 Subject: Define PIPE_FORMAT_ tokens as an enum set, rather than #defines. This makes debugging a _lot_ easier. In gdb, "print format" used to display 613570600, now you see PIPE_FORMAT_A8R8G8B8_UNORM. --- .../drivers/dri/intel_winsys/intel_winsys_pipe.c | 2 +- src/mesa/pipe/draw/draw_vertex_fetch.c | 2 +- src/mesa/pipe/draw/draw_vertex_shader_llvm.c | 2 +- src/mesa/pipe/i915simple/i915_context.c | 5 +- src/mesa/pipe/i915simple/i915_state_emit.c | 4 +- src/mesa/pipe/i915simple/i915_state_sampler.c | 2 +- src/mesa/pipe/p_context.h | 2 +- src/mesa/pipe/p_format.h | 154 +++++++++++---------- src/mesa/pipe/p_state.h | 7 +- src/mesa/pipe/p_winsys.h | 4 +- src/mesa/pipe/softpipe/sp_context.c | 3 +- src/mesa/pipe/softpipe/sp_quad_depth_test.c | 2 +- src/mesa/pipe/softpipe/sp_tile_cache.c | 3 +- src/mesa/pipe/xlib/xm_winsys.c | 5 +- src/mesa/state_tracker/st_cb_clear.c | 6 +- src/mesa/state_tracker/st_cb_drawpixels.c | 5 +- src/mesa/state_tracker/st_cb_fbo.c | 5 +- src/mesa/state_tracker/st_format.c | 14 +- src/mesa/state_tracker/st_format.h | 18 ++- 19 files changed, 127 insertions(+), 118 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c b/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c index 1b71d0ac10..1799e9b901 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c @@ -193,7 +193,7 @@ intel_i915_surface_pitch(struct pipe_winsys *winsys, static struct pipe_surface * -intel_i915_surface_alloc(struct pipe_winsys *winsys, unsigned format) +intel_i915_surface_alloc(struct pipe_winsys *winsys, enum pipe_format format) { struct pipe_surface *surf = CALLOC_STRUCT(pipe_surface); if (surf) { diff --git a/src/mesa/pipe/draw/draw_vertex_fetch.c b/src/mesa/pipe/draw/draw_vertex_fetch.c index 77df5c6427..e0759c2e9a 100644 --- a/src/mesa/pipe/draw/draw_vertex_fetch.c +++ b/src/mesa/pipe/draw/draw_vertex_fetch.c @@ -46,7 +46,7 @@ * XXX this might be a temporary thing. */ static void -fetch_attrib4(const void *ptr, unsigned format, float attrib[4]) +fetch_attrib4(const void *ptr, enum pipe_format format, float attrib[4]) { /* defaults */ attrib[1] = 0.0; diff --git a/src/mesa/pipe/draw/draw_vertex_shader_llvm.c b/src/mesa/pipe/draw/draw_vertex_shader_llvm.c index 53a1776ffc..29de437595 100644 --- a/src/mesa/pipe/draw/draw_vertex_shader_llvm.c +++ b/src/mesa/pipe/draw/draw_vertex_shader_llvm.c @@ -43,7 +43,7 @@ #define DBG 0 static INLINE void -fetch_attrib4(const void *ptr, unsigned format, float attrib[4]) +fetch_attrib4(const void *ptr, enum pipe_format format, float attrib[4]) { /* defaults */ attrib[1] = 0.0; diff --git a/src/mesa/pipe/i915simple/i915_context.c b/src/mesa/pipe/i915simple/i915_context.c index cfce116920..b915a67790 100644 --- a/src/mesa/pipe/i915simple/i915_context.c +++ b/src/mesa/pipe/i915simple/i915_context.c @@ -45,7 +45,7 @@ */ static boolean i915_is_format_supported( struct pipe_context *pipe, - uint format ) + enum pipe_format format ) { #if 0 /* XXX: This is broken -- rewrite if still needed. */ @@ -101,8 +101,9 @@ i915_is_format_supported( struct pipe_context *pipe, case PIPE_FORMAT_R5G6B5_UNORM: case PIPE_FORMAT_S8Z24_UNORM: return TRUE; + default: + return FALSE; }; - return FALSE; #endif } diff --git a/src/mesa/pipe/i915simple/i915_state_emit.c b/src/mesa/pipe/i915simple/i915_state_emit.c index 1e0db91024..09bf1fa2d6 100644 --- a/src/mesa/pipe/i915simple/i915_state_emit.c +++ b/src/mesa/pipe/i915simple/i915_state_emit.c @@ -35,7 +35,7 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" -static unsigned translate_format( unsigned format ) +static unsigned translate_format( enum pipe_format format ) { switch (format) { case PIPE_FORMAT_A8R8G8B8_UNORM: @@ -48,7 +48,7 @@ static unsigned translate_format( unsigned format ) } } -static unsigned translate_depth_format( unsigned zformat ) +static unsigned translate_depth_format( enum pipe_format zformat ) { switch (zformat) { case PIPE_FORMAT_S8Z24_UNORM: diff --git a/src/mesa/pipe/i915simple/i915_state_sampler.c b/src/mesa/pipe/i915simple/i915_state_sampler.c index dd2d51d9f6..59408b6ba0 100644 --- a/src/mesa/pipe/i915simple/i915_state_sampler.c +++ b/src/mesa/pipe/i915simple/i915_state_sampler.c @@ -127,7 +127,7 @@ void i915_update_samplers( struct i915_context *i915 ) static uint -translate_texture_format(uint pipeFormat) +translate_texture_format(enum pipe_format pipeFormat) { switch (pipeFormat) { case PIPE_FORMAT_U_L8: diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 2420d02213..b3a2122ade 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -51,7 +51,7 @@ struct pipe_context { * Queries */ boolean (*is_format_supported)( struct pipe_context *pipe, - uint format ); + enum pipe_format format ); const char *(*get_name)( struct pipe_context *pipe ); diff --git a/src/mesa/pipe/p_format.h b/src/mesa/pipe/p_format.h index 86728f77a2..8f11bfab76 100644 --- a/src/mesa/pipe/p_format.h +++ b/src/mesa/pipe/p_format.h @@ -198,86 +198,90 @@ static INLINE uint pf_rev(pipe_format_ycbcr_t f) * z24s8, compressed textures, ycbcr, etc that won't fit that model. */ -#define PIPE_FORMAT_NONE _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_0000, 0, 0, 0, 0, PIPE_FORMAT_TYPE_UNKNOWN ) -#define PIPE_FORMAT_A8R8G8B8_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_ARGB, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_B8G8R8A8_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_BGRA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_A1R5G5B5_UNORM _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_ARGB, 1, 5, 5, 5, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_A4R4G4B4_UNORM _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_ARGB, 4, 4, 4, 4, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R5G6B5_UNORM _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_RGB0, 5, 6, 5, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_U_L8 _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRR1, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ) /**< ubyte luminance */ -#define PIPE_FORMAT_U_A8 _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_000R, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ) /**< ubyte alpha */ -#define PIPE_FORMAT_U_I8 _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRRR, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ) /**< ubyte intensity */ -#define PIPE_FORMAT_U_A8_L8 _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRRG, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ) /**< ubyte alpha, luminance */ -#define PIPE_FORMAT_YCBCR _PIPE_FORMAT_YCBCR( 0 ) -#define PIPE_FORMAT_YCBCR_REV _PIPE_FORMAT_YCBCR( 1 ) -#define PIPE_FORMAT_Z16_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_Z000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_Z32_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_Z000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_Z32_FLOAT _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_Z000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT ) -#define PIPE_FORMAT_S8Z24_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_SZ00, 1, 3, 0, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_Z24S8_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_ZS00, 3, 1, 0, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_S8_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_S000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R64_FLOAT _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT ) -#define PIPE_FORMAT_R64G64_FLOAT _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_FLOAT ) -#define PIPE_FORMAT_R64G64B64_FLOAT _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_FLOAT ) -#define PIPE_FORMAT_R64G64B64A64_FLOAT _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_FLOAT ) -#define PIPE_FORMAT_R32_FLOAT _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT ) -#define PIPE_FORMAT_R32G32_FLOAT _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_FLOAT ) -#define PIPE_FORMAT_R32G32B32_FLOAT _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_FLOAT ) -#define PIPE_FORMAT_R32G32B32A32_FLOAT _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_FLOAT ) -#define PIPE_FORMAT_R32_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R32G32_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R32G32B32_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R32G32B32A32_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R32_USCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R32G32_USCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R32G32B32_USCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R32G32B32A32_USCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R32_SNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R32G32_SNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R32G32B32_SNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R32G32B32A32_SNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R32_SSCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R32G32_SSCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R32G32B32_SSCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R32G32B32A32_SSCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R16_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R16G16_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 2, 2, 0, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R16G16B16_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 2, 2, 2, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R16G16B16A16_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R16_USCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R16G16_USCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 2, 2, 0, 0, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R16G16B16_USCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 2, 2, 2, 0, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R16G16B16A16_USCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R16_SNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R16G16_SNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 2, 2, 0, 0, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R16G16B16_SNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 2, 2, 2, 0, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R16G16B16A16_SNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R16_SSCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R16G16_SSCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 2, 2, 0, 0, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R16G16B16_SSCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 2, 2, 2, 0, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R16G16B16A16_SSCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R8_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R8G8_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R8G8B8_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R8G8B8A8_UNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ) -#define PIPE_FORMAT_R8_USCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R8G8_USCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R8G8B8_USCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R8G8B8A8_USCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_USCALED ) -#define PIPE_FORMAT_R8_SNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R8G8_SNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R8G8B8_SNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R8G8B8A8_SNORM _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SNORM ) -#define PIPE_FORMAT_R8_SSCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R8G8_SSCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R8G8B8_SSCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_SSCALED ) -#define PIPE_FORMAT_R8G8B8A8_SSCALED _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SSCALED ) +enum pipe_format { + PIPE_FORMAT_NONE = _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_0000, 0, 0, 0, 0, PIPE_FORMAT_TYPE_UNKNOWN ), + PIPE_FORMAT_A8R8G8B8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_ARGB, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_B8G8R8A8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_BGRA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_A1R5G5B5_UNORM = _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_ARGB, 1, 5, 5, 5, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_A4R4G4B4_UNORM = _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_ARGB, 4, 4, 4, 4, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R5G6B5_UNORM = _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_RGB0, 5, 6, 5, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_U_L8 = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRR1, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), /**< ubyte luminance */ + PIPE_FORMAT_U_A8 = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_000R, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), /**< ubyte alpha */ + PIPE_FORMAT_U_I8 = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRRR, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), /**< ubyte intensity */ + PIPE_FORMAT_U_A8_L8 = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRRG, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), /**< ubyte alpha, luminance */ + PIPE_FORMAT_YCBCR = _PIPE_FORMAT_YCBCR( 0 ), + PIPE_FORMAT_YCBCR_REV = _PIPE_FORMAT_YCBCR( 1 ), + PIPE_FORMAT_Z16_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_Z000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_Z32_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_Z000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_Z32_FLOAT = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_Z000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_S8Z24_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_SZ00, 1, 3, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_Z24S8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_ZS00, 3, 1, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_S8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_S000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), /**< ubyte stencil */ + PIPE_FORMAT_R64_FLOAT = _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_R64G64_FLOAT = _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_R64G64B64_FLOAT = _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_R64G64B64A64_FLOAT = _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_R32_FLOAT = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_R32G32_FLOAT = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_R32G32B32_FLOAT = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_R32G32B32A32_FLOAT = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_R32_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R32G32_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R32G32B32_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R32G32B32A32_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R32_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R32G32_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R32G32B32_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R32G32B32A32_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R32_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R32G32_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R32G32B32_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R32G32B32A32_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R32_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R32G32_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R32G32B32_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R32G32B32A32_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R16_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R16G16_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 2, 2, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R16G16B16_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 2, 2, 2, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R16G16B16A16_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R16_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R16G16_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 2, 2, 0, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R16G16B16_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 2, 2, 2, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R16G16B16A16_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R16_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R16G16_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 2, 2, 0, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R16G16B16_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 2, 2, 2, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R16G16B16A16_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R16_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R16G16_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 2, 2, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R16G16B16_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 2, 2, 2, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R16G16B16A16_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R8G8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R8G8B8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R8G8B8A8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R8_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R8G8_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R8G8B8_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R8G8B8A8_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R8_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R8G8_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R8G8B8_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R8G8B8A8_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R8_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R8G8_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R8G8B8_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R8G8B8A8_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SSCALED ) +}; + /** - * Duplicated formats: + * XXX should remove this, but S8_UNORM is a poor name */ #define PIPE_FORMAT_U_S8 PIPE_FORMAT_S8_UNORM + /** * Builds pipe format name from format token. */ diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index 44dec9b773..6db9bbc953 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -39,6 +39,7 @@ #define PIPE_STATE_H #include "p_compiler.h" +#include "p_format.h" /** * Implementation limits @@ -265,7 +266,7 @@ struct pipe_surface struct pipe_buffer_handle *buffer; /**< driver private buffer handle */ ubyte *map; /**< only non-NULL when surface is actually mapped */ unsigned map_refcount; /**< Reference count for mapping */ - unsigned format; /**< PIPE_FORMAT_x */ + enum pipe_format format; /**< PIPE_FORMAT_x */ unsigned cpp; /**< bytes per pixel */ unsigned width, height; unsigned pitch; /**< in pixels */ @@ -286,7 +287,7 @@ struct pipe_texture unsigned target; /* XXX convert to PIPE_TEXTURE_x */ unsigned internal_format; /* XXX convert to PIPE_FORMAT_x */ - unsigned format; /**< PIPE_FORMAT_x */ + enum pipe_format format; /**< PIPE_FORMAT_x */ unsigned first_level; unsigned last_level; @@ -331,7 +332,7 @@ struct pipe_vertex_element unsigned vertex_buffer_index:5; unsigned dst_offset:8; - unsigned src_format; /**< PIPE_FORMAT_* */ + enum pipe_format src_format; /**< PIPE_FORMAT_* */ }; diff --git a/src/mesa/pipe/p_winsys.h b/src/mesa/pipe/p_winsys.h index 5adca1d6fd..438e8bdb63 100644 --- a/src/mesa/pipe/p_winsys.h +++ b/src/mesa/pipe/p_winsys.h @@ -29,6 +29,8 @@ #define P_WINSYS_H +#include "p_format.h" + /** * \file * This is the interface that Gallium3D requires any window system @@ -90,7 +92,7 @@ struct pipe_winsys /** allocate a new surface (no context dependency) */ struct pipe_surface *(*surface_alloc)(struct pipe_winsys *ws, - unsigned format); + enum pipe_format format); void (*surface_release)(struct pipe_winsys *ws, struct pipe_surface **s); diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index 54b2076b4a..bdfd6228ef 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -51,7 +51,8 @@ * parameter or another function. */ static boolean -softpipe_is_format_supported( struct pipe_context *pipe, uint format ) +softpipe_is_format_supported( struct pipe_context *pipe, + enum pipe_format format ) { struct softpipe_context *softpipe = softpipe_context( pipe ); /* ask winsys if the format is supported */ diff --git a/src/mesa/pipe/softpipe/sp_quad_depth_test.c b/src/mesa/pipe/softpipe/sp_quad_depth_test.c index 00128fa528..93ea1196f9 100644 --- a/src/mesa/pipe/softpipe/sp_quad_depth_test.c +++ b/src/mesa/pipe/softpipe/sp_quad_depth_test.c @@ -54,7 +54,7 @@ sp_depth_test_quad(struct quad_stage *qs, struct quad_header *quad) { struct softpipe_context *softpipe = qs->softpipe; struct pipe_surface *ps = softpipe->framebuffer.zbuf; - const uint format = ps->format; + const enum pipe_format format = ps->format; unsigned bzzzz[QUAD_SIZE]; /**< Z values fetched from depth buffer */ unsigned qzzzz[QUAD_SIZE]; /**< Z values from the quad */ unsigned zmask = 0; diff --git a/src/mesa/pipe/softpipe/sp_tile_cache.c b/src/mesa/pipe/softpipe/sp_tile_cache.c index be5dd5c289..602b78ebe6 100644 --- a/src/mesa/pipe/softpipe/sp_tile_cache.c +++ b/src/mesa/pipe/softpipe/sp_tile_cache.c @@ -174,7 +174,8 @@ is_depth_stencil_surface(struct pipe_surface *ps) * Set pixels in a tile to the given clear color/value. */ static void -clear_tile(struct softpipe_cached_tile *tile, uint format, +clear_tile(struct softpipe_cached_tile *tile, + enum pipe_format format, const float clear_value[4]) { uint i, j; diff --git a/src/mesa/pipe/xlib/xm_winsys.c b/src/mesa/pipe/xlib/xm_winsys.c index 408797c688..976884ad52 100644 --- a/src/mesa/pipe/xlib/xm_winsys.c +++ b/src/mesa/pipe/xlib/xm_winsys.c @@ -301,7 +301,7 @@ xm_surface_pitch(struct pipe_winsys *winsys, unsigned cpp, unsigned width, * renderbuffers, etc. */ static struct pipe_surface * -xm_surface_alloc(struct pipe_winsys *ws, GLuint pipeFormat) +xm_surface_alloc(struct pipe_winsys *ws, enum pipe_format pipeFormat) { struct xmesa_surface *xms = CALLOC_STRUCT(xmesa_surface); @@ -379,7 +379,8 @@ xmesa_get_pipe_winsys(void) * can support any format. */ static boolean -xmesa_is_format_supported(struct softpipe_winsys *sws, uint format) +xmesa_is_format_supported(struct softpipe_winsys *sws, + enum pipe_format format) { struct xmesa_softpipe_winsys *xmws = xmesa_softpipe_winsys(sws); diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 1f0d1e6426..b4b2429a2a 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -55,7 +55,7 @@ static GLuint -color_value(GLuint pipeFormat, const GLfloat color[4]) +color_value(enum pipe_format pipeFormat, const GLfloat color[4]) { GLubyte r, g, b, a; @@ -81,7 +81,7 @@ color_value(GLuint pipeFormat, const GLfloat color[4]) static uint -depth_value(GLuint pipeFormat, GLfloat value) +depth_value(enum pipe_format pipeFormat, GLfloat value) { switch (pipeFormat) { case PIPE_FORMAT_Z16_UNORM: @@ -104,7 +104,7 @@ depth_value(GLuint pipeFormat, GLfloat value) static GLboolean -is_depth_stencil_format(GLuint pipeFormat) +is_depth_stencil_format(enum pipe_format pipeFormat) { switch (pipeFormat) { case PIPE_FORMAT_S8Z24_UNORM: diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 464cf5ced3..c0e41dbeec 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -456,7 +456,8 @@ make_texture(struct st_context *st, struct pipe_context *pipe = st->pipe; const struct gl_texture_format *mformat; struct pipe_texture *pt; - GLuint pipeFormat, cpp; + enum pipe_format pipeFormat; + GLuint cpp; GLenum baseFormat; baseFormat = _mesa_base_format(format); @@ -729,7 +730,7 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, * XXX probably move this to a re-usable place. */ static GLboolean -compatible_formats(GLenum format, GLenum type, GLuint pipeFormat) +compatible_formats(GLenum format, GLenum type, enum pipe_format pipeFormat) { static const GLuint one = 1; GLubyte littleEndian = *((GLubyte *) &one); diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 0ee5f45aae..cbda56b5c3 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -55,7 +55,8 @@ * Compute the renderbuffer's Red/Green/EtcBit fields from the pipe format. */ static int -init_renderbuffer_bits(struct st_renderbuffer *strb, uint pipeFormat) +init_renderbuffer_bits(struct st_renderbuffer *strb, + enum pipe_format pipeFormat) { struct pipe_format_info info; @@ -86,7 +87,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, { struct pipe_context *pipe = ctx->st->pipe; struct st_renderbuffer *strb = st_renderbuffer(rb); - const uint pipeFormat + const enum pipe_format pipeFormat = st_choose_pipe_format(pipe, internalFormat, GL_NONE, GL_NONE); GLuint cpp; GLbitfield flags = PIPE_SURFACE_FLAG_RENDER; /* want to render to surface */ diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c index 9e249a47a6..8d39e1bec6 100644 --- a/src/mesa/state_tracker/st_format.c +++ b/src/mesa/state_tracker/st_format.c @@ -99,9 +99,7 @@ format_size( * XXX temporary here */ GLboolean -st_get_format_info( - GLuint format, - struct pipe_format_info *pinfo ) +st_get_format_info(enum pipe_format format, struct pipe_format_info *pinfo) { if (pf_layout(format) == PIPE_FORMAT_LAYOUT_RGBAZS) { pipe_format_rgbazs_t info; @@ -222,10 +220,10 @@ st_get_format_info( * Return bytes per pixel for the given format. */ GLuint -st_sizeof_format(GLuint pipeFormat) +st_sizeof_format(enum pipe_format format) { struct pipe_format_info info; - if (!st_get_format_info( pipeFormat, &info )) { + if (!st_get_format_info( format, &info )) { assert( 0 ); return 0; } @@ -237,10 +235,10 @@ st_sizeof_format(GLuint pipeFormat) * Return bytes per pixel for the given format. */ GLenum -st_format_datatype(GLuint pipeFormat) +st_format_datatype(enum pipe_format format) { struct pipe_format_info info; - if (!st_get_format_info( pipeFormat, &info )) { + if (!st_get_format_info( format, &info )) { assert( 0 ); return 0; } @@ -248,7 +246,7 @@ st_format_datatype(GLuint pipeFormat) } -GLuint +enum pipe_format st_mesa_format_to_pipe_format(GLuint mesaFormat) { switch (mesaFormat) { diff --git a/src/mesa/state_tracker/st_format.h b/src/mesa/state_tracker/st_format.h index 23abc36edf..6ccf5536f9 100644 --- a/src/mesa/state_tracker/st_format.h +++ b/src/mesa/state_tracker/st_format.h @@ -26,13 +26,13 @@ **************************************************************************/ -#ifndef ST_CB_TEXIMAGE_H -#define ST_CB_TEXIMAGE_H +#ifndef ST_FORMAT_H +#define ST_FORMAT_H struct pipe_format_info { - GLuint format; + enum pipe_format format; GLenum base_format; GLenum datatype; GLubyte red_bits; @@ -47,21 +47,19 @@ struct pipe_format_info }; -extern GLboolean -st_get_format_info( - GLuint format, - struct pipe_format_info *pinfo ); +GLboolean +st_get_format_info(enum pipe_format format, struct pipe_format_info *pinfo); extern GLuint -st_sizeof_format(GLuint pipeFormat); +st_sizeof_format(enum pipe_format format); extern GLenum -st_format_datatype(GLuint pipeFormat); +st_format_datatype(enum pipe_format format); -extern GLuint +extern enum pipe_format st_mesa_format_to_pipe_format(GLuint mesaFormat); -- cgit v1.2.3 From f8f9580a2a1c89af1dc0e169b62440053d9d7e81 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Sun, 9 Dec 2007 18:26:26 +0000 Subject: Adapt for winsys interface changes. --- .../drivers/dri/intel_winsys/intel_winsys_pipe.c | 38 +++++++++++++--------- src/mesa/drivers/x11/xm_winsys.c | 7 ++-- src/mesa/pipe/draw/draw_vertex_fetch.c | 1 - src/mesa/pipe/i915simple/i915_texture.c | 3 +- src/mesa/pipe/softpipe/sp_texture.c | 4 ++- src/mesa/pipe/xlib/xm_winsys.c | 14 +++++--- src/mesa/state_tracker/st_cb_fbo.c | 2 +- 7 files changed, 43 insertions(+), 26 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c b/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c index 1799e9b901..86ea86a58f 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c @@ -105,42 +105,48 @@ intel_buffer_reference(struct pipe_winsys *winsys, /* Grabs the hardware lock! */ -static void intel_buffer_data(struct pipe_winsys *winsys, - struct pipe_buffer_handle *buf, - unsigned size, const void *data, - unsigned usage ) +static int intel_buffer_data(struct pipe_winsys *winsys, + struct pipe_buffer_handle *buf, + unsigned size, const void *data, + unsigned usage ) { driBOData( dri_bo(buf), size, data, 0 ); + return 0; } -static void intel_buffer_subdata(struct pipe_winsys *winsys, - struct pipe_buffer_handle *buf, - unsigned long offset, - unsigned long size, - const void *data) +static int intel_buffer_subdata(struct pipe_winsys *winsys, + struct pipe_buffer_handle *buf, + unsigned long offset, + unsigned long size, + const void *data) { driBOSubData( dri_bo(buf), offset, size, data ); + return 0; } -static void intel_buffer_get_subdata(struct pipe_winsys *winsys, - struct pipe_buffer_handle *buf, - unsigned long offset, - unsigned long size, - void *data) +static int intel_buffer_get_subdata(struct pipe_winsys *winsys, + struct pipe_buffer_handle *buf, + unsigned long offset, + unsigned long size, + void *data) { driBOGetSubData( dri_bo(buf), offset, size, data ); + return 0; } /* Pipe has no concept of pools. We choose the tex/region pool * for all buffers. */ static struct pipe_buffer_handle * -intel_buffer_create(struct pipe_winsys *winsys, unsigned flags) +intel_buffer_create(struct pipe_winsys *winsys, + unsigned alignment, + unsigned flags, + unsigned hint ) { struct _DriBufferObject *buffer; struct intel_pipe_winsys *iws = intel_pipe_winsys(winsys); driGenBuffers( iws->regionPool, - "pipe buffer", 1, &buffer, 64, 0, 0 ); + "pipe buffer", 1, &buffer, alignment, flags, hint ); return pipe_bo(buffer); } diff --git a/src/mesa/drivers/x11/xm_winsys.c b/src/mesa/drivers/x11/xm_winsys.c index f863cdbc15..dafbe96a1e 100644 --- a/src/mesa/drivers/x11/xm_winsys.c +++ b/src/mesa/drivers/x11/xm_winsys.c @@ -210,7 +210,10 @@ xm_get_name(struct pipe_winsys *pws) static struct pipe_buffer_handle * -xm_buffer_create(struct pipe_winsys *pws, unsigned alignment) +xm_buffer_create(struct pipe_winsys *pws, + unsigned alignment, + unsigned flags, + unsigned hint) { struct xm_buffer *buffer = CALLOC_STRUCT(xm_buffer); buffer->refcount = 1; @@ -258,7 +261,7 @@ xm_region_alloc(struct pipe_winsys *winsys, assert(region->pitch > 0); - region->buffer = winsys->buffer_create( winsys, alignment ) + region->buffer = winsys->buffer_create( winsys, alignment, 0, 0 ) ; /* NULL data --> just allocate the space */ diff --git a/src/mesa/pipe/draw/draw_vertex_fetch.c b/src/mesa/pipe/draw/draw_vertex_fetch.c index b51cff59f5..7d983ebd29 100644 --- a/src/mesa/pipe/draw/draw_vertex_fetch.c +++ b/src/mesa/pipe/draw/draw_vertex_fetch.c @@ -80,7 +80,6 @@ fetch_attrib4(const void *ptr, enum pipe_format format, float attrib[4]) break; case PIPE_FORMAT_A8R8G8B8_UNORM: - case PIPE_FORMAT_U_A8_R8_G8_B8: case PIPE_FORMAT_R8G8B8A8_UNORM: attrib[0] = (float) ((unsigned char *) ptr)[2] / 255.0f; attrib[1] = (float) ((unsigned char *) ptr)[1] / 255.0f; diff --git a/src/mesa/pipe/i915simple/i915_texture.c b/src/mesa/pipe/i915simple/i915_texture.c index 1ca2815dfb..59e8db8a95 100644 --- a/src/mesa/pipe/i915simple/i915_texture.c +++ b/src/mesa/pipe/i915simple/i915_texture.c @@ -496,7 +496,8 @@ i915_texture_create(struct pipe_context *pipe, struct pipe_texture **pt) if (i915->flags.is_i945 ? i945_miptree_layout(pipe, tex) : i915_miptree_layout(pipe, tex)) { tex->buffer = pipe->winsys->buffer_create(pipe->winsys, - PIPE_SURFACE_FLAG_TEXTURE); + PIPE_SURFACE_FLAG_TEXTURE, + 0, 0); if (tex->buffer) pipe->winsys->buffer_data(pipe->winsys, tex->buffer, diff --git a/src/mesa/pipe/softpipe/sp_texture.c b/src/mesa/pipe/softpipe/sp_texture.c index 2288c343bf..cfe9628184 100644 --- a/src/mesa/pipe/softpipe/sp_texture.c +++ b/src/mesa/pipe/softpipe/sp_texture.c @@ -382,7 +382,9 @@ softpipe_texture_create(struct pipe_context *pipe, struct pipe_texture **pt) if (softpipe_mipmap_tree_layout(pipe, spt)) { spt->buffer = pipe->winsys->buffer_create(pipe->winsys, - PIPE_SURFACE_FLAG_TEXTURE); + 32, + PIPE_SURFACE_FLAG_TEXTURE, + 0); if (spt->buffer) { pipe->winsys->buffer_data(pipe->winsys, spt->buffer, diff --git a/src/mesa/pipe/xlib/xm_winsys.c b/src/mesa/pipe/xlib/xm_winsys.c index 976884ad52..c347d1c2a3 100644 --- a/src/mesa/pipe/xlib/xm_winsys.c +++ b/src/mesa/pipe/xlib/xm_winsys.c @@ -155,7 +155,7 @@ xm_buffer_reference(struct pipe_winsys *pws, } } -static void +static int xm_buffer_data(struct pipe_winsys *pws, struct pipe_buffer_handle *buf, unsigned size, const void *data, unsigned usage ) { @@ -169,9 +169,10 @@ xm_buffer_data(struct pipe_winsys *pws, struct pipe_buffer_handle *buf, } if (data) memcpy(xm_buf->data, data, size); + return 0; } -static void +static int xm_buffer_subdata(struct pipe_winsys *pws, struct pipe_buffer_handle *buf, unsigned long offset, unsigned long size, const void *data) { @@ -180,9 +181,10 @@ xm_buffer_subdata(struct pipe_winsys *pws, struct pipe_buffer_handle *buf, assert(!xm_buf->userBuffer); assert(b); memcpy(b + offset, data, size); + return 0; } -static void +static int xm_buffer_get_subdata(struct pipe_winsys *pws, struct pipe_buffer_handle *buf, unsigned long offset, unsigned long size, void *data) { @@ -191,6 +193,7 @@ xm_buffer_get_subdata(struct pipe_winsys *pws, struct pipe_buffer_handle *buf, assert(!xm_buf->userBuffer); assert(b); memcpy(data, b + offset, size); + return 0; } @@ -255,7 +258,10 @@ xm_get_name(struct pipe_winsys *pws) static struct pipe_buffer_handle * -xm_buffer_create(struct pipe_winsys *pws, unsigned flags) +xm_buffer_create(struct pipe_winsys *pws, + unsigned alignment, + unsigned flags, + unsigned hints) { struct xm_buffer *buffer = CALLOC_STRUCT(xm_buffer); buffer->refcount = 1; diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index cbda56b5c3..10396c3feb 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -118,7 +118,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, pipe->winsys->buffer_reference(pipe->winsys, &strb->surface->buffer, NULL); - strb->surface->buffer = pipe->winsys->buffer_create(pipe->winsys, flags); + strb->surface->buffer = pipe->winsys->buffer_create(pipe->winsys, 32, flags, 0); if (!strb->surface->buffer) return GL_FALSE; /* out of memory, try s/w buffer? */ -- cgit v1.2.3 From 37484a387495f1241e5e1220243d6355f5333aca Mon Sep 17 00:00:00 2001 From: Michel Dänzer Date: Mon, 10 Dec 2007 17:31:52 +0100 Subject: Fix up some confusion wrt winsys->buffer_create alignment / flags parameters. intel_winsys works again. --- src/mesa/pipe/i915simple/i915_texture.c | 4 +--- src/mesa/pipe/softpipe/sp_texture.c | 5 +---- src/mesa/state_tracker/st_cb_fbo.c | 2 +- 3 files changed, 3 insertions(+), 8 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/pipe/i915simple/i915_texture.c b/src/mesa/pipe/i915simple/i915_texture.c index 59e8db8a95..fefd105adf 100644 --- a/src/mesa/pipe/i915simple/i915_texture.c +++ b/src/mesa/pipe/i915simple/i915_texture.c @@ -495,9 +495,7 @@ i915_texture_create(struct pipe_context *pipe, struct pipe_texture **pt) if (i915->flags.is_i945 ? i945_miptree_layout(pipe, tex) : i915_miptree_layout(pipe, tex)) { - tex->buffer = pipe->winsys->buffer_create(pipe->winsys, - PIPE_SURFACE_FLAG_TEXTURE, - 0, 0); + tex->buffer = pipe->winsys->buffer_create(pipe->winsys, 64, 0, 0); if (tex->buffer) pipe->winsys->buffer_data(pipe->winsys, tex->buffer, diff --git a/src/mesa/pipe/softpipe/sp_texture.c b/src/mesa/pipe/softpipe/sp_texture.c index cfe9628184..2dd1add6f7 100644 --- a/src/mesa/pipe/softpipe/sp_texture.c +++ b/src/mesa/pipe/softpipe/sp_texture.c @@ -381,10 +381,7 @@ softpipe_texture_create(struct pipe_context *pipe, struct pipe_texture **pt) sizeof(struct softpipe_texture) - sizeof(struct pipe_texture)); if (softpipe_mipmap_tree_layout(pipe, spt)) { - spt->buffer = pipe->winsys->buffer_create(pipe->winsys, - 32, - PIPE_SURFACE_FLAG_TEXTURE, - 0); + spt->buffer = pipe->winsys->buffer_create(pipe->winsys, 32, 0, 0); if (spt->buffer) { pipe->winsys->buffer_data(pipe->winsys, spt->buffer, diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 10396c3feb..36d25a576d 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -118,7 +118,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, pipe->winsys->buffer_reference(pipe->winsys, &strb->surface->buffer, NULL); - strb->surface->buffer = pipe->winsys->buffer_create(pipe->winsys, 32, flags, 0); + strb->surface->buffer = pipe->winsys->buffer_create(pipe->winsys, 32, 0, 0); if (!strb->surface->buffer) return GL_FALSE; /* out of memory, try s/w buffer? */ -- cgit v1.2.3 From 4f58d9af9addb1506a1b2abc7dd8012147772b78 Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 10 Dec 2007 13:48:09 -0700 Subject: Add 'type' parameter to is_format_supported() to specify texture vs. drawing surface, etc. Additional types may be added in the future. --- .../drivers/dri/intel_winsys/intel_winsys_pipe.c | 2 +- src/mesa/pipe/i915simple/i915_context.c | 77 ++++++++---------- src/mesa/pipe/p_context.h | 3 +- src/mesa/pipe/p_defines.h | 7 +- src/mesa/pipe/softpipe/sp_context.c | 24 ++++-- src/mesa/pipe/softpipe/sp_winsys.h | 16 ++-- src/mesa/pipe/xlib/xm_winsys.c | 26 +----- src/mesa/state_tracker/st_cb_drawpixels.c | 4 +- src/mesa/state_tracker/st_cb_fbo.c | 11 ++- src/mesa/state_tracker/st_cb_fbo.h | 3 +- src/mesa/state_tracker/st_format.c | 95 +++++++++++----------- src/mesa/state_tracker/st_format.h | 2 +- src/mesa/state_tracker/st_framebuffer.c | 29 +++---- 13 files changed, 142 insertions(+), 157 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c b/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c index 86ea86a58f..9c643dd0ba 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c @@ -191,7 +191,7 @@ intel_i915_surface_pitch(struct pipe_winsys *winsys, */ /* XXX is the pitch different for textures vs. drawables? */ - if (flags & PIPE_SURFACE_FLAG_TEXTURE) /* or PIPE_SURFACE_FLAG_RENDER? */ + if (1/*flags & PIPE_SURFACE_FLAG_TEXTURE*/) /* or PIPE_SURFACE_FLAG_RENDER? */ return ((cpp * width + 63) & ~63) / cpp; else return ((cpp * width + 63) & ~63) / cpp; diff --git a/src/mesa/pipe/i915simple/i915_context.c b/src/mesa/pipe/i915simple/i915_context.c index b915a67790..f505ff6ae6 100644 --- a/src/mesa/pipe/i915simple/i915_context.c +++ b/src/mesa/pipe/i915simple/i915_context.c @@ -39,72 +39,61 @@ /** - * Query format support. - * If we find texture and drawable support differs, add a selector - * parameter or another function. + * Query format support for creating a texture, drawing surface, etc. + * \param format the format to test + * \param type one of PIPE_TEXTURE, PIPE_SURFACE, PIPE_SCREEN_SURFACE */ static boolean i915_is_format_supported( struct pipe_context *pipe, - enum pipe_format format ) + enum pipe_format format, uint type ) { -#if 0 - /* XXX: This is broken -- rewrite if still needed. */ - static const unsigned tex_supported[] = { + static const enum pipe_format tex_supported[] = { PIPE_FORMAT_R8G8B8A8_UNORM, PIPE_FORMAT_A8R8G8B8_UNORM, PIPE_FORMAT_R5G6B5_UNORM, PIPE_FORMAT_U_L8, PIPE_FORMAT_U_A8, PIPE_FORMAT_U_I8, - PIPE_FORMAT_U_L8_A8, + PIPE_FORMAT_U_A8_L8, PIPE_FORMAT_YCBCR, PIPE_FORMAT_YCBCR_REV, PIPE_FORMAT_S8Z24_UNORM, + PIPE_FORMAT_NONE /* list terminator */ }; - - - /* Actually a lot more than this - add later: - */ - static const unsigned render_supported[] = { + static const enum pipe_format surface_supported[] = { PIPE_FORMAT_A8R8G8B8_UNORM, PIPE_FORMAT_R5G6B5_UNORM, - }; - - /* - */ - static const unsigned z_stencil_supported[] = { - PIPE_FORMAT_Z16_UNORM, - PIPE_FORMAT_Z32_UNORM, PIPE_FORMAT_S8Z24_UNORM, + PIPE_FORMAT_R16G16B16A16_SNORM, + PIPE_FORMAT_NONE /* list terminator */ + }; + static const enum pipe_format screen_surface_supported[] = { + PIPE_FORMAT_A8R8G8B8_UNORM, + PIPE_FORMAT_NONE /* list terminator */ }; + const enum pipe_format *list; + uint i; switch (type) { - case PIPE_RENDER_FORMAT: - *numFormats = Elements(render_supported); - return render_supported; - - case PIPE_TEX_FORMAT: - *numFormats = Elements(tex_supported); - return render_supported; - - case PIPE_Z_STENCIL_FORMAT: - *numFormats = Elements(render_supported); - return render_supported; - + case PIPE_TEXTURE: + list = tex_supported; + break; + case PIPE_SURFACE: + list = surface_supported; + break; + case PIPE_SCREEN_SURFACE: + list = screen_surface_supported; + break; default: - *numFormats = 0; - return NULL; + assert(0); } -#else - switch( format ) { - case PIPE_FORMAT_A8R8G8B8_UNORM: - case PIPE_FORMAT_R5G6B5_UNORM: - case PIPE_FORMAT_S8Z24_UNORM: - return TRUE; - default: - return FALSE; - }; -#endif + + for (i = 0; list[i] != PIPE_FORMAT_NONE; i++) { + if (list[i] == format) + return TRUE; + } + + return FALSE; } diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index b3a2122ade..00379fbacf 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -50,8 +50,9 @@ struct pipe_context { /* * Queries */ + /** type is one of PIPE_SURFACE, PIPE_TEXTURE, etc. */ boolean (*is_format_supported)( struct pipe_context *pipe, - enum pipe_format format ); + enum pipe_format format, uint type ); const char *(*get_name)( struct pipe_context *pipe ); diff --git a/src/mesa/pipe/p_defines.h b/src/mesa/pipe/p_defines.h index 8dce3aba90..d3afef95b4 100644 --- a/src/mesa/pipe/p_defines.h +++ b/src/mesa/pipe/p_defines.h @@ -161,10 +161,11 @@ #define PIPE_TEX_FACE_MAX 6 /** - * Surface flags + * Surfaces, textures, etc. (others may be added) */ -#define PIPE_SURFACE_FLAG_TEXTURE 0x1 -#define PIPE_SURFACE_FLAG_RENDER 0x2 +#define PIPE_TEXTURE 1 +#define PIPE_SURFACE 2 /**< user-created surfaces */ +#define PIPE_SCREEN_SURFACE 3 /**< On-screen front/back colorbuffer */ /** diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index 809b165f45..8b8e04c2f9 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -46,17 +46,29 @@ /** - * Query format support. - * If we find texture and drawable support differs, add a selector - * parameter or another function. + * Query format support for creating a texture, drawing surface, etc. + * \param format the format to test + * \param type one of PIPE_TEXTURE, PIPE_SURFACE, PIPE_SCREEN_SURFACE */ static boolean softpipe_is_format_supported( struct pipe_context *pipe, - enum pipe_format format ) + enum pipe_format format, uint type ) { struct softpipe_context *softpipe = softpipe_context( pipe ); - /* ask winsys if the format is supported */ - return softpipe->winsys->is_format_supported( softpipe->winsys, format ); + + switch (type) { + case PIPE_TEXTURE: + /* softpipe supports all texture formats */ + return TRUE; + case PIPE_SURFACE: + /* softpipe supports all (off-screen) surface formats */ + return TRUE; + case PIPE_SCREEN_SURFACE: + return softpipe->winsys->is_format_supported( softpipe->winsys, format ); + default: + assert(0); + return FALSE; + } } diff --git a/src/mesa/pipe/softpipe/sp_winsys.h b/src/mesa/pipe/softpipe/sp_winsys.h index 1912e59b9f..cbf64ebb85 100644 --- a/src/mesa/pipe/softpipe/sp_winsys.h +++ b/src/mesa/pipe/softpipe/sp_winsys.h @@ -25,21 +25,23 @@ * **************************************************************************/ +/* This is the interface that softpipe requires any window system + * hosting it to implement. This is the only include file in softpipe + * which is public. + */ + + #ifndef SP_WINSYS_H #define SP_WINSYS_H -#include "pipe/p_compiler.h" // for boolean +#include "pipe/p_compiler.h" /* for boolean */ -/* This is the interface that softpipe requires any window system - * hosting it to implement. This is the only include file in softpipe - * which is public. - */ - struct softpipe_winsys { + /** test if the given format is supported for front/back color bufs */ boolean (*is_format_supported)( struct softpipe_winsys *sws, - uint format ); + enum pipe_format format ); }; diff --git a/src/mesa/pipe/xlib/xm_winsys.c b/src/mesa/pipe/xlib/xm_winsys.c index c347d1c2a3..68f9c39116 100644 --- a/src/mesa/pipe/xlib/xm_winsys.c +++ b/src/mesa/pipe/xlib/xm_winsys.c @@ -71,7 +71,7 @@ struct xmesa_surface struct xmesa_softpipe_winsys { struct softpipe_winsys spws; - uint pixelformat; + enum pipe_format pixelformat; }; @@ -377,35 +377,17 @@ xmesa_get_pipe_winsys(void) /** + * Called via softpipe_winsys->is_format_supported(). + * This function is only called to test formats for front/back color surfaces. * The winsys being queried will have been created at glXCreateContext * time, with a pixel format corresponding to the context's visual. - * - * XXX we should pass a flag indicating if the format is going to be - * use for a drawing surface vs. a texture. In the later case, we - * can support any format. */ static boolean xmesa_is_format_supported(struct softpipe_winsys *sws, enum pipe_format format) { struct xmesa_softpipe_winsys *xmws = xmesa_softpipe_winsys(sws); - - if (format == xmws->pixelformat) { - return TRUE; - } - else { - /* non-color / window surface format */ - switch (format) { - case PIPE_FORMAT_R16G16B16A16_SNORM: - case PIPE_FORMAT_S8Z24_UNORM: - case PIPE_FORMAT_U_S8: - case PIPE_FORMAT_Z16_UNORM: - case PIPE_FORMAT_Z32_UNORM: - return TRUE; - default: - return FALSE; - } - } + return (format == xmws->pixelformat); } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index c0e41dbeec..0179000353 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -993,13 +993,13 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, int row, col; /* find a texture format we know */ - if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_I8 )) { + if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_I8, PIPE_TEXTURE )) { format = PIPE_FORMAT_U_I8; internal_format = GL_INTENSITY8; cpp = 1; comp = 0; } - else if (pipe->is_format_supported( pipe, PIPE_FORMAT_A8R8G8B8_UNORM )) { + else if (pipe->is_format_supported( pipe, PIPE_FORMAT_A8R8G8B8_UNORM, PIPE_TEXTURE )) { format = PIPE_FORMAT_A8R8G8B8_UNORM; internal_format = GL_RGBA8; cpp = 4; diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 36d25a576d..6e9e7e3a24 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -87,12 +87,14 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, { struct pipe_context *pipe = ctx->st->pipe; struct st_renderbuffer *strb = st_renderbuffer(rb); + uint type = strb->screenSurface ? PIPE_SCREEN_SURFACE : PIPE_SURFACE; const enum pipe_format pipeFormat - = st_choose_pipe_format(pipe, internalFormat, GL_NONE, GL_NONE); + = st_choose_pipe_format(pipe, internalFormat, GL_NONE, GL_NONE, type); GLuint cpp; - GLbitfield flags = PIPE_SURFACE_FLAG_RENDER; /* want to render to surface */ + GLbitfield flags = 0x0; /* XXX needed? */ cpp = init_renderbuffer_bits(strb, pipeFormat); + assert(cpp); if (strb->surface && strb->surface->format != pipeFormat) { /* need to change surface types, free this surface */ @@ -201,9 +203,11 @@ st_new_renderbuffer(GLcontext *ctx, GLuint name) /** * Allocate a renderbuffer for a an on-screen window (not a user-created * renderbuffer). The window system code determines the internal format. + * \param screenSurface indicates if the renderbuffer is a front/back color + * buffer that'll be displayed/copied to the screen */ struct gl_renderbuffer * -st_new_renderbuffer_fb(GLenum intFormat) +st_new_renderbuffer_fb(GLenum intFormat, GLboolean screenSurface) { struct st_renderbuffer *strb; @@ -216,6 +220,7 @@ st_new_renderbuffer_fb(GLenum intFormat) _mesa_init_renderbuffer(&strb->Base, 0); strb->Base.ClassID = 0x4242; /* just a unique value */ strb->Base.InternalFormat = intFormat; + strb->screenSurface = screenSurface; switch (intFormat) { case GL_RGB5: diff --git a/src/mesa/state_tracker/st_cb_fbo.h b/src/mesa/state_tracker/st_cb_fbo.h index 2280441db5..bd85bfc549 100644 --- a/src/mesa/state_tracker/st_cb_fbo.h +++ b/src/mesa/state_tracker/st_cb_fbo.h @@ -39,6 +39,7 @@ struct st_renderbuffer { struct gl_renderbuffer Base; struct pipe_surface *surface; + GLboolean screenSurface; /**< A front/back colorbuffer? */ }; @@ -50,7 +51,7 @@ st_renderbuffer(struct gl_renderbuffer *rb) extern struct gl_renderbuffer * -st_new_renderbuffer_fb(GLenum intFormat); +st_new_renderbuffer_fb(GLenum intFormat, GLboolean screen_surface); extern void diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c index 8d39e1bec6..c292a975f3 100644 --- a/src/mesa/state_tracker/st_format.c +++ b/src/mesa/state_tracker/st_format.c @@ -276,10 +276,9 @@ st_mesa_format_to_pipe_format(GLuint mesaFormat) * Find an RGBA format supported by the context/winsys. */ static GLuint -default_rgba_format( - struct pipe_context *pipe ) +default_rgba_format(struct pipe_context *pipe, uint type) { - static const uint colorFormats[] = { + static const enum pipe_format colorFormats[] = { PIPE_FORMAT_R8G8B8A8_UNORM, PIPE_FORMAT_A8R8G8B8_UNORM, PIPE_FORMAT_B8G8R8A8_UNORM, @@ -287,7 +286,7 @@ default_rgba_format( }; uint i; for (i = 0; i < Elements(colorFormats); i++) { - if (pipe->is_format_supported( pipe, colorFormats[i] )) { + if (pipe->is_format_supported( pipe, colorFormats[i], type )) { return colorFormats[i]; } } @@ -299,10 +298,9 @@ default_rgba_format( * Search list of formats for first RGBA format with >8 bits/channel. */ static GLuint -default_deep_rgba_format( - struct pipe_context *pipe ) +default_deep_rgba_format(struct pipe_context *pipe, uint type) { - if (pipe->is_format_supported( pipe, PIPE_FORMAT_R16G16B16A16_SNORM )) { + if (pipe->is_format_supported(pipe, PIPE_FORMAT_R16G16B16A16_SNORM, type)) { return PIPE_FORMAT_R16G16B16A16_SNORM; } return PIPE_FORMAT_NONE; @@ -313,10 +311,9 @@ default_deep_rgba_format( * Find an Z format supported by the context/winsys. */ static GLuint -default_depth_format( - struct pipe_context *pipe ) +default_depth_format(struct pipe_context *pipe, uint type) { - static const uint zFormats[] = { + static const enum pipe_format zFormats[] = { PIPE_FORMAT_Z16_UNORM, PIPE_FORMAT_Z32_UNORM, PIPE_FORMAT_S8Z24_UNORM, @@ -324,7 +321,7 @@ default_depth_format( }; uint i; for (i = 0; i < Elements(zFormats); i++) { - if (pipe->is_format_supported( pipe, zFormats[i] )) { + if (pipe->is_format_supported( pipe, zFormats[i], type )) { return zFormats[i]; } } @@ -348,67 +345,71 @@ default_depth_format( */ GLuint st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat, - GLenum format, GLenum type) + GLenum format, GLenum type, uint surfType) { + assert(surfType == PIPE_TEXTURE || + surfType == PIPE_SURFACE || + surfType == PIPE_SCREEN_SURFACE); + switch (internalFormat) { case 4: case GL_RGBA: case GL_COMPRESSED_RGBA: if (format == GL_BGRA) { if (type == GL_UNSIGNED_BYTE || type == GL_UNSIGNED_INT_8_8_8_8_REV) { - if (pipe->is_format_supported( pipe, PIPE_FORMAT_A8R8G8B8_UNORM )) + if (pipe->is_format_supported( pipe, PIPE_FORMAT_A8R8G8B8_UNORM, surfType )) return PIPE_FORMAT_A8R8G8B8_UNORM; } else if (type == GL_UNSIGNED_SHORT_4_4_4_4_REV) { - if (pipe->is_format_supported( pipe, PIPE_FORMAT_A4R4G4B4_UNORM )) + if (pipe->is_format_supported( pipe, PIPE_FORMAT_A4R4G4B4_UNORM, surfType )) return PIPE_FORMAT_A4R4G4B4_UNORM; } else if (type == GL_UNSIGNED_SHORT_1_5_5_5_REV) { - if (pipe->is_format_supported( pipe, PIPE_FORMAT_A1R5G5B5_UNORM )) + if (pipe->is_format_supported( pipe, PIPE_FORMAT_A1R5G5B5_UNORM, surfType )) return PIPE_FORMAT_A1R5G5B5_UNORM; } } - return default_rgba_format( pipe ); + return default_rgba_format( pipe, surfType ); case 3: case GL_RGB: case GL_COMPRESSED_RGB: if (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) { - if (pipe->is_format_supported( pipe, PIPE_FORMAT_R5G6B5_UNORM )) + if (pipe->is_format_supported( pipe, PIPE_FORMAT_R5G6B5_UNORM, surfType )) return PIPE_FORMAT_R5G6B5_UNORM; } - return default_rgba_format( pipe ); + return default_rgba_format( pipe, surfType ); case GL_RGBA8: case GL_RGB10_A2: case GL_RGBA12: - return default_rgba_format( pipe ); + return default_rgba_format( pipe, surfType ); case GL_RGBA16: - return default_deep_rgba_format( pipe ); + return default_deep_rgba_format( pipe, surfType ); case GL_RGBA4: case GL_RGBA2: - if (pipe->is_format_supported( pipe, PIPE_FORMAT_A4R4G4B4_UNORM )) + if (pipe->is_format_supported( pipe, PIPE_FORMAT_A4R4G4B4_UNORM, surfType )) return PIPE_FORMAT_A4R4G4B4_UNORM; - return default_rgba_format( pipe ); + return default_rgba_format( pipe, surfType ); case GL_RGB5_A1: - if (pipe->is_format_supported( pipe, PIPE_FORMAT_A1R5G5B5_UNORM )) + if (pipe->is_format_supported( pipe, PIPE_FORMAT_A1R5G5B5_UNORM, surfType )) return PIPE_FORMAT_A1R5G5B5_UNORM; - return default_rgba_format( pipe ); + return default_rgba_format( pipe, surfType ); case GL_RGB8: case GL_RGB10: case GL_RGB12: case GL_RGB16: - return default_rgba_format( pipe ); + return default_rgba_format( pipe, surfType ); case GL_RGB5: case GL_RGB4: case GL_R3_G3_B2: - if (pipe->is_format_supported( pipe, PIPE_FORMAT_A1R5G5B5_UNORM )) + if (pipe->is_format_supported( pipe, PIPE_FORMAT_A1R5G5B5_UNORM, surfType )) return PIPE_FORMAT_A1R5G5B5_UNORM; - return default_rgba_format( pipe ); + return default_rgba_format( pipe, surfType ); case GL_ALPHA: case GL_ALPHA4: @@ -416,9 +417,9 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat, case GL_ALPHA12: case GL_ALPHA16: case GL_COMPRESSED_ALPHA: - if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A8 )) + if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A8, surfType )) return PIPE_FORMAT_U_A8; - return default_rgba_format( pipe ); + return default_rgba_format( pipe, surfType ); case 1: case GL_LUMINANCE: @@ -427,9 +428,9 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat, case GL_LUMINANCE12: case GL_LUMINANCE16: case GL_COMPRESSED_LUMINANCE: - if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A8 )) + if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A8, surfType )) return PIPE_FORMAT_U_A8; - return default_rgba_format( pipe ); + return default_rgba_format( pipe, surfType ); case 2: case GL_LUMINANCE_ALPHA: @@ -440,9 +441,9 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat, case GL_LUMINANCE12_ALPHA12: case GL_LUMINANCE16_ALPHA16: case GL_COMPRESSED_LUMINANCE_ALPHA: - if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A8_L8 )) + if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A8_L8, surfType )) return PIPE_FORMAT_U_A8_L8; - return default_rgba_format( pipe ); + return default_rgba_format( pipe, surfType ); case GL_INTENSITY: case GL_INTENSITY4: @@ -450,17 +451,17 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat, case GL_INTENSITY12: case GL_INTENSITY16: case GL_COMPRESSED_INTENSITY: - if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_I8 )) + if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_I8, surfType )) return PIPE_FORMAT_U_I8; - return default_rgba_format( pipe ); + return default_rgba_format( pipe, surfType ); case GL_YCBCR_MESA: if (type == GL_UNSIGNED_SHORT_8_8_MESA || type == GL_UNSIGNED_BYTE) { - if (pipe->is_format_supported( pipe, PIPE_FORMAT_YCBCR )) + if (pipe->is_format_supported( pipe, PIPE_FORMAT_YCBCR, surfType )) return PIPE_FORMAT_YCBCR; } else { - if (pipe->is_format_supported( pipe, PIPE_FORMAT_YCBCR_REV )) + if (pipe->is_format_supported( pipe, PIPE_FORMAT_YCBCR_REV, surfType )) return PIPE_FORMAT_YCBCR_REV; } return PIPE_FORMAT_NONE; @@ -489,40 +490,40 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat, #endif case GL_DEPTH_COMPONENT16: - if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z16_UNORM )) + if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z16_UNORM, surfType )) return PIPE_FORMAT_Z16_UNORM; /* fall-through */ case GL_DEPTH_COMPONENT24: - if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8Z24_UNORM )) + if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8Z24_UNORM, surfType )) return PIPE_FORMAT_S8Z24_UNORM; - if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24S8_UNORM )) + if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24S8_UNORM, surfType )) return PIPE_FORMAT_Z24S8_UNORM; /* fall-through */ case GL_DEPTH_COMPONENT32: - if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z32_UNORM )) + if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z32_UNORM, surfType )) return PIPE_FORMAT_Z32_UNORM; /* fall-through */ case GL_DEPTH_COMPONENT: - return default_depth_format( pipe ); + return default_depth_format( pipe, surfType ); case GL_STENCIL_INDEX: case GL_STENCIL_INDEX1_EXT: case GL_STENCIL_INDEX4_EXT: case GL_STENCIL_INDEX8_EXT: case GL_STENCIL_INDEX16_EXT: - if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_S8 )) + if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_S8, surfType )) return PIPE_FORMAT_U_S8; - if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8Z24_UNORM )) + if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8Z24_UNORM, surfType )) return PIPE_FORMAT_S8Z24_UNORM; - if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24S8_UNORM )) + if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24S8_UNORM, surfType )) return PIPE_FORMAT_Z24S8_UNORM; return PIPE_FORMAT_NONE; case GL_DEPTH_STENCIL_EXT: case GL_DEPTH24_STENCIL8_EXT: - if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8Z24_UNORM )) + if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8Z24_UNORM, surfType )) return PIPE_FORMAT_S8Z24_UNORM; - if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24S8_UNORM )) + if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24S8_UNORM, surfType )) return PIPE_FORMAT_Z24S8_UNORM; return PIPE_FORMAT_NONE; diff --git a/src/mesa/state_tracker/st_format.h b/src/mesa/state_tracker/st_format.h index 6ccf5536f9..ebff7c5b91 100644 --- a/src/mesa/state_tracker/st_format.h +++ b/src/mesa/state_tracker/st_format.h @@ -65,7 +65,7 @@ st_mesa_format_to_pipe_format(GLuint mesaFormat); extern GLuint st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat, - GLenum format, GLenum type); + GLenum format, GLenum type, uint surfType); extern const struct gl_texture_format * diff --git a/src/mesa/state_tracker/st_framebuffer.c b/src/mesa/state_tracker/st_framebuffer.c index 8633f431b2..454306b874 100644 --- a/src/mesa/state_tracker/st_framebuffer.c +++ b/src/mesa/state_tracker/st_framebuffer.c @@ -51,19 +51,21 @@ struct st_framebuffer *st_create_framebuffer( const __GLcontextModes *visual, /* fake frontbuffer */ /* XXX allocation should only happen in the unusual case it's actually needed */ - struct gl_renderbuffer *rb = st_new_renderbuffer_fb(rgbFormat); + struct gl_renderbuffer *rb + = st_new_renderbuffer_fb(rgbFormat, GL_TRUE); _mesa_add_renderbuffer(&stfb->Base, BUFFER_FRONT_LEFT, rb); } if (visual->doubleBufferMode) { - struct gl_renderbuffer *rb = st_new_renderbuffer_fb(rgbFormat); + struct gl_renderbuffer *rb + = st_new_renderbuffer_fb(rgbFormat, GL_TRUE); _mesa_add_renderbuffer(&stfb->Base, BUFFER_BACK_LEFT, rb); } if (visual->depthBits == 24 && visual->stencilBits == 8) { /* combined depth/stencil buffer */ struct gl_renderbuffer *depthStencilRb - = st_new_renderbuffer_fb(GL_DEPTH24_STENCIL8_EXT); + = st_new_renderbuffer_fb(GL_DEPTH24_STENCIL8_EXT, GL_FALSE); /* note: bind RB to two attachment points */ _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthStencilRb); _mesa_add_renderbuffer(&stfb->Base, BUFFER_STENCIL, depthStencilRb); @@ -74,47 +76,36 @@ struct st_framebuffer *st_create_framebuffer( const __GLcontextModes *visual, if (visual->depthBits == 32) { /* 32-bit depth buffer */ struct gl_renderbuffer *depthRb - = st_new_renderbuffer_fb(GL_DEPTH_COMPONENT32); + = st_new_renderbuffer_fb(GL_DEPTH_COMPONENT32, GL_FALSE); _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb); } else if (visual->depthBits == 24) { /* 24-bit depth buffer, ignore stencil bits */ struct gl_renderbuffer *depthRb - = st_new_renderbuffer_fb(GL_DEPTH24_STENCIL8_EXT); + = st_new_renderbuffer_fb(GL_DEPTH24_STENCIL8_EXT, GL_FALSE); _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb); } else if (visual->depthBits > 0) { /* 16-bit depth buffer */ struct gl_renderbuffer *depthRb - = st_new_renderbuffer_fb(GL_DEPTH_COMPONENT16); + = st_new_renderbuffer_fb(GL_DEPTH_COMPONENT16, GL_FALSE); _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb); } if (visual->stencilBits > 0) { /* 8-bit stencil */ struct gl_renderbuffer *stencilRb - = st_new_renderbuffer_fb(GL_STENCIL_INDEX8_EXT); + = st_new_renderbuffer_fb(GL_STENCIL_INDEX8_EXT, GL_FALSE); _mesa_add_renderbuffer(&stfb->Base, BUFFER_STENCIL, stencilRb); } } -#if 0 if (visual->accumRedBits > 0) { /* 16-bit/channel accum */ struct gl_renderbuffer *accumRb - = st_new_renderbuffer_fb(GL_RGBA16); + = st_new_renderbuffer_fb(GL_RGBA16, GL_FALSE); _mesa_add_renderbuffer(&stfb->Base, BUFFER_ACCUM, accumRb); } -#endif - - /* now add any/all software-based renderbuffers we may need */ - _mesa_add_soft_renderbuffers(&stfb->Base, - GL_FALSE, /* never sw color */ - GL_FALSE, /* never sw depth */ - GL_FALSE, /* stencil */ - visual->accumRedBits > 0, - GL_FALSE, /* never sw alpha */ - GL_FALSE /* never sw aux */ ); } stfb->Base.Initialized = GL_TRUE; -- cgit v1.2.3 From c9f9c5098042e4f200efc3d25447a5a8b7e69b36 Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 10 Dec 2007 17:25:54 -0700 Subject: XXX comments about some hard-coded values that need to be fixed --- src/mesa/state_tracker/st_cb_fbo.c | 1 + src/mesa/state_tracker/st_draw.c | 1 + 2 files changed, 2 insertions(+) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 6e9e7e3a24..ef6aec6e88 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -120,6 +120,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, pipe->winsys->buffer_reference(pipe->winsys, &strb->surface->buffer, NULL); + /* XXX don't hard-code magic 32 here */ strb->surface->buffer = pipe->winsys->buffer_create(pipe->winsys, 32, 0, 0); if (!strb->surface->buffer) return GL_FALSE; /* out of memory, try s/w buffer? */ diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index 24bb4823bc..274ae86a3e 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -199,6 +199,7 @@ static void create_default_attribs_buffer(struct st_context *st) { struct pipe_context *pipe = st->pipe; + /* XXX don't hardcode magic 32 here */ st->default_attrib_buffer = pipe->winsys->buffer_create( pipe->winsys, 32, 0, 0 ); } -- cgit v1.2.3 From 12363674e5aa39b780020339038186b7715bd4b2 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Tue, 11 Dec 2007 01:14:38 +0000 Subject: Add surface storage allocation function to winsys interface. --- .../drivers/dri/intel_winsys/intel_winsys_pipe.c | 72 +++++++++++++++------- src/mesa/pipe/i915simple/i915_surface.c | 3 +- src/mesa/pipe/p_winsys.h | 18 +++--- src/mesa/pipe/softpipe/sp_surface.c | 4 +- src/mesa/pipe/xlib/xm_winsys.c | 41 +++++++++--- src/mesa/state_tracker/st_cb_fbo.c | 36 ++++------- 6 files changed, 108 insertions(+), 66 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c b/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c index 9c643dd0ba..c7b519d95b 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c @@ -178,32 +178,11 @@ intel_flush_frontbuffer( struct pipe_winsys *winsys, } -static unsigned -intel_i915_surface_pitch(struct pipe_winsys *winsys, - unsigned cpp, unsigned width, unsigned flags) -{ - /* Choose a pitch to match hardware requirements - requires 64 byte - * alignment of render targets. - * - * XXX: is this ok for textures?? - * clearly want to be able to render to textures under some - * circumstances, but maybe not always a requirement. - */ - - /* XXX is the pitch different for textures vs. drawables? */ - if (1/*flags & PIPE_SURFACE_FLAG_TEXTURE*/) /* or PIPE_SURFACE_FLAG_RENDER? */ - return ((cpp * width + 63) & ~63) / cpp; - else - return ((cpp * width + 63) & ~63) / cpp; -} - - static struct pipe_surface * -intel_i915_surface_alloc(struct pipe_winsys *winsys, enum pipe_format format) +intel_i915_surface_alloc(struct pipe_winsys *winsys) { struct pipe_surface *surf = CALLOC_STRUCT(pipe_surface); if (surf) { - surf->format = format; surf->refcount = 1; surf->winsys = winsys; } @@ -211,6 +190,53 @@ intel_i915_surface_alloc(struct pipe_winsys *winsys, enum pipe_format format) } +/** + * Round n up to next multiple. + */ +static INLINE unsigned +round_up(unsigned n, unsigned multiple) +{ + return (n + multiple - 1) & ~(multiple - 1); +} + +/** + * Copied from xm_winsys.c + */ +static int +intel_i915_surface_alloc_storage(struct pipe_winsys *winsys, + struct pipe_surface *surf, + unsigned width, unsigned height, + enum pipe_format format, + unsigned flags) +{ + const unsigned alignment = 64; + int ret; + + surf->width = width; + surf->height = height; + surf->format = format; + surf->cpp = pf_get_size(format); + surf->pitch = round_up(width, alignment / surf->cpp); + + assert(!surf->buffer); + surf->buffer = winsys->buffer_create(winsys, alignment, 0, 0); + if(!surf->buffer) + return -1; + + ret = winsys->buffer_data(winsys, + surf->buffer, + surf->pitch * surf->cpp * height, + NULL, + 0); + if(ret) { + winsys->buffer_reference(winsys, &surf->buffer, NULL); + return ret; + } + + return 0; +} + + static void intel_i915_surface_release(struct pipe_winsys *winsys, struct pipe_surface **s) { @@ -265,8 +291,8 @@ intel_create_pipe_winsys( int fd ) iws->winsys.flush_frontbuffer = intel_flush_frontbuffer; iws->winsys.printf = intel_printf; iws->winsys.get_name = intel_get_name; - iws->winsys.surface_pitch = intel_i915_surface_pitch; iws->winsys.surface_alloc = intel_i915_surface_alloc; + iws->winsys.surface_alloc_storage = intel_i915_surface_alloc_storage; iws->winsys.surface_release = intel_i915_surface_release; if (fd) diff --git a/src/mesa/pipe/i915simple/i915_surface.c b/src/mesa/pipe/i915simple/i915_surface.c index bd6fd32704..f93a75b0f0 100644 --- a/src/mesa/pipe/i915simple/i915_surface.c +++ b/src/mesa/pipe/i915simple/i915_surface.c @@ -238,11 +238,12 @@ i915_get_tex_surface(struct pipe_context *pipe, assert(zslice == 0); } - ps = pipe->winsys->surface_alloc(pipe->winsys, pt->format); + ps = pipe->winsys->surface_alloc(pipe->winsys); if (ps) { assert(ps->format); assert(ps->refcount); pipe->winsys->buffer_reference(pipe->winsys, &ps->buffer, tex->buffer); + ps->format = pt->format; ps->cpp = pt->cpp; ps->width = pt->width[level]; ps->height = pt->height[level]; diff --git a/src/mesa/pipe/p_winsys.h b/src/mesa/pipe/p_winsys.h index 1418af6918..aa9362ec0b 100644 --- a/src/mesa/pipe/p_winsys.h +++ b/src/mesa/pipe/p_winsys.h @@ -76,16 +76,16 @@ struct pipe_winsys const char *, ... ); - /** - * flags is bitmask of PIPE_SURFACE_FLAG_RENDER, PIPE_SURFACE_FLAG_TEXTURE - */ - unsigned (*surface_pitch)(struct pipe_winsys *ws, unsigned cpp, - unsigned with, unsigned flags); - /** allocate a new surface (no context dependency) */ - struct pipe_surface *(*surface_alloc)(struct pipe_winsys *ws, - enum pipe_format format); - + struct pipe_surface *(*surface_alloc)(struct pipe_winsys *ws); + + /** allocate storage for a pipe_surface */ + int (*surface_alloc_storage)(struct pipe_winsys *ws, + struct pipe_surface *surf, + unsigned width, unsigned height, + enum pipe_format format, + unsigned flags); + void (*surface_release)(struct pipe_winsys *ws, struct pipe_surface **s); diff --git a/src/mesa/pipe/softpipe/sp_surface.c b/src/mesa/pipe/softpipe/sp_surface.c index 55b8b85ef2..3ef3db9f1f 100644 --- a/src/mesa/pipe/softpipe/sp_surface.c +++ b/src/mesa/pipe/softpipe/sp_surface.c @@ -576,11 +576,11 @@ softpipe_get_tex_surface(struct pipe_context *pipe, assert(zslice == 0); } - ps = pipe->winsys->surface_alloc(pipe->winsys, pt->format); + ps = pipe->winsys->surface_alloc(pipe->winsys); if (ps) { - assert(ps->format); assert(ps->refcount); pipe->winsys->buffer_reference(pipe->winsys, &ps->buffer, spt->buffer); + ps->format = pt->format; ps->cpp = pt->cpp; ps->width = pt->width[level]; ps->height = pt->height[level]; diff --git a/src/mesa/pipe/xlib/xm_winsys.c b/src/mesa/pipe/xlib/xm_winsys.c index b090d8927c..ad31f4498e 100644 --- a/src/mesa/pipe/xlib/xm_winsys.c +++ b/src/mesa/pipe/xlib/xm_winsys.c @@ -388,11 +388,38 @@ round_up(unsigned n, unsigned multiple) return (n + multiple - 1) & ~(multiple - 1); } -static unsigned -xm_surface_pitch(struct pipe_winsys *winsys, unsigned cpp, unsigned width, - unsigned flags) +static int +xm_surface_alloc_storage(struct pipe_winsys *winsys, + struct pipe_surface *surf, + unsigned width, unsigned height, + enum pipe_format format, + unsigned flags) { - return round_up(width, 64 / cpp); + const unsigned alignment = 64; + int ret; + + surf->width = width; + surf->height = height; + surf->format = format; + surf->cpp = pf_get_size(format); + surf->pitch = round_up(width, alignment / surf->cpp); + + assert(!surf->buffer); + surf->buffer = winsys->buffer_create(winsys, alignment, 0, 0); + if(!surf->buffer) + return -1; + + ret = winsys->buffer_data(winsys, + surf->buffer, + surf->pitch * surf->cpp * height, + NULL, + 0); + if(ret) { + winsys->buffer_reference(winsys, &surf->buffer, NULL); + return ret; + } + + return 0; } @@ -401,14 +428,12 @@ xm_surface_pitch(struct pipe_winsys *winsys, unsigned cpp, unsigned width, * renderbuffers, etc. */ static struct pipe_surface * -xm_surface_alloc(struct pipe_winsys *ws, enum pipe_format pipeFormat) +xm_surface_alloc(struct pipe_winsys *ws) { struct xmesa_surface *xms = CALLOC_STRUCT(xmesa_surface); assert(ws); - assert(pipeFormat); - xms->surface.format = pipeFormat; xms->surface.refcount = 1; xms->surface.winsys = ws; @@ -463,8 +488,8 @@ xmesa_get_pipe_winsys(void) ws->buffer_subdata = xm_buffer_subdata; ws->buffer_get_subdata = xm_buffer_get_subdata; - ws->surface_pitch = xm_surface_pitch; ws->surface_alloc = xm_surface_alloc; + ws->surface_alloc_storage = xm_surface_alloc_storage; ws->surface_release = xm_surface_release; ws->flush_frontbuffer = xm_flush_frontbuffer; diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index ef6aec6e88..047de412e3 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -90,29 +90,15 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, uint type = strb->screenSurface ? PIPE_SCREEN_SURFACE : PIPE_SURFACE; const enum pipe_format pipeFormat = st_choose_pipe_format(pipe, internalFormat, GL_NONE, GL_NONE, type); - GLuint cpp; GLbitfield flags = 0x0; /* XXX needed? */ - cpp = init_renderbuffer_bits(strb, pipeFormat); - assert(cpp); - - if (strb->surface && strb->surface->format != pipeFormat) { - /* need to change surface types, free this surface */ - pipe_surface_reference(&strb->surface, NULL); - assert(strb->surface == NULL); - } - if (!strb->surface) { - strb->surface = pipe->winsys->surface_alloc(pipe->winsys, pipeFormat); + strb->surface = pipe->winsys->surface_alloc(pipe->winsys); assert(strb->surface); if (!strb->surface) return GL_FALSE; - strb->surface->cpp = cpp; } - strb->surface->pitch = pipe->winsys->surface_pitch(pipe->winsys, cpp, - width, flags); - /* loop here since mapping is refcounted */ while (strb->surface->map) pipe_surface_unmap(strb->surface); @@ -120,20 +106,24 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, pipe->winsys->buffer_reference(pipe->winsys, &strb->surface->buffer, NULL); - /* XXX don't hard-code magic 32 here */ - strb->surface->buffer = pipe->winsys->buffer_create(pipe->winsys, 32, 0, 0); + pipe->winsys->surface_alloc_storage(pipe->winsys, + strb->surface, + width, + height, + pipeFormat, + flags); if (!strb->surface->buffer) return GL_FALSE; /* out of memory, try s/w buffer? */ - pipe->winsys->buffer_data(pipe->winsys, strb->surface->buffer, - strb->surface->pitch * cpp * height, NULL, - PIPE_BUFFER_USAGE_PIXEL); - ASSERT(strb->surface->buffer); ASSERT(strb->surface->format); + ASSERT(strb->surface->cpp); + ASSERT(strb->surface->width == width); + ASSERT(strb->surface->height == height); + ASSERT(strb->surface->pitch); - strb->Base.Width = strb->surface->width = width; - strb->Base.Height = strb->surface->height = height; + strb->Base.Width = width; + strb->Base.Height = height; return GL_TRUE; } -- cgit v1.2.3 From 20eae595faa20dba8a59d8a4bfd01aa6b458cecd Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 12 Dec 2007 14:55:57 -0700 Subject: Re-org of st_create_framebuffer() and renderbuffer format selection. st_create_framebuffer() now takes pipe_formats for the color, depth, stencil buffers. This avoids a round-about chain of calls to pipe->is_format_supported() for window renderbuffers (their format never changes). Renderbuffer format selection code in st_format.c is simpler now too. --- src/mesa/drivers/dri/intel_winsys/intel_screen.c | 25 ++++- src/mesa/pipe/softpipe/sp_surface.c | 5 + src/mesa/pipe/xlib/xm_api.c | 120 ++++++++++++++--------- src/mesa/state_tracker/st_cb_fbo.c | 59 +++++++---- src/mesa/state_tracker/st_cb_fbo.h | 5 +- src/mesa/state_tracker/st_format.c | 58 ++--------- src/mesa/state_tracker/st_format.h | 5 +- src/mesa/state_tracker/st_framebuffer.c | 31 +++--- src/mesa/state_tracker/st_public.h | 4 + 9 files changed, 173 insertions(+), 139 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/drivers/dri/intel_winsys/intel_screen.c b/src/mesa/drivers/dri/intel_winsys/intel_screen.c index 1b520f7135..bce6c5699a 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_screen.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_screen.c @@ -274,11 +274,34 @@ intelCreateBuffer(__DRIscreenPrivate * driScrnPriv, return GL_FALSE; /* not implemented */ } else { + enum pipe_format colorFormat, depthFormat, stencilFormat; struct intel_framebuffer *intelfb = CALLOC_STRUCT(intel_framebuffer); + if (!intelfb) return GL_FALSE; - intelfb->stfb = st_create_framebuffer(visual, GL_TRUE, (void*) intelfb); + if (visual->redBits == 5) + colorFormat = PIPE_FORMAT_R5G6B5_UNORM; + else + colorFormat = PIPE_FORMAT_A8R8G8B8_UNORM; + + if (visual->depthBits == 16) + depthFormat = PIPE_FORMAT_Z16_UNORM; + else if (visual->depthBits == 24) + depthFormat = PIPE_FORMAT_S8Z24_UNORM; + else + depthFormat = PIPE_FORMAT_NONE; + + if (visual->stencilBits == 8) + stencilFormat = PIPE_FORMAT_S8Z24_UNORM; + else + stencilFormat = PIPE_FORMAT_NONE; + + intelfb->stfb = st_create_framebuffer(visual, GL_TRUE, + colorFormat, + depthFormat, + stencilFormat, + (void*) intelfb); if (!intelfb->stfb) { free(intelfb); return GL_FALSE; diff --git a/src/mesa/pipe/softpipe/sp_surface.c b/src/mesa/pipe/softpipe/sp_surface.c index 1dc494d6ff..c81e0f9c18 100644 --- a/src/mesa/pipe/softpipe/sp_surface.c +++ b/src/mesa/pipe/softpipe/sp_surface.c @@ -783,6 +783,11 @@ softpipe_put_tile_rgba(struct pipe_context *pipe, case PIPE_FORMAT_A1R5G5B5_UNORM: /*a1r5g5b5_put_tile(ps, x, y, w, h, p);*/ break; + case PIPE_FORMAT_R5G6B5_UNORM: + case PIPE_FORMAT_R8G8B8A8_UNORM: + /* XXX need these */ + fprintf(stderr, "unsup pipe format in softpipe_put_tile_rgba()\n"); + break; case PIPE_FORMAT_U_L8: /*l8_put_tile(ps, x, y, w, h, p);*/ break; diff --git a/src/mesa/pipe/xlib/xm_api.c b/src/mesa/pipe/xlib/xm_api.c index 4021af187c..142074bc65 100644 --- a/src/mesa/pipe/xlib/xm_api.c +++ b/src/mesa/pipe/xlib/xm_api.c @@ -251,6 +251,52 @@ xmesa_get_window_size(XMesaDisplay *dpy, XMesaBuffer b, } +/** + * Choose the pixel format for the given visual. + * This will tell the gallium driver how to pack pixel data into + * drawing surfaces. + */ +static GLuint +choose_pixel_format(XMesaVisual v) +{ + if ( GET_REDMASK(v) == 0x0000ff + && GET_GREENMASK(v) == 0x00ff00 + && GET_BLUEMASK(v) == 0xff0000 + && v->BitsPerPixel == 32) { + if (CHECK_BYTE_ORDER(v)) { + /* no byteswapping needed */ + return 0 /* PIXEL_FORMAT_U_A8_B8_G8_R8 */; + } + else { + return PIPE_FORMAT_R8G8B8A8_UNORM; + } + } + else if ( GET_REDMASK(v) == 0xff0000 + && GET_GREENMASK(v) == 0x00ff00 + && GET_BLUEMASK(v) == 0x0000ff + && v->BitsPerPixel == 32) { + if (CHECK_BYTE_ORDER(v)) { + /* no byteswapping needed */ + return PIPE_FORMAT_A8R8G8B8_UNORM; + } + else { + return PIPE_FORMAT_B8G8R8A8_UNORM; + } + } + else if ( GET_REDMASK(v) == 0xf800 + && GET_GREENMASK(v) == 0x07e0 + && GET_BLUEMASK(v) == 0x001f + && CHECK_BYTE_ORDER(v) + && v->BitsPerPixel == 16) { + /* 5-6-5 RGB */ + return PIPE_FORMAT_R5G6B5_UNORM; + } + + assert(0); + return 0; +} + + /**********************************************************************/ /***** Linked list of XMesaBuffers *****/ @@ -276,6 +322,7 @@ create_xmesa_buffer(XMesaDrawable d, BufferType type, { XMesaBuffer b; GLframebuffer *fb; + enum pipe_format colorFormat, depthFormat, stencilFormat; ASSERT(type == WINDOW || type == PIXMAP || type == PBUFFER); @@ -289,10 +336,35 @@ create_xmesa_buffer(XMesaDrawable d, BufferType type, b->type = type; b->cmap = cmap; + /* determine PIPE_FORMATs for buffers */ + colorFormat = choose_pixel_format(vis); + + if (vis->mesa_visual.depthBits == 0) + depthFormat = PIPE_FORMAT_NONE; + else if (vis->mesa_visual.depthBits <= 16) + depthFormat = PIPE_FORMAT_Z16_UNORM; + else if (vis->mesa_visual.depthBits <= 24) + depthFormat = PIPE_FORMAT_S8Z24_UNORM; + else + depthFormat = PIPE_FORMAT_Z32_UNORM; + + if (vis->mesa_visual.stencilBits == 8) { + if (depthFormat == PIPE_FORMAT_S8Z24_UNORM) + stencilFormat = depthFormat; + else + stencilFormat = PIPE_FORMAT_S8_UNORM; + } + else { + stencilFormat = PIPE_FORMAT_NONE; + } + + /* * Create framebuffer, but we'll plug in our own renderbuffers below. */ - b->stfb = st_create_framebuffer(&vis->mesa_visual, GL_TRUE, (void *) b); + b->stfb = st_create_framebuffer(&vis->mesa_visual, GL_TRUE, + colorFormat, depthFormat, stencilFormat, + (void *) b); fb = &b->stfb->Base; /* @@ -387,52 +459,6 @@ xmesa_free_buffer(XMesaBuffer buffer) /**********************************************************************/ -/** - * Choose the pixel format for the given visual. - * This will tell the gallium driver how to pack pixel data into - * drawing surfaces. - */ -static GLuint -choose_pixel_format(XMesaVisual v) -{ - if ( GET_REDMASK(v) == 0x0000ff - && GET_GREENMASK(v) == 0x00ff00 - && GET_BLUEMASK(v) == 0xff0000 - && v->BitsPerPixel == 32) { - if (CHECK_BYTE_ORDER(v)) { - /* no byteswapping needed */ - return 0 /* PIXEL_FORMAT_U_A8_B8_G8_R8 */; - } - else { - return PIPE_FORMAT_R8G8B8A8_UNORM; - } - } - else if ( GET_REDMASK(v) == 0xff0000 - && GET_GREENMASK(v) == 0x00ff00 - && GET_BLUEMASK(v) == 0x0000ff - && v->BitsPerPixel == 32) { - if (CHECK_BYTE_ORDER(v)) { - /* no byteswapping needed */ - return PIPE_FORMAT_A8R8G8B8_UNORM; - } - else { - return PIPE_FORMAT_B8G8R8A8_UNORM; - } - } - else if ( GET_REDMASK(v) == 0xf800 - && GET_GREENMASK(v) == 0x07e0 - && GET_BLUEMASK(v) == 0x001f - && CHECK_BYTE_ORDER(v) - && v->BitsPerPixel == 16) { - /* 5-6-5 RGB */ - return PIPE_FORMAT_R5G6B5_UNORM; - } - - assert(0); - return 0; -} - - /** * When a context is bound for the first time, we can finally finish * initializing the context's visual and buffer information. diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 047de412e3..254740ff20 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -87,9 +87,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, { struct pipe_context *pipe = ctx->st->pipe; struct st_renderbuffer *strb = st_renderbuffer(rb); - uint type = strb->screenSurface ? PIPE_SCREEN_SURFACE : PIPE_SURFACE; - const enum pipe_format pipeFormat - = st_choose_pipe_format(pipe, internalFormat, GL_NONE, GL_NONE, type); + enum pipe_format pipeFormat; GLbitfield flags = 0x0; /* XXX needed? */ if (!strb->surface) { @@ -106,6 +104,18 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, pipe->winsys->buffer_reference(pipe->winsys, &strb->surface->buffer, NULL); + /* Determine surface format here */ + if (strb->format != PIPE_FORMAT_NONE) { + assert(strb->format != 0); + /* we'll hit this for front/back color bufs */ + pipeFormat = strb->format; + } + else { + pipeFormat = st_choose_renderbuffer_format(pipe, internalFormat); + } + + init_renderbuffer_bits(strb, pipeFormat); + pipe->winsys->surface_alloc_storage(pipe->winsys, strb->surface, width, @@ -185,6 +195,7 @@ st_new_renderbuffer(GLcontext *ctx, GLuint name) strb->Base.Delete = st_renderbuffer_delete; strb->Base.AllocStorage = st_renderbuffer_alloc_storage; strb->Base.GetPointer = null_get_pointer; + strb->format = PIPE_FORMAT_NONE; return &strb->Base; } return NULL; @@ -193,12 +204,10 @@ st_new_renderbuffer(GLcontext *ctx, GLuint name) /** * Allocate a renderbuffer for a an on-screen window (not a user-created - * renderbuffer). The window system code determines the internal format. - * \param screenSurface indicates if the renderbuffer is a front/back color - * buffer that'll be displayed/copied to the screen + * renderbuffer). The window system code determines the format. */ struct gl_renderbuffer * -st_new_renderbuffer_fb(GLenum intFormat, GLboolean screenSurface) +st_new_renderbuffer_fb(enum pipe_format format) { struct st_renderbuffer *strb; @@ -210,28 +219,37 @@ st_new_renderbuffer_fb(GLenum intFormat, GLboolean screenSurface) _mesa_init_renderbuffer(&strb->Base, 0); strb->Base.ClassID = 0x4242; /* just a unique value */ - strb->Base.InternalFormat = intFormat; - strb->screenSurface = screenSurface; - - switch (intFormat) { - case GL_RGB5: - case GL_RGBA8: - case GL_RGBA16: + strb->format = format; + + switch (format) { + case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_A1R5G5B5_UNORM: + case PIPE_FORMAT_A4R4G4B4_UNORM: + case PIPE_FORMAT_R5G6B5_UNORM: + strb->Base.InternalFormat = GL_RGBA; strb->Base._BaseFormat = GL_RGBA; break; - case GL_DEPTH_COMPONENT16: - case GL_DEPTH_COMPONENT32: + case PIPE_FORMAT_Z16_UNORM: + strb->Base.InternalFormat = GL_DEPTH_COMPONENT16; strb->Base._BaseFormat = GL_DEPTH_COMPONENT; break; - case GL_DEPTH24_STENCIL8_EXT: + case PIPE_FORMAT_Z32_UNORM: + strb->Base.InternalFormat = GL_DEPTH_COMPONENT32; + strb->Base._BaseFormat = GL_DEPTH_COMPONENT; + break; + case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_Z24S8_UNORM: + strb->Base.InternalFormat = GL_DEPTH24_STENCIL8_EXT; strb->Base._BaseFormat = GL_DEPTH_STENCIL_EXT; break; - case GL_STENCIL_INDEX8_EXT: - strb->Base._BaseFormat = GL_STENCIL_INDEX; + case PIPE_FORMAT_R16G16B16A16_SNORM: + strb->Base.InternalFormat = GL_RGBA16; + strb->Base._BaseFormat = GL_RGBA; break; default: _mesa_problem(NULL, - "Unexpected intFormat in st_new_renderbuffer"); + "Unexpected format in st_new_renderbuffer_fb"); return NULL; } @@ -248,6 +266,7 @@ st_new_renderbuffer_fb(GLenum intFormat, GLboolean screenSurface) + /** * Called via ctx->Driver.BindFramebufferEXT(). */ diff --git a/src/mesa/state_tracker/st_cb_fbo.h b/src/mesa/state_tracker/st_cb_fbo.h index bd85bfc549..21e531d1d0 100644 --- a/src/mesa/state_tracker/st_cb_fbo.h +++ b/src/mesa/state_tracker/st_cb_fbo.h @@ -39,7 +39,7 @@ struct st_renderbuffer { struct gl_renderbuffer Base; struct pipe_surface *surface; - GLboolean screenSurface; /**< A front/back colorbuffer? */ + enum pipe_format format; /** preferred format, or PIPE_FORMAT_NONE */ }; @@ -51,8 +51,7 @@ st_renderbuffer(struct gl_renderbuffer *rb) extern struct gl_renderbuffer * -st_new_renderbuffer_fb(GLenum intFormat, GLboolean screen_surface); - +st_new_renderbuffer_fb(enum pipe_format format); extern void st_init_fbo_functions(struct dd_function_table *functions); diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c index 287a0054b9..2a23445ca2 100644 --- a/src/mesa/state_tracker/st_format.c +++ b/src/mesa/state_tracker/st_format.c @@ -283,9 +283,9 @@ static GLuint default_rgba_format(struct pipe_context *pipe, uint type) { static const enum pipe_format colorFormats[] = { - PIPE_FORMAT_R8G8B8A8_UNORM, PIPE_FORMAT_A8R8G8B8_UNORM, PIPE_FORMAT_B8G8R8A8_UNORM, + PIPE_FORMAT_R8G8B8A8_UNORM, PIPE_FORMAT_R5G6B5_UNORM }; uint i; @@ -334,56 +334,22 @@ default_depth_format(struct pipe_context *pipe, uint type) /** - * Choose the PIPE_FORMAT_ to use for storing a texture image based - * on the user's internalFormat, format and type parameters. - * We query the pipe device for a list of formats which it supports - * and choose from them. - * If we find a device that needs a more intricate selection mechanism, - * this function _could_ get pushed down into the pipe device. - * - * Note: also used for glRenderbufferStorageEXT() - * - * Note: format and type may be GL_NONE (see renderbuffers) + * Choose the PIPE_FORMAT_ to use for user-created renderbuffers. * * \return PIPE_FORMAT_NONE if error/problem. */ -GLuint -st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat, - GLenum format, GLenum type, uint surfType) +enum pipe_format +st_choose_renderbuffer_format(struct pipe_context *pipe, GLint internalFormat) { - assert(surfType == PIPE_TEXTURE || - surfType == PIPE_SURFACE || - surfType == PIPE_SCREEN_SURFACE); + uint surfType = PIPE_SURFACE; switch (internalFormat) { case 4: case GL_RGBA: case GL_COMPRESSED_RGBA: - if (format == GL_BGRA) { - if (type == GL_UNSIGNED_BYTE || type == GL_UNSIGNED_INT_8_8_8_8_REV) { - if (pipe->is_format_supported( pipe, PIPE_FORMAT_A8R8G8B8_UNORM, surfType )) - return PIPE_FORMAT_A8R8G8B8_UNORM; - } - else if (type == GL_UNSIGNED_SHORT_4_4_4_4_REV) { - if (pipe->is_format_supported( pipe, PIPE_FORMAT_A4R4G4B4_UNORM, surfType )) - return PIPE_FORMAT_A4R4G4B4_UNORM; - } - else if (type == GL_UNSIGNED_SHORT_1_5_5_5_REV) { - if (pipe->is_format_supported( pipe, PIPE_FORMAT_A1R5G5B5_UNORM, surfType )) - return PIPE_FORMAT_A1R5G5B5_UNORM; - } - } - return default_rgba_format( pipe, surfType ); - case 3: case GL_RGB: case GL_COMPRESSED_RGB: - if (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) { - if (pipe->is_format_supported( pipe, PIPE_FORMAT_R5G6B5_UNORM, surfType )) - return PIPE_FORMAT_R5G6B5_UNORM; - } - return default_rgba_format( pipe, surfType ); - case GL_RGBA8: case GL_RGB10_A2: case GL_RGBA12: @@ -434,7 +400,7 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat, case GL_LUMINANCE12: case GL_LUMINANCE16: case GL_COMPRESSED_LUMINANCE: - if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A8, surfType )) + if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_L8, surfType )) return PIPE_FORMAT_U_A8; return default_rgba_format( pipe, surfType ); @@ -461,18 +427,10 @@ st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat, return PIPE_FORMAT_U_I8; return default_rgba_format( pipe, surfType ); +#if 0 + /* not supported for renderbuffers */ case GL_YCBCR_MESA: - if (type == GL_UNSIGNED_SHORT_8_8_MESA || type == GL_UNSIGNED_BYTE) { - if (pipe->is_format_supported( pipe, PIPE_FORMAT_YCBCR, surfType )) - return PIPE_FORMAT_YCBCR; - } - else { - if (pipe->is_format_supported( pipe, PIPE_FORMAT_YCBCR_REV, surfType )) - return PIPE_FORMAT_YCBCR_REV; - } return PIPE_FORMAT_NONE; - -#if 0 case GL_COMPRESSED_RGB_FXT1_3DFX: return &_mesa_texformat_rgb_fxt1; case GL_COMPRESSED_RGBA_FXT1_3DFX: diff --git a/src/mesa/state_tracker/st_format.h b/src/mesa/state_tracker/st_format.h index ebff7c5b91..c9a11de504 100644 --- a/src/mesa/state_tracker/st_format.h +++ b/src/mesa/state_tracker/st_format.h @@ -63,9 +63,8 @@ extern enum pipe_format st_mesa_format_to_pipe_format(GLuint mesaFormat); -extern GLuint -st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat, - GLenum format, GLenum type, uint surfType); +extern enum pipe_format +st_choose_renderbuffer_format(struct pipe_context *pipe, GLint internalFormat); extern const struct gl_texture_format * diff --git a/src/mesa/state_tracker/st_framebuffer.c b/src/mesa/state_tracker/st_framebuffer.c index 454306b874..b81a894ef1 100644 --- a/src/mesa/state_tracker/st_framebuffer.c +++ b/src/mesa/state_tracker/st_framebuffer.c @@ -35,15 +35,16 @@ #include "st_cb_fbo.h" -struct st_framebuffer *st_create_framebuffer( const __GLcontextModes *visual, - boolean createRenderbuffers, - void *private) +struct st_framebuffer * +st_create_framebuffer( const __GLcontextModes *visual, + boolean createRenderbuffers, /* XXX remove? */ + enum pipe_format colorFormat, + enum pipe_format depthFormat, + enum pipe_format stencilFormat, + void *private) { - struct st_framebuffer *stfb - = CALLOC_STRUCT(st_framebuffer); + struct st_framebuffer *stfb = CALLOC_STRUCT(st_framebuffer); if (stfb) { - GLenum rgbFormat = (visual->redBits == 5 ? GL_RGB5 : GL_RGBA8); - _mesa_initialize_framebuffer(&stfb->Base, visual); if (createRenderbuffers) { @@ -52,20 +53,20 @@ struct st_framebuffer *st_create_framebuffer( const __GLcontextModes *visual, /* XXX allocation should only happen in the unusual case it's actually needed */ struct gl_renderbuffer *rb - = st_new_renderbuffer_fb(rgbFormat, GL_TRUE); + = st_new_renderbuffer_fb(colorFormat); _mesa_add_renderbuffer(&stfb->Base, BUFFER_FRONT_LEFT, rb); } if (visual->doubleBufferMode) { struct gl_renderbuffer *rb - = st_new_renderbuffer_fb(rgbFormat, GL_TRUE); + = st_new_renderbuffer_fb(colorFormat); _mesa_add_renderbuffer(&stfb->Base, BUFFER_BACK_LEFT, rb); } if (visual->depthBits == 24 && visual->stencilBits == 8) { /* combined depth/stencil buffer */ struct gl_renderbuffer *depthStencilRb - = st_new_renderbuffer_fb(GL_DEPTH24_STENCIL8_EXT, GL_FALSE); + = st_new_renderbuffer_fb(depthFormat); /* note: bind RB to two attachment points */ _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthStencilRb); _mesa_add_renderbuffer(&stfb->Base, BUFFER_STENCIL, depthStencilRb); @@ -76,26 +77,26 @@ struct st_framebuffer *st_create_framebuffer( const __GLcontextModes *visual, if (visual->depthBits == 32) { /* 32-bit depth buffer */ struct gl_renderbuffer *depthRb - = st_new_renderbuffer_fb(GL_DEPTH_COMPONENT32, GL_FALSE); + = st_new_renderbuffer_fb(depthFormat); _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb); } else if (visual->depthBits == 24) { /* 24-bit depth buffer, ignore stencil bits */ struct gl_renderbuffer *depthRb - = st_new_renderbuffer_fb(GL_DEPTH24_STENCIL8_EXT, GL_FALSE); + = st_new_renderbuffer_fb(depthFormat); _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb); } else if (visual->depthBits > 0) { /* 16-bit depth buffer */ struct gl_renderbuffer *depthRb - = st_new_renderbuffer_fb(GL_DEPTH_COMPONENT16, GL_FALSE); + = st_new_renderbuffer_fb(depthFormat); _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb); } if (visual->stencilBits > 0) { /* 8-bit stencil */ struct gl_renderbuffer *stencilRb - = st_new_renderbuffer_fb(GL_STENCIL_INDEX8_EXT, GL_FALSE); + = st_new_renderbuffer_fb(stencilFormat); _mesa_add_renderbuffer(&stfb->Base, BUFFER_STENCIL, stencilRb); } } @@ -103,7 +104,7 @@ struct st_framebuffer *st_create_framebuffer( const __GLcontextModes *visual, if (visual->accumRedBits > 0) { /* 16-bit/channel accum */ struct gl_renderbuffer *accumRb - = st_new_renderbuffer_fb(GL_RGBA16, GL_FALSE); + = st_new_renderbuffer_fb(PIPE_FORMAT_R16G16B16A16_SNORM); _mesa_add_renderbuffer(&stfb->Base, BUFFER_ACCUM, accumRb); } } diff --git a/src/mesa/state_tracker/st_public.h b/src/mesa/state_tracker/st_public.h index 307635936b..558b20f1e8 100644 --- a/src/mesa/state_tracker/st_public.h +++ b/src/mesa/state_tracker/st_public.h @@ -29,6 +29,7 @@ #define ST_PUBLIC_H #include "pipe/p_compiler.h" +#include "pipe/p_format.h" #define ST_SURFACE_FRONT_LEFT 0 @@ -55,6 +56,9 @@ void st_copy_context_state(struct st_context *dst, struct st_context *src, struct st_framebuffer *st_create_framebuffer( const __GLcontextModes *visual, boolean createRenderbuffers, + enum pipe_format colorFormat, + enum pipe_format depthFormat, + enum pipe_format stencilFormat, void *privateData); void st_resize_framebuffer( struct st_framebuffer *stfb, -- cgit v1.2.3 From a2b4d4a8db77443b834daf811802a909768fa926 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 13 Dec 2007 18:26:48 -0700 Subject: add missing code for PIPE_FORMAT_S8_UNORM renderbuffer --- src/mesa/state_tracker/st_cb_fbo.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 254740ff20..c40f75417f 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -243,6 +243,10 @@ st_new_renderbuffer_fb(enum pipe_format format) strb->Base.InternalFormat = GL_DEPTH24_STENCIL8_EXT; strb->Base._BaseFormat = GL_DEPTH_STENCIL_EXT; break; + case PIPE_FORMAT_S8_UNORM: + strb->Base.InternalFormat = GL_STENCIL_INDEX8_EXT; + strb->Base._BaseFormat = GL_STENCIL_INDEX; + break; case PIPE_FORMAT_R16G16B16A16_SNORM: strb->Base.InternalFormat = GL_RGBA16; strb->Base._BaseFormat = GL_RGBA; -- cgit v1.2.3 From a85535b7cb0886f23e5686e37d1fa54394cdece4 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Thu, 20 Dec 2007 13:47:46 +0000 Subject: gallium: make state tracker explictly ask for rendercache flushes --- src/mesa/state_tracker/st_cb_accum.c | 2 +- src/mesa/state_tracker/st_cb_drawpixels.c | 4 ++-- src/mesa/state_tracker/st_cb_fbo.c | 2 +- src/mesa/state_tracker/st_cb_flush.c | 4 ++-- src/mesa/state_tracker/st_cb_readpixels.c | 2 +- src/mesa/state_tracker/st_framebuffer.c | 3 ++- 6 files changed, 9 insertions(+), 8 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_accum.c b/src/mesa/state_tracker/st_cb_accum.c index ea0b1187fc..cf2e9db51c 100644 --- a/src/mesa/state_tracker/st_cb_accum.c +++ b/src/mesa/state_tracker/st_cb_accum.c @@ -321,7 +321,7 @@ st_Accum(GLcontext *ctx, GLenum op, GLfloat value) const GLint height = ctx->DrawBuffer->_Ymax - ypos; /* make sure color bufs aren't cached */ - pipe->flush(pipe, 0); + pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE); switch (op) { case GL_ADD: diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index e70a5b49e1..2db12c653b 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -849,7 +849,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, GLint skipPixels; ubyte *stmap; - pipe->flush(pipe, 0); + pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE); /* map the stencil buffer */ stmap = pipe_surface_map(ps); @@ -1208,7 +1208,7 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, uint format; /* make sure rendering has completed */ - pipe->flush(pipe, 0x0); + pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE); st_validate_state(st); diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index c40f75417f..bc0f26ffb0 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -365,7 +365,7 @@ st_finish_render_texture(GLcontext *ctx, assert(strb); - ctx->st->pipe->flush(ctx->st->pipe, 0x0); + ctx->st->pipe->flush(ctx->st->pipe, PIPE_FLUSH_RENDER_CACHE); /* printf("FINISH RENDER TO TEXTURE surf=%p\n", strb->surface); diff --git a/src/mesa/state_tracker/st_cb_flush.c b/src/mesa/state_tracker/st_cb_flush.c index 95149a3200..9808b1f8f6 100644 --- a/src/mesa/state_tracker/st_cb_flush.c +++ b/src/mesa/state_tracker/st_cb_flush.c @@ -83,7 +83,7 @@ void st_flush( struct st_context *st, uint pipeFlushFlags ) */ static void st_Flush(GLcontext *ctx) { - st_flush(ctx->st, 0x0); + st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE); } @@ -92,7 +92,7 @@ static void st_Flush(GLcontext *ctx) */ static void st_Finish(GLcontext *ctx) { - st_flush(ctx->st, PIPE_FLUSH_WAIT); + st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_WAIT); } diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c index 96829fcfa0..b0c9275c6f 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -155,7 +155,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, } /* make sure rendering has completed */ - pipe->flush(pipe, 0x0); + pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE); if (pack->BufferObj && pack->BufferObj->Name) { /* reading into a PBO */ diff --git a/src/mesa/state_tracker/st_framebuffer.c b/src/mesa/state_tracker/st_framebuffer.c index 5e0943f75c..7ddc74e355 100644 --- a/src/mesa/state_tracker/st_framebuffer.c +++ b/src/mesa/state_tracker/st_framebuffer.c @@ -33,6 +33,7 @@ #include "st_public.h" #include "st_context.h" #include "st_cb_fbo.h" +#include "pipe/p_defines.h" struct st_framebuffer * @@ -170,7 +171,7 @@ st_notify_swapbuffers(struct st_framebuffer *stfb) GET_CURRENT_CONTEXT(ctx); if (ctx && ctx->DrawBuffer == &stfb->Base) { - st_flush(ctx->st, 0x0); + st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE); } } -- cgit v1.2.3 From c76efb96b405e43e3261d1dc9e8812fdb2cfbac8 Mon Sep 17 00:00:00 2001 From: Michel Dänzer Date: Thu, 10 Jan 2008 17:44:04 +0100 Subject: Remove mapping fields from struct pipe_surface. It's now the responsibility of surface users to keep track of their mappings. --- src/mesa/pipe/i915simple/i915_surface.c | 17 ++-- src/mesa/pipe/i965simple/brw_surface.c | 17 ++-- src/mesa/pipe/p_context.h | 4 +- src/mesa/pipe/p_inlines.h | 26 ++---- src/mesa/pipe/p_state.h | 2 - src/mesa/pipe/softpipe/sp_context.c | 26 ++---- src/mesa/pipe/softpipe/sp_state_surface.c | 42 ++------- src/mesa/pipe/softpipe/sp_surface.c | 16 ++-- src/mesa/pipe/softpipe/sp_tile_cache.c | 45 ++++++++-- src/mesa/pipe/softpipe/sp_tile_cache.h | 6 ++ src/mesa/pipe/util/p_tile.c | 128 +++++++++++++++++----------- src/mesa/pipe/xlib/xm_api.c | 21 ++--- src/mesa/state_tracker/st_cb_accum.c | 137 ++++-------------------------- src/mesa/state_tracker/st_cb_drawpixels.c | 6 -- src/mesa/state_tracker/st_cb_fbo.c | 3 - src/mesa/state_tracker/st_cb_readpixels.c | 4 - src/mesa/state_tracker/st_cb_texture.c | 13 +-- 17 files changed, 191 insertions(+), 322 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/pipe/i915simple/i915_surface.c b/src/mesa/pipe/i915simple/i915_surface.c index 79e74e1143..4e1b0929ee 100644 --- a/src/mesa/pipe/i915simple/i915_surface.c +++ b/src/mesa/pipe/i915simple/i915_surface.c @@ -171,10 +171,10 @@ i915_surface_copy(struct pipe_context *pipe, /* Fill a rectangular sub-region. Need better logic about when to * push buffers into AGP - will currently do so whenever possible. */ -static ubyte * -get_pointer(struct pipe_surface *dst, unsigned x, unsigned y) +static void * +get_pointer(struct pipe_surface *dst, void *dst_map, unsigned x, unsigned y) { - return dst->map + (y * dst->pitch + x) * dst->cpp; + return (char *)dst_map + (y * dst->pitch + x) * dst->cpp; } @@ -186,12 +186,11 @@ i915_surface_fill(struct pipe_context *pipe, { if (0) { unsigned i, j; - - (void)pipe_surface_map(dst); + void *dst_map = pipe_surface_map(dst); switch (dst->cpp) { case 1: { - ubyte *row = get_pointer(dst, dstx, dsty); + ubyte *row = get_pointer(dst, dst_map, dstx, dsty); for (i = 0; i < height; i++) { memset(row, value, width); row += dst->pitch; @@ -199,7 +198,7 @@ i915_surface_fill(struct pipe_context *pipe, } break; case 2: { - ushort *row = (ushort *) get_pointer(dst, dstx, dsty); + ushort *row = get_pointer(dst, dst_map, dstx, dsty); for (i = 0; i < height; i++) { for (j = 0; j < width; j++) row[j] = (ushort) value; @@ -208,7 +207,7 @@ i915_surface_fill(struct pipe_context *pipe, } break; case 4: { - unsigned *row = (unsigned *) get_pointer(dst, dstx, dsty); + unsigned *row = get_pointer(dst, dst_map, dstx, dsty); for (i = 0; i < height; i++) { for (j = 0; j < width; j++) row[j] = value; @@ -220,6 +219,8 @@ i915_surface_fill(struct pipe_context *pipe, assert(0); break; } + + pipe_surface_unmap( dst ); } else { i915_fill_blit( i915_context(pipe), diff --git a/src/mesa/pipe/i965simple/brw_surface.c b/src/mesa/pipe/i965simple/brw_surface.c index d0e7229d5c..850423bdd5 100644 --- a/src/mesa/pipe/i965simple/brw_surface.c +++ b/src/mesa/pipe/i965simple/brw_surface.c @@ -171,10 +171,10 @@ brw_surface_copy(struct pipe_context *pipe, /* Fill a rectangular sub-region. Need better logic about when to * push buffers into AGP - will currently do so whenever possible. */ -static ubyte * -get_pointer(struct pipe_surface *dst, unsigned x, unsigned y) +static void * +get_pointer(struct pipe_surface *dst, void *dst_map, unsigned x, unsigned y) { - return dst->map + (y * dst->pitch + x) * dst->cpp; + return (char *)dst_map + (y * dst->pitch + x) * dst->cpp; } @@ -186,12 +186,11 @@ brw_surface_fill(struct pipe_context *pipe, { if (0) { unsigned i, j; - - (void)pipe_surface_map(dst); + void *dst_map = pipe_surface_map(dst); switch (dst->cpp) { case 1: { - ubyte *row = get_pointer(dst, dstx, dsty); + ubyte *row = get_pointer(dst, dst_map, dstx, dsty); for (i = 0; i < height; i++) { memset(row, value, width); row += dst->pitch; @@ -199,7 +198,7 @@ brw_surface_fill(struct pipe_context *pipe, } break; case 2: { - ushort *row = (ushort *) get_pointer(dst, dstx, dsty); + ushort *row = get_pointer(dst, dst_map, dstx, dsty); for (i = 0; i < height; i++) { for (j = 0; j < width; j++) row[j] = (ushort) value; @@ -208,7 +207,7 @@ brw_surface_fill(struct pipe_context *pipe, } break; case 4: { - unsigned *row = (unsigned *) get_pointer(dst, dstx, dsty); + unsigned *row = get_pointer(dst, dst_map, dstx, dsty); for (i = 0; i < height; i++) { for (j = 0; j < width; j++) row[j] = value; @@ -220,6 +219,8 @@ brw_surface_fill(struct pipe_context *pipe, assert(0); break; } + + pipe_surface_unmap( dst ); } else { brw_fill_blit(brw_context(pipe), diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 1afb38a868..1a1f4f4e78 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -194,9 +194,9 @@ struct pipe_context { const void *p, int src_stride); /* XXX temporary here, move these to softpipe */ void (*get_tile_rgba)(struct pipe_context *pipe, struct pipe_surface *ps, - uint x, uint y, uint w, uint h, float *p); + uint x, uint y, uint w, uint h, float *p); void (*put_tile_rgba)(struct pipe_context *pipe, struct pipe_surface *ps, - uint x, uint y, uint w, uint h, const float *p); + uint x, uint y, uint w, uint h, const float *p); /* diff --git a/src/mesa/pipe/p_inlines.h b/src/mesa/pipe/p_inlines.h index e7303c45c1..6976d087f9 100644 --- a/src/mesa/pipe/p_inlines.h +++ b/src/mesa/pipe/p_inlines.h @@ -33,35 +33,21 @@ #include "p_winsys.h" -static INLINE ubyte * +static INLINE void * pipe_surface_map(struct pipe_surface *surface) { - if (!surface->map_refcount++) { - surface->map - = (ubyte *) surface->winsys->buffer_map( surface->winsys, - surface->buffer, - PIPE_BUFFER_FLAG_WRITE | - PIPE_BUFFER_FLAG_READ ) - + surface->offset; - } - - return surface->map; + return (char *)surface->winsys->buffer_map( surface->winsys, surface->buffer, + PIPE_BUFFER_FLAG_WRITE | + PIPE_BUFFER_FLAG_READ ) + + surface->offset; } static INLINE void pipe_surface_unmap(struct pipe_surface *surface) { - if (surface->map_refcount > 0) { - assert(surface->map); - if (!--surface->map_refcount) { - surface->winsys->buffer_unmap( surface->winsys, - surface->buffer ); - surface->map = NULL; - } - } + surface->winsys->buffer_unmap( surface->winsys, surface->buffer ); } - /** * Set 'ptr' to point to 'surf' and update reference counting. * The old thing pointed to, if any, will be unreferenced first. diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index f9c5bfb6c6..ccd2a5f9e2 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -242,8 +242,6 @@ struct pipe_sampler_state struct pipe_surface { struct pipe_buffer_handle *buffer; /**< driver private buffer handle */ - ubyte *map; /**< only non-NULL when surface is actually mapped */ - unsigned map_refcount; /**< Reference count for mapping */ enum pipe_format format; /**< PIPE_FORMAT_x */ unsigned cpp; /**< bytes per pixel */ unsigned width, height; diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index 4f22539629..68c18e2d05 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -75,22 +75,15 @@ softpipe_is_format_supported( struct pipe_context *pipe, void softpipe_map_surfaces(struct softpipe_context *sp) { - struct pipe_surface *ps; unsigned i; for (i = 0; i < sp->framebuffer.num_cbufs; i++) { - ps = sp->framebuffer.cbufs[i]; - if (ps->buffer && !ps->map) - pipe_surface_map(ps); + sp_tile_cache_map_surfaces(sp->cbuf_cache[i]); } - ps = sp->framebuffer.zbuf; - if (ps && ps->buffer && !ps->map) - pipe_surface_map(ps); + sp_tile_cache_map_surfaces(sp->zbuf_cache); - ps = sp->framebuffer.sbuf; - if (ps && ps->buffer && !ps->map) - pipe_surface_map(ps); + sp_tile_cache_map_surfaces(sp->sbuf_cache); } @@ -100,7 +93,6 @@ softpipe_map_surfaces(struct softpipe_context *sp) void softpipe_unmap_surfaces(struct softpipe_context *sp) { - struct pipe_surface *ps; uint i; for (i = 0; i < sp->framebuffer.num_cbufs; i++) @@ -109,18 +101,12 @@ softpipe_unmap_surfaces(struct softpipe_context *sp) sp_flush_tile_cache(sp, sp->sbuf_cache); for (i = 0; i < sp->framebuffer.num_cbufs; i++) { - ps = sp->framebuffer.cbufs[i]; - if (ps->map) - pipe_surface_unmap(ps); + sp_tile_cache_unmap_surfaces(sp->cbuf_cache[i]); } - ps = sp->framebuffer.zbuf; - if (ps && ps->map) - pipe_surface_unmap(ps); + sp_tile_cache_unmap_surfaces(sp->zbuf_cache); - ps = sp->framebuffer.sbuf; - if (ps && ps->map) - pipe_surface_unmap(ps); + sp_tile_cache_unmap_surfaces(sp->sbuf_cache); } diff --git a/src/mesa/pipe/softpipe/sp_state_surface.c b/src/mesa/pipe/softpipe/sp_state_surface.c index ee72aaf4c5..4a9a28cc4d 100644 --- a/src/mesa/pipe/softpipe/sp_state_surface.c +++ b/src/mesa/pipe/softpipe/sp_state_surface.c @@ -38,7 +38,7 @@ /** * XXX this might get moved someday * Set the framebuffer surface info: color buffers, zbuffer, stencil buffer. - * Here, we map the surfaces and update the tile cache to point to the new + * Here, we flush the old surfaces and update the tile cache to point to the new * surfaces. */ void @@ -46,7 +46,6 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe, const struct pipe_framebuffer_state *fb) { struct softpipe_context *sp = softpipe_context(pipe); - struct pipe_surface *ps; uint i; for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { @@ -54,19 +53,12 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe, if (sp->framebuffer.cbufs[i] != fb->cbufs[i]) { /* flush old */ sp_flush_tile_cache(sp, sp->cbuf_cache[i]); - /* unmap old */ - ps = sp->framebuffer.cbufs[i]; - if (ps && ps->map) - pipe_surface_unmap(ps); - /* map new */ - ps = fb->cbufs[i]; - if (ps) - pipe_surface_map(ps); + /* assign new */ sp->framebuffer.cbufs[i] = fb->cbufs[i]; /* update cache */ - sp_tile_cache_set_surface(sp->cbuf_cache[i], ps); + sp_tile_cache_set_surface(sp->cbuf_cache[i], fb->cbufs[i]); } } @@ -76,23 +68,12 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe, if (sp->framebuffer.zbuf != fb->zbuf) { /* flush old */ sp_flush_tile_cache(sp, sp->zbuf_cache); - /* unmap old */ - ps = sp->framebuffer.zbuf; - if (ps && ps->map) - pipe_surface_unmap(ps); - if (sp->framebuffer.sbuf == sp->framebuffer.zbuf) { - /* combined z/stencil */ - sp->framebuffer.sbuf = NULL; - } - /* map new */ - ps = fb->zbuf; - if (ps) - pipe_surface_map(ps); + /* assign new */ sp->framebuffer.zbuf = fb->zbuf; /* update cache */ - sp_tile_cache_set_surface(sp->zbuf_cache, ps); + sp_tile_cache_set_surface(sp->zbuf_cache, fb->zbuf); } /* XXX combined depth/stencil here */ @@ -101,14 +82,7 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe, if (sp->framebuffer.sbuf != fb->sbuf) { /* flush old */ sp_flush_tile_cache(sp, sp->sbuf_cache_sep); - /* unmap old */ - ps = sp->framebuffer.sbuf; - if (ps && ps->map) - pipe_surface_unmap(ps); - /* map new */ - ps = fb->sbuf; - if (ps && fb->sbuf != fb->zbuf) - pipe_surface_map(ps); + /* assign new */ sp->framebuffer.sbuf = fb->sbuf; @@ -116,12 +90,12 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe, if (fb->sbuf != fb->zbuf) { /* separate stencil buf */ sp->sbuf_cache = sp->sbuf_cache_sep; - sp_tile_cache_set_surface(sp->sbuf_cache, ps); + sp_tile_cache_set_surface(sp->sbuf_cache, fb->sbuf); } else { /* combined depth/stencil */ sp->sbuf_cache = sp->zbuf_cache; - sp_tile_cache_set_surface(sp->sbuf_cache, ps); + sp_tile_cache_set_surface(sp->sbuf_cache, fb->sbuf); } } diff --git a/src/mesa/pipe/softpipe/sp_surface.c b/src/mesa/pipe/softpipe/sp_surface.c index ece30e36ec..b44ba3e957 100644 --- a/src/mesa/pipe/softpipe/sp_surface.c +++ b/src/mesa/pipe/softpipe/sp_surface.c @@ -158,10 +158,10 @@ sp_surface_copy(struct pipe_context *pipe, } -static ubyte * -get_pointer(struct pipe_surface *dst, unsigned x, unsigned y) +static void * +get_pointer(struct pipe_surface *dst, void *dst_map, unsigned x, unsigned y) { - return dst->map + (y * dst->pitch + x) * dst->cpp; + return (char *)dst_map + (y * dst->pitch + x) * dst->cpp; } @@ -179,16 +179,16 @@ sp_surface_fill(struct pipe_context *pipe, unsigned width, unsigned height, unsigned value) { unsigned i, j; + void *dst_map = pipe_surface_map(dst); assert(dst->pitch > 0); assert(width <= dst->pitch); - (void)pipe_surface_map(dst); switch (dst->cpp) { case 1: { - ubyte *row = get_pointer(dst, dstx, dsty); + ubyte *row = get_pointer(dst, dst_map, dstx, dsty); for (i = 0; i < height; i++) { memset(row, value, width); row += dst->pitch; @@ -197,7 +197,7 @@ sp_surface_fill(struct pipe_context *pipe, break; case 2: { - ushort *row = (ushort *) get_pointer(dst, dstx, dsty); + ushort *row = get_pointer(dst, dst_map, dstx, dsty); for (i = 0; i < height; i++) { for (j = 0; j < width; j++) row[j] = (ushort) value; @@ -207,7 +207,7 @@ sp_surface_fill(struct pipe_context *pipe, break; case 4: { - unsigned *row = (unsigned *) get_pointer(dst, dstx, dsty); + unsigned *row = get_pointer(dst, dst_map, dstx, dsty); for (i = 0; i < height; i++) { for (j = 0; j < width; j++) row[j] = value; @@ -218,7 +218,7 @@ sp_surface_fill(struct pipe_context *pipe, case 8: { /* expand the 4-byte clear value to an 8-byte value */ - ushort *row = (ushort *) get_pointer(dst, dstx, dsty); + ushort *row = (ushort *) get_pointer(dst, dst_map, dstx, dsty); ushort val0 = UBYTE_TO_USHORT((value >> 0) & 0xff); ushort val1 = UBYTE_TO_USHORT((value >> 8) & 0xff); ushort val2 = UBYTE_TO_USHORT((value >> 16) & 0xff); diff --git a/src/mesa/pipe/softpipe/sp_tile_cache.c b/src/mesa/pipe/softpipe/sp_tile_cache.c index 1dbcc5aadd..d6f60807e6 100644 --- a/src/mesa/pipe/softpipe/sp_tile_cache.c +++ b/src/mesa/pipe/softpipe/sp_tile_cache.c @@ -49,6 +49,7 @@ struct softpipe_tile_cache { struct pipe_surface *surface; /**< the surface we're caching */ + void *surface_map; struct pipe_texture *texture; /**< if caching a texture */ struct softpipe_cached_tile entries[NUM_ENTRIES]; uint clear_flags[(MAX_WIDTH / TILE_SIZE) * (MAX_HEIGHT / TILE_SIZE) / 32]; @@ -57,6 +58,7 @@ struct softpipe_tile_cache boolean depth_stencil; /** Is the surface a depth/stencil format? */ struct pipe_surface *tex_surf; + void *tex_surf_map; int tex_face, tex_level, tex_z; struct softpipe_cached_tile tile; /**< scratch tile for clears */ @@ -150,7 +152,7 @@ sp_tile_cache_set_surface(struct softpipe_tile_cache *tc, { assert(!tc->texture); - if (tc->surface && tc->surface->map) { + if (tc->surface_map) { /*assert(tc->surface != ps);*/ pipe_surface_unmap(tc->surface); } @@ -158,8 +160,8 @@ sp_tile_cache_set_surface(struct softpipe_tile_cache *tc, pipe_surface_reference(&tc->surface, ps); if (ps) { - if (!ps->map) - pipe_surface_map(ps); + if (tc->surface_map) + tc->surface_map = pipe_surface_map(ps); tc->depth_stencil = (ps->format == PIPE_FORMAT_S8Z24_UNORM || ps->format == PIPE_FORMAT_Z16_UNORM || @@ -179,6 +181,32 @@ sp_tile_cache_get_surface(struct softpipe_tile_cache *tc) } +void +sp_tile_cache_map_surfaces(struct softpipe_tile_cache *tc) +{ + if (tc->surface && !tc->surface_map) + tc->surface_map = pipe_surface_map(tc->surface); + + if (tc->tex_surf && !tc->tex_surf_map) + tc->tex_surf_map = pipe_surface_map(tc->tex_surf); +} + + +void +sp_tile_cache_unmap_surfaces(struct softpipe_tile_cache *tc) +{ + if (tc->surface_map) { + pipe_surface_unmap(tc->surface); + tc->surface_map = NULL; + } + + if (tc->tex_surf_map) { + pipe_surface_unmap(tc->tex_surf); + tc->tex_surf_map = NULL; + } +} + + /** * Specify the texture to cache. */ @@ -192,8 +220,10 @@ sp_tile_cache_set_texture(struct softpipe_tile_cache *tc, tc->texture = texture; - if (tc->tex_surf && tc->tex_surf->map) + if (tc->tex_surf_map) { pipe_surface_unmap(tc->tex_surf); + tc->tex_surf_map = NULL; + } pipe_surface_reference(&tc->tex_surf, NULL); /* mark as entries as invalid/empty */ @@ -330,9 +360,6 @@ sp_flush_tile_cache(struct softpipe_context *softpipe, if (!ps || !ps->buffer) return; - if (!ps->map) - pipe_surface_map(ps); - for (pos = 0; pos < NUM_ENTRIES; pos++) { struct softpipe_cached_tile *tile = tc->entries + pos; if (tile->x >= 0) { @@ -475,11 +502,11 @@ sp_get_cached_tile_tex(struct pipe_context *pipe, tc->tex_z != z) { /* get new surface (view into texture) */ - if (tc->tex_surf && tc->tex_surf->map) + if (tc->tex_surf_map) pipe_surface_unmap(tc->tex_surf); tc->tex_surf = pipe->get_tex_surface(pipe, tc->texture, face, level, z); - pipe_surface_map(tc->tex_surf); + tc->tex_surf_map = pipe_surface_map(tc->tex_surf); tc->tex_face = face; tc->tex_level = level; diff --git a/src/mesa/pipe/softpipe/sp_tile_cache.h b/src/mesa/pipe/softpipe/sp_tile_cache.h index 91fb2795a2..7fd1081286 100644 --- a/src/mesa/pipe/softpipe/sp_tile_cache.h +++ b/src/mesa/pipe/softpipe/sp_tile_cache.h @@ -73,6 +73,12 @@ sp_tile_cache_set_surface(struct softpipe_tile_cache *tc, extern struct pipe_surface * sp_tile_cache_get_surface(struct softpipe_tile_cache *tc); +extern void +sp_tile_cache_map_surfaces(struct softpipe_tile_cache *tc); + +extern void +sp_tile_cache_unmap_surfaces(struct softpipe_tile_cache *tc); + extern void sp_tile_cache_set_texture(struct softpipe_tile_cache *tc, struct pipe_texture *texture); diff --git a/src/mesa/pipe/util/p_tile.c b/src/mesa/pipe/util/p_tile.c index 8bc3c22c83..f2e19f19dc 100644 --- a/src/mesa/pipe/util/p_tile.c +++ b/src/mesa/pipe/util/p_tile.c @@ -56,8 +56,6 @@ pipe_get_tile_raw(struct pipe_context *pipe, ubyte *pDest; uint i; - assert(ps->map); - if (dst_stride == 0) { dst_stride = w * cpp; } @@ -65,7 +63,7 @@ pipe_get_tile_raw(struct pipe_context *pipe, if (pipe_clip_tile(x, y, &w, &h, ps)) return; - pSrc = ps->map + (y * ps->pitch + x) * cpp; + pSrc = (const ubyte *) pipe_surface_map(ps) + (y * ps->pitch + x) * cpp; pDest = (ubyte *) p; for (i = 0; i < h; i++) { @@ -73,6 +71,8 @@ pipe_get_tile_raw(struct pipe_context *pipe, pDest += dst_stride; pSrc += src_stride; } + + pipe_surface_unmap(ps); } @@ -92,8 +92,6 @@ pipe_put_tile_raw(struct pipe_context *pipe, ubyte *pDest; uint i; - assert(ps->map); - if (src_stride == 0) { src_stride = w * cpp; } @@ -102,13 +100,15 @@ pipe_put_tile_raw(struct pipe_context *pipe, return; pSrc = (const ubyte *) p; - pDest = ps->map + (y * ps->pitch + x) * cpp; + pDest = (ubyte *) pipe_surface_map(ps) + (y * ps->pitch + x) * cpp; for (i = 0; i < h; i++) { memcpy(pDest, pSrc, w * cpp); pDest += dst_stride; pSrc += src_stride; } + + pipe_surface_unmap(ps); } @@ -126,11 +126,12 @@ pipe_put_tile_raw(struct pipe_context *pipe, static void a8r8g8b8_get_tile_rgba(struct pipe_surface *ps, + void *map, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const unsigned *src - = ((const unsigned *) (ps->map)) + = ((const unsigned *) map) + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -158,11 +159,12 @@ a8r8g8b8_get_tile_rgba(struct pipe_surface *ps, static void a8r8g8b8_put_tile_rgba(struct pipe_surface *ps, + void *map, unsigned x, unsigned y, unsigned w, unsigned h, const float *p) { unsigned *dst - = ((unsigned *) (ps->map)) + = ((unsigned *) map) + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -193,11 +195,12 @@ a8r8g8b8_put_tile_rgba(struct pipe_surface *ps, static void b8g8r8a8_get_tile_rgba(struct pipe_surface *ps, + void *map, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const unsigned *src - = ((const unsigned *) (ps->map)) + = ((const unsigned *) map) + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -225,11 +228,12 @@ b8g8r8a8_get_tile_rgba(struct pipe_surface *ps, static void b8g8r8a8_put_tile_rgba(struct pipe_surface *ps, + void *map, unsigned x, unsigned y, unsigned w, unsigned h, const float *p) { unsigned *dst - = ((unsigned *) (ps->map)) + = ((unsigned *) map) + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -260,11 +264,12 @@ b8g8r8a8_put_tile_rgba(struct pipe_surface *ps, static void a1r5g5b5_get_tile_rgba(struct pipe_surface *ps, + void *map, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const ushort *src - = ((const ushort *) (ps->map)) + = ((const ushort *) map) + y * ps->pitch + x; unsigned i, j; @@ -288,11 +293,12 @@ a1r5g5b5_get_tile_rgba(struct pipe_surface *ps, static void a4r4g4b4_get_tile_rgba(struct pipe_surface *ps, + void *map, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const ushort *src - = ((const ushort *) (ps->map)) + = ((const ushort *) map) + y * ps->pitch + x; unsigned i, j; @@ -316,11 +322,12 @@ a4r4g4b4_get_tile_rgba(struct pipe_surface *ps, static void r5g6b5_get_tile_rgba(struct pipe_surface *ps, + void *map, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const ushort *src - = ((const ushort *) (ps->map)) + = ((const ushort *) map) + y * ps->pitch + x; unsigned i, j; @@ -342,11 +349,12 @@ r5g6b5_get_tile_rgba(struct pipe_surface *ps, static void r5g5b5_put_tile_rgba(struct pipe_surface *ps, + void *map, unsigned x, unsigned y, unsigned w, unsigned h, const float *p) { ushort *dst - = ((ushort *) (ps->map)) + = ((ushort *) map) + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -379,11 +387,12 @@ r5g5b5_put_tile_rgba(struct pipe_surface *ps, */ static void z16_get_tile_rgba(struct pipe_surface *ps, + void *map, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const ushort *src - = ((const ushort *) (ps->map)) + = ((const ushort *) map) + y * ps->pitch + x; const float scale = 1.0f / 65535.0f; unsigned i, j; @@ -414,11 +423,12 @@ z16_get_tile_rgba(struct pipe_surface *ps, static void l8_get_tile_rgba(struct pipe_surface *ps, + void *map, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const ubyte *src - = ((const ubyte *) (ps->map)) + = ((const ubyte *) map) + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -447,11 +457,12 @@ l8_get_tile_rgba(struct pipe_surface *ps, static void a8_get_tile_rgba(struct pipe_surface *ps, + void *map, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const ubyte *src - = ((const ubyte *) (ps->map)) + = ((const ubyte *) map) + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -480,11 +491,12 @@ a8_get_tile_rgba(struct pipe_surface *ps, static void r16g16b16a16_get_tile_rgba(struct pipe_surface *ps, + void *map, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const short *src - = ((const short *) (ps->map)) + = ((const short *) map) + (y * ps->pitch + x) * 4; unsigned i, j; unsigned w0 = w; @@ -513,11 +525,12 @@ r16g16b16a16_get_tile_rgba(struct pipe_surface *ps, static void r16g16b16a16_put_tile_rgba(struct pipe_surface *ps, + void *map, unsigned x, unsigned y, unsigned w, unsigned h, const float *p) { short *dst - = ((short *) (ps->map)) + = ((short *) map) + (y * ps->pitch + x) * 4; unsigned i, j; unsigned w0 = w; @@ -552,11 +565,12 @@ r16g16b16a16_put_tile_rgba(struct pipe_surface *ps, static void i8_get_tile_rgba(struct pipe_surface *ps, + void *map, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const ubyte *src - = ((const ubyte *) (ps->map)) + = ((const ubyte *) map) + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -585,11 +599,12 @@ i8_get_tile_rgba(struct pipe_surface *ps, static void a8_l8_get_tile_rgba(struct pipe_surface *ps, + void *map, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const ushort *src - = ((const ushort *) (ps->map)) + = ((const ushort *) map) + y * ps->pitch + x; unsigned i, j; unsigned w0 = w; @@ -624,11 +639,12 @@ a8_l8_get_tile_rgba(struct pipe_surface *ps, */ static void z32_get_tile_rgba(struct pipe_surface *ps, + void *map, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const uint *src - = ((const uint *) (ps->map)) + = ((const uint *) map) + y * ps->pitch + x; const double scale = 1.0 / (double) 0xffffffff; unsigned i, j; @@ -660,11 +676,12 @@ z32_get_tile_rgba(struct pipe_surface *ps, */ static void s8z24_get_tile_rgba(struct pipe_surface *ps, + void *map, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const uint *src - = ((const uint *) (ps->map)) + = ((const uint *) map) + y * ps->pitch + x; const double scale = 1.0 / ((1 << 24) - 1); unsigned i, j; @@ -696,11 +713,12 @@ s8z24_get_tile_rgba(struct pipe_surface *ps, */ static void z24s8_get_tile_rgba(struct pipe_surface *ps, + void *map, unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const uint *src - = ((const uint *) (ps->map)) + = ((const uint *) map) + y * ps->pitch + x; const double scale = 1.0 / ((1 << 24) - 1); unsigned i, j; @@ -731,52 +749,56 @@ pipe_get_tile_rgba(struct pipe_context *pipe, uint x, uint y, uint w, uint h, float *p) { + void *map = pipe_surface_map(ps); + switch (ps->format) { case PIPE_FORMAT_A8R8G8B8_UNORM: - a8r8g8b8_get_tile_rgba(ps, x, y, w, h, p); + a8r8g8b8_get_tile_rgba(ps, map, x, y, w, h, p); break; case PIPE_FORMAT_B8G8R8A8_UNORM: - b8g8r8a8_get_tile_rgba(ps, x, y, w, h, p); + b8g8r8a8_get_tile_rgba(ps, map, x, y, w, h, p); break; case PIPE_FORMAT_A1R5G5B5_UNORM: - a1r5g5b5_get_tile_rgba(ps, x, y, w, h, p); + a1r5g5b5_get_tile_rgba(ps, map, x, y, w, h, p); break; case PIPE_FORMAT_A4R4G4B4_UNORM: - a4r4g4b4_get_tile_rgba(ps, x, y, w, h, p); + a4r4g4b4_get_tile_rgba(ps, map, x, y, w, h, p); break; case PIPE_FORMAT_R5G6B5_UNORM: - r5g6b5_get_tile_rgba(ps, x, y, w, h, p); + r5g6b5_get_tile_rgba(ps, map, x, y, w, h, p); break; case PIPE_FORMAT_U_L8: - l8_get_tile_rgba(ps, x, y, w, h, p); + l8_get_tile_rgba(ps, map, x, y, w, h, p); break; case PIPE_FORMAT_U_A8: - a8_get_tile_rgba(ps, x, y, w, h, p); + a8_get_tile_rgba(ps, map, x, y, w, h, p); break; case PIPE_FORMAT_U_I8: - i8_get_tile_rgba(ps, x, y, w, h, p); + i8_get_tile_rgba(ps, map, x, y, w, h, p); break; case PIPE_FORMAT_U_A8_L8: - a8_l8_get_tile_rgba(ps, x, y, w, h, p); + a8_l8_get_tile_rgba(ps, map, x, y, w, h, p); break; case PIPE_FORMAT_R16G16B16A16_SNORM: - r16g16b16a16_get_tile_rgba(ps, x, y, w, h, p); + r16g16b16a16_get_tile_rgba(ps, map, x, y, w, h, p); break; case PIPE_FORMAT_Z16_UNORM: - z16_get_tile_rgba(ps, x, y, w, h, p); + z16_get_tile_rgba(ps, map, x, y, w, h, p); break; case PIPE_FORMAT_Z32_UNORM: - z32_get_tile_rgba(ps, x, y, w, h, p); + z32_get_tile_rgba(ps, map, x, y, w, h, p); break; case PIPE_FORMAT_S8Z24_UNORM: - s8z24_get_tile_rgba(ps, x, y, w, h, p); + s8z24_get_tile_rgba(ps, map, x, y, w, h, p); break; case PIPE_FORMAT_Z24S8_UNORM: - z24s8_get_tile_rgba(ps, x, y, w, h, p); + z24s8_get_tile_rgba(ps, map, x, y, w, h, p); break; default: assert(0); } + + pipe_surface_unmap(ps); } @@ -786,49 +808,53 @@ pipe_put_tile_rgba(struct pipe_context *pipe, uint x, uint y, uint w, uint h, const float *p) { + void *map = pipe_surface_map(ps); + switch (ps->format) { case PIPE_FORMAT_A8R8G8B8_UNORM: - a8r8g8b8_put_tile_rgba(ps, x, y, w, h, p); + a8r8g8b8_put_tile_rgba(ps, map, x, y, w, h, p); break; case PIPE_FORMAT_B8G8R8A8_UNORM: - b8g8r8a8_put_tile_rgba(ps, x, y, w, h, p); + b8g8r8a8_put_tile_rgba(ps, map, x, y, w, h, p); break; case PIPE_FORMAT_A1R5G5B5_UNORM: - /*a1r5g5b5_put_tile_rgba(ps, x, y, w, h, p);*/ + /*a1r5g5b5_put_tile_rgba(ps, map, x, y, w, h, p);*/ break; case PIPE_FORMAT_R5G6B5_UNORM: - r5g5b5_put_tile_rgba(ps, x, y, w, h, p); + r5g5b5_put_tile_rgba(ps, map, x, y, w, h, p); break; case PIPE_FORMAT_R8G8B8A8_UNORM: break; case PIPE_FORMAT_U_L8: - /*l8_put_tile_rgba(ps, x, y, w, h, p);*/ + /*l8_put_tile_rgba(ps, map, x, y, w, h, p);*/ break; case PIPE_FORMAT_U_A8: - /*a8_put_tile_rgba(ps, x, y, w, h, p);*/ + /*a8_put_tile_rgba(ps, map, x, y, w, h, p);*/ break; case PIPE_FORMAT_U_I8: - /*i8_put_tile_rgba(ps, x, y, w, h, p);*/ + /*i8_put_tile_rgba(ps, map, x, y, w, h, p);*/ break; case PIPE_FORMAT_U_A8_L8: - /*a8_l8_put_tile_rgba(ps, x, y, w, h, p);*/ + /*a8_l8_put_tile_rgba(ps, map, x, y, w, h, p);*/ break; case PIPE_FORMAT_R16G16B16A16_SNORM: - r16g16b16a16_put_tile_rgba(ps, x, y, w, h, p); + r16g16b16a16_put_tile_rgba(ps, map, x, y, w, h, p); break; case PIPE_FORMAT_Z16_UNORM: - /*z16_put_tile_rgba(ps, x, y, w, h, p);*/ + /*z16_put_tile_rgba(ps, map, x, y, w, h, p);*/ break; case PIPE_FORMAT_Z32_UNORM: - /*z32_put_tile_rgba(ps, x, y, w, h, p);*/ + /*z32_put_tile_rgba(ps, map, x, y, w, h, p);*/ break; case PIPE_FORMAT_S8Z24_UNORM: - /*s8z24_put_tile_rgba(ps, x, y, w, h, p);*/ + /*s8z24_put_tile_rgba(ps, map, x, y, w, h, p);*/ break; case PIPE_FORMAT_Z24S8_UNORM: - /*z24s8_put_tile_rgba(ps, x, y, w, h, p);*/ + /*z24s8_put_tile_rgba(ps, map, x, y, w, h, p);*/ break; default: assert(0); } + + pipe_surface_unmap(ps); } diff --git a/src/mesa/pipe/xlib/xm_api.c b/src/mesa/pipe/xlib/xm_api.c index 168eba0784..03985eab5a 100644 --- a/src/mesa/pipe/xlib/xm_api.c +++ b/src/mesa/pipe/xlib/xm_api.c @@ -1247,22 +1247,11 @@ void XMesaCopySubBuffer( XMesaBuffer b, int x, int y, int width, int height ) GLboolean XMesaGetDepthBuffer( XMesaBuffer b, GLint *width, GLint *height, GLint *bytesPerValue, void **buffer ) { - struct pipe_surface *surf - = st_get_framebuffer_surface(b->stfb, ST_SURFACE_DEPTH); - if (surf) { - *width = surf->width; - *height = surf->pitch; - *bytesPerValue = surf->cpp; - *buffer = surf->map; - return GL_TRUE; - } - else { - *width = 0; - *height = 0; - *bytesPerValue = 0; - *buffer = 0; - return GL_FALSE; - } + *width = 0; + *height = 0; + *bytesPerValue = 0; + *buffer = 0; + return GL_FALSE; } diff --git a/src/mesa/state_tracker/st_cb_accum.c b/src/mesa/state_tracker/st_cb_accum.c index cf2e9db51c..73cd7db18d 100644 --- a/src/mesa/state_tracker/st_cb_accum.c +++ b/src/mesa/state_tracker/st_cb_accum.c @@ -59,6 +59,7 @@ void st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { + struct pipe_context *pipe = ctx->st->pipe; struct st_renderbuffer *acc_strb = st_renderbuffer(rb); struct pipe_surface *acc_ps = acc_strb->surface; const GLint xpos = ctx->DrawBuffer->_Xmin; @@ -69,102 +70,17 @@ st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) const GLfloat g = ctx->Accum.ClearColor[1]; const GLfloat b = ctx->Accum.ClearColor[2]; const GLfloat a = ctx->Accum.ClearColor[3]; + GLfloat *accBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); + int i; - (void) pipe_surface_map(acc_ps); - - switch (acc_ps->format) { - case PIPE_FORMAT_R16G16B16A16_SNORM: - { - const short sr = (short) (32767 * r); - const short sg = (short) (32767 * g); - const short sb = (short) (32767 * b); - const short sa = (short) (32767 * a); - short *acc = ((short *) acc_ps->map) - + (ypos * acc_ps->pitch + xpos) * 4; - int i, j; - for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) { - acc[j*4+0] = sr; - acc[j*4+1] = sg; - acc[j*4+2] = sb; - acc[j*4+3] = sa; - } - acc += acc_ps->pitch * 4; - } - } - break; - default: - assert(0); + for (i = 0; i < width * height; i++) { + accBuf[i*4+0] = r; + accBuf[i*4+1] = g; + accBuf[i*4+2] = b; + accBuf[i*4+3] = a; } - pipe_surface_unmap(acc_ps); -} - - -/** Get block of values from accum buffer, converting to float */ -static void -get_accum_tile(struct pipe_context *pipe, - struct pipe_surface *acc_surf, - int xpos, int ypos, int width, int height, - float *buf) -{ - switch (acc_surf->format) { - case PIPE_FORMAT_R16G16B16A16_SNORM: - { - const short *acc = ((const short *) acc_surf->map) - + (ypos * acc_surf->pitch + xpos) * 4; - int i, j; - for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) { - buf[j*4+0] = SHORT_TO_FLOAT(acc[j*4+0]); - buf[j*4+1] = SHORT_TO_FLOAT(acc[j*4+1]); - buf[j*4+2] = SHORT_TO_FLOAT(acc[j*4+2]); - buf[j*4+3] = SHORT_TO_FLOAT(acc[j*4+3]); - } - acc += acc_surf->pitch * 4; - buf += width * 4; - } - } - break; - default: - assert(0); - } -} - - -/** Put block of values into accum buffer, converting from float */ -static void -put_accum_tile(struct pipe_context *pipe, - struct pipe_surface *acc_surf, - int xpos, int ypos, int width, int height, - const float *buf) -{ - switch (acc_surf->format) { - case PIPE_FORMAT_R16G16B16A16_SNORM: - { - short *acc = ((short *) acc_surf->map) - + (ypos * acc_surf->pitch + xpos) * 4; - int i, j; - for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) { - short r, g, b, a; - UNCLAMPED_FLOAT_TO_SHORT(r, buf[j*4+0]); - UNCLAMPED_FLOAT_TO_SHORT(g, buf[j*4+1]); - UNCLAMPED_FLOAT_TO_SHORT(b, buf[j*4+2]); - UNCLAMPED_FLOAT_TO_SHORT(a, buf[j*4+3]); - acc[j*4+0] = r; - acc[j*4+1] = g; - acc[j*4+2] = b; - acc[j*4+3] = a; - } - acc += acc_surf->pitch * 4; - buf += width * 4; - } - } - break; - default: - assert(0); - } + pipe->put_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf); } @@ -179,19 +95,15 @@ accum_mad(struct pipe_context *pipe, GLfloat scale, GLfloat bias, accBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - (void) pipe_surface_map(acc_ps); - - get_accum_tile(pipe, acc_ps, xpos, ypos, width, height, accBuf); + pipe->get_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf); for (i = 0; i < 4 * width * height; i++) { accBuf[i] = accBuf[i] * scale + bias; } - put_accum_tile(pipe, acc_ps, xpos, ypos, width, height, accBuf); + pipe->put_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf); free(accBuf); - - pipe_surface_unmap(acc_ps); } @@ -201,30 +113,23 @@ accum_accum(struct pipe_context *pipe, GLfloat value, struct pipe_surface *acc_ps, struct pipe_surface *color_ps) { - ubyte *colorMap, *accMap; GLfloat *colorBuf, *accBuf; GLint i; colorBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); accBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - colorMap = pipe_surface_map(color_ps); - accMap = pipe_surface_map(acc_ps); - pipe->get_tile_rgba(pipe, color_ps, xpos, ypos, width, height, colorBuf); - get_accum_tile(pipe, acc_ps, xpos, ypos, width, height, accBuf); + pipe->get_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf); for (i = 0; i < 4 * width * height; i++) { accBuf[i] = accBuf[i] + colorBuf[i] * value; } - put_accum_tile(pipe, acc_ps, xpos, ypos, width, height, accBuf); + pipe->put_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf); free(colorBuf); free(accBuf); - - pipe_surface_unmap(color_ps); - pipe_surface_unmap(acc_ps); } @@ -239,21 +144,15 @@ accum_load(struct pipe_context *pipe, GLfloat value, buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - (void) pipe_surface_map(color_ps); - (void) pipe_surface_map(acc_ps); - pipe->get_tile_rgba(pipe, color_ps, xpos, ypos, width, height, buf); for (i = 0; i < 4 * width * height; i++) { buf[i] = buf[i] * value; } - put_accum_tile(pipe, acc_ps, xpos, ypos, width, height, buf); + pipe->put_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, buf); free(buf); - - pipe_surface_unmap(color_ps); - pipe_surface_unmap(acc_ps); } @@ -270,10 +169,7 @@ accum_return(GLcontext *ctx, GLfloat value, abuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - (void) pipe_surface_map(color_ps); - (void) pipe_surface_map(acc_ps); - - get_accum_tile(pipe, acc_ps, xpos, ypos, width, height, abuf); + pipe->get_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, abuf); if (!colormask[0] || !colormask[1] || !colormask[2] || !colormask[3]) { cbuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); @@ -297,9 +193,6 @@ accum_return(GLcontext *ctx, GLfloat value, free(abuf); if (cbuf) free(cbuf); - - pipe_surface_unmap(color_ps); - pipe_surface_unmap(acc_ps); } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 2db12c653b..5ea2f08b8a 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -1261,15 +1261,9 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, /* alternate path using get/put_tile() */ GLfloat *buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - (void) pipe_surface_map(psRead); - (void) pipe_surface_map(psTex); - pipe->get_tile_rgba(pipe, psRead, srcx, srcy, width, height, buf); pipe->put_tile_rgba(pipe, psTex, 0, 0, width, height, buf); - pipe_surface_unmap(psRead); - pipe_surface_unmap(psTex); - free(buf); } diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index bc0f26ffb0..2d6b3fc749 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -97,9 +97,6 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, return GL_FALSE; } - /* loop here since mapping is refcounted */ - while (strb->surface->map) - pipe_surface_unmap(strb->surface); if (strb->surface->buffer) pipe->winsys->buffer_reference(pipe->winsys, &strb->surface->buffer, NULL); diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c index b0c9275c6f..585fe04dee 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -179,8 +179,6 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, if (!strb) return; - pipe_surface_map(strb->surface); - if (format == GL_RGBA && type == GL_FLOAT) { /* write tile(row) directly into user's buffer */ df = (GLfloat *) _mesa_image_address2d(&clippedPacking, dest, width, @@ -229,8 +227,6 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, } } } - - pipe_surface_unmap(strb->surface); } diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 773fc0012e..19274570a1 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -1063,15 +1063,13 @@ fallback_copy_texsubimage(GLcontext *ctx, dest_surf = pipe->get_tex_surface(pipe, pt, face, level, destZ); - (void) pipe_surface_map(dest_surf); - (void) pipe_surface_map(src_surf); - /* buffer for one row */ data = (GLfloat *) malloc(width * 4 * sizeof(GLfloat)); /* do copy row by row */ for (row = 0; row < height; row++) { - pipe->get_tile_rgba(pipe, src_surf, srcX, srcY + row, width, 1, data); + pipe->get_tile_rgba(pipe, src_surf, srcX, srcY + row, width, 1, + data); /* XXX we're ignoring convolution for now */ if (ctx->_ImageTransferState) { @@ -1080,14 +1078,11 @@ fallback_copy_texsubimage(GLcontext *ctx, width, (GLfloat (*)[4])data); } - pipe->put_tile_rgba(pipe, dest_surf, destX, destY, width, 1, data); + pipe->put_tile_rgba(pipe, dest_surf, destX, destY, width, 1, + data); destY += yStep; } - - (void) pipe_surface_unmap(dest_surf); - (void) pipe_surface_unmap(src_surf); - free(data); } -- cgit v1.2.3 From 271f9dac79a9247de9a57f4d248e404bf1652a13 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Thu, 17 Jan 2008 13:39:14 +0900 Subject: Back-port miscellaneous fixes from internal branch (mostly portability fixes). These are changes that are in our internal branch, but somehow were skipped so far. It was done using visual comparison of the branches -- it is likely that changes are being carried on the wrong way --- src/mesa/pipe/Makefile.template | 9 +++-- src/mesa/pipe/i915simple/i915_prim_vbuf.c | 2 +- src/mesa/pipe/i915simple/i915_surface.c | 1 + src/mesa/pipe/i915simple/i915_texture.c | 12 +++--- src/mesa/pipe/p_compiler.h | 19 +++++++++ src/mesa/pipe/p_format.h | 2 + src/mesa/pipe/p_shader_tokens.h | 3 +- src/mesa/pipe/p_util.h | 64 +++++++++++++++++++------------ src/mesa/pipe/p_winsys.h | 5 ++- src/mesa/pipe/softpipe/sp_prim_setup.c | 2 +- src/mesa/pipe/softpipe/sp_quad_fs.c | 2 +- src/mesa/pipe/softpipe/sp_quad_stipple.c | 2 + src/mesa/pipe/softpipe/sp_surface.c | 1 + src/mesa/pipe/softpipe/sp_texture.c | 2 +- src/mesa/pipe/softpipe/sp_tile_cache.c | 10 ++--- src/mesa/pipe/tgsi/util/tgsi_build.c | 6 +-- src/mesa/state_tracker/st_cb_fbo.c | 2 + src/mesa/state_tracker/st_public.h | 3 ++ 18 files changed, 98 insertions(+), 49 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/pipe/Makefile.template b/src/mesa/pipe/Makefile.template index 3cd07660b6..8e84f8eb2d 100644 --- a/src/mesa/pipe/Makefile.template +++ b/src/mesa/pipe/Makefile.template @@ -17,7 +17,8 @@ INCLUDES = \ -I. \ -I$(TOP)/src/mesa/pipe \ -I$(TOP)/src/mesa \ - -I$(TOP)/include + -I$(TOP)/include \ + $(DRIVER_INCLUDES) ##### RULES ##### @@ -34,11 +35,11 @@ INCLUDES = \ ##### TARGETS ##### -default:: depend symlinks $(LIBNAME) +default: depend symlinks $(LIBNAME) $(LIBNAME): $(OBJECTS) Makefile $(TOP)/src/mesa/pipe/Makefile.template - $(TOP)/bin/mklib -o $@ -static $(OBJECTS) + $(TOP)/bin/mklib -o $@ -static $(OBJECTS) $(DRIVER_LIBS) depend: $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(SYMLINKS) @@ -54,7 +55,7 @@ tags: # Remove .o and backup files -clean: +clean:: -rm -f *.o */*.o *~ *.so *~ server/*.o $(SYMLINKS) -rm -f depend depend.bak diff --git a/src/mesa/pipe/i915simple/i915_prim_vbuf.c b/src/mesa/pipe/i915simple/i915_prim_vbuf.c index d85a6d3c0f..edc62e25e5 100644 --- a/src/mesa/pipe/i915simple/i915_prim_vbuf.c +++ b/src/mesa/pipe/i915simple/i915_prim_vbuf.c @@ -202,7 +202,7 @@ static void i915_vbuf_render_destroy( struct vbuf_render *render ) { struct i915_vbuf_render *i915_render = i915_vbuf_render(render); - free(i915_render); + FREE(i915_render); } diff --git a/src/mesa/pipe/i915simple/i915_surface.c b/src/mesa/pipe/i915simple/i915_surface.c index e3c3cdd2e4..72a65e0fb4 100644 --- a/src/mesa/pipe/i915simple/i915_surface.c +++ b/src/mesa/pipe/i915simple/i915_surface.c @@ -64,6 +64,7 @@ i915_get_tex_surface(struct pipe_context *pipe, ps = pipe->winsys->surface_alloc(pipe->winsys); if (ps) { assert(ps->refcount); + assert(ps->winsys); pipe->winsys->buffer_reference(pipe->winsys, &ps->buffer, tex->buffer); ps->format = pt->format; ps->cpp = pt->cpp; diff --git a/src/mesa/pipe/i915simple/i915_texture.c b/src/mesa/pipe/i915simple/i915_texture.c index 44f72e63cc..6b0a4a96f3 100644 --- a/src/mesa/pipe/i915simple/i915_texture.c +++ b/src/mesa/pipe/i915simple/i915_texture.c @@ -123,7 +123,7 @@ i945_miptree_layout_2d( struct i915_texture *tex ) * 2nd mipmap out past the width of its parent. */ if (pt->first_level != pt->last_level) { - unsigned mip1_width = align(minify(pt->width[0]), align_w) + unsigned mip1_width = align_int(minify(pt->width[0]), align_w) + minify(minify(pt->width[0])); if (mip1_width > pt->width[0]) @@ -133,7 +133,7 @@ i945_miptree_layout_2d( struct i915_texture *tex ) /* Pitch must be a whole number of dwords, even though we * express it in texels. */ - tex->pitch = align(tex->pitch * pt->cpp, 4) / pt->cpp; + tex->pitch = align_int(tex->pitch * pt->cpp, 4) / pt->cpp; tex->total_height = 0; for ( level = pt->first_level ; level <= pt->last_level ; level++ ) { @@ -144,7 +144,7 @@ i945_miptree_layout_2d( struct i915_texture *tex ) if (pt->compressed) img_height = MAX2(1, height/4); else - img_height = align(height, align_h); + img_height = align_int(height, align_h); /* Because the images are packed better, the final offset @@ -155,7 +155,7 @@ i945_miptree_layout_2d( struct i915_texture *tex ) /* Layout_below: step right after second mipmap. */ if (level == pt->first_level + 1) { - x += align(width, align_w); + x += align_int(width, align_w); } else { y += img_height; @@ -531,9 +531,9 @@ i915_texture_release(struct pipe_context *pipe, struct pipe_texture **pt) for (i = 0; i < PIPE_MAX_TEXTURE_LEVELS; i++) if (tex->image_offset[i]) - free(tex->image_offset[i]); + FREE(tex->image_offset[i]); - free(tex); + FREE(tex); } *pt = NULL; } diff --git a/src/mesa/pipe/p_compiler.h b/src/mesa/pipe/p_compiler.h index 4f2c9ef88a..ab9609deab 100644 --- a/src/mesa/pipe/p_compiler.h +++ b/src/mesa/pipe/p_compiler.h @@ -50,6 +50,25 @@ typedef unsigned short ushort; typedef unsigned long long uint64; +#if defined(__MSC__) + +typedef unsigned short uint16_t; +typedef long int32_t; +typedef unsigned long uint32_t; +typedef long long int64_t; +typedef unsigned long long uint64_t; + +#if defined(_WIN64) +typedef unsigned __int64 uintptr_t; +#else +typedef unsigned int uintptr_t; +#endif + +#else +#include +#endif + + #define TRUE 1 #define FALSE 0 diff --git a/src/mesa/pipe/p_format.h b/src/mesa/pipe/p_format.h index b1772b352f..9f60cdbb04 100644 --- a/src/mesa/pipe/p_format.h +++ b/src/mesa/pipe/p_format.h @@ -97,6 +97,8 @@ static INLINE uint pf_get(pipe_format_rgbazs_t f, uint shift, uint mask) return (f >> shift) & mask; } +/* XXX: The bit layout needs to be revised, can't currently encode 10-bit components. */ + #define pf_swizzle_x(f) pf_get(f, 2, 0x7) /**< PIPE_FORMAT_COMP_ */ #define pf_swizzle_y(f) pf_get(f, 5, 0x7) /**< PIPE_FORMAT_COMP_ */ #define pf_swizzle_z(f) pf_get(f, 8, 0x7) /**< PIPE_FORMAT_COMP_ */ diff --git a/src/mesa/pipe/p_shader_tokens.h b/src/mesa/pipe/p_shader_tokens.h index e5922b439f..e9d1d66bda 100644 --- a/src/mesa/pipe/p_shader_tokens.h +++ b/src/mesa/pipe/p_shader_tokens.h @@ -109,7 +109,8 @@ struct tgsi_declaration_interpolation #define TGSI_SEMANTIC_FOG 3 #define TGSI_SEMANTIC_PSIZE 4 #define TGSI_SEMANTIC_GENERIC 5 -#define TGSI_SEMANTIC_COUNT 6 /**< number of semantic values */ +#define TGSI_SEMANTIC_NORMAL 6 +#define TGSI_SEMANTIC_COUNT 7 /**< number of semantic values */ struct tgsi_declaration_semantic { diff --git a/src/mesa/pipe/p_util.h b/src/mesa/pipe/p_util.h index 69ec62e307..573fef9b83 100644 --- a/src/mesa/pipe/p_util.h +++ b/src/mesa/pipe/p_util.h @@ -111,6 +111,32 @@ REALLOC( void *old_ptr, unsigned old_size, unsigned new_size ) #define CALLOC_STRUCT(T) (struct T *) CALLOC(1, sizeof(struct T)) +/** + * Return a pointer aligned to next multiple of N bytes. + */ +static INLINE void * +align_pointer( void *unaligned, uint alignment ) +{ + if (sizeof(void *) == 64) { + union { + void *p; + uint64 u; + } pu; + pu.p = unaligned; + pu.u = (pu.u + alignment - 1) & ~(uint64) (alignment - 1); + return pu.p; + } + else { + /* 32-bit pointers */ + union { + void *p; + uint u; + } pu; + pu.p = unaligned; + pu.u = (pu.u + alignment - 1) & ~(alignment - 1); + return pu.p; + } +} /** * Return memory on given byte alignment @@ -123,19 +149,18 @@ align_malloc(size_t bytes, uint alignment) (void) posix_memalign(& mem, alignment, bytes); return mem; #else - typedef unsigned long int uintptr_t; - uintptr_t ptr, buf; + char *ptr, *buf; assert( alignment > 0 ); - ptr = (uintptr_t) MALLOC(bytes + alignment + sizeof(void *)); + ptr = (char *) MALLOC(bytes + alignment + sizeof(void *)); if (!ptr) return NULL; - buf = (ptr + alignment + sizeof(void *)) & ~(uintptr_t)(alignment - 1); - *(uintptr_t *)(buf - sizeof(void *)) = ptr; + buf = (char *) align_pointer( ptr + sizeof(void *), alignment ); + *(char **)(buf - sizeof(void *)) = ptr; - return (void *) buf; + return buf; #endif /* defined(HAVE_POSIX_MEMALIGN) */ } @@ -169,28 +194,17 @@ align_free(void *ptr) static INLINE void * align16( void *unaligned ) { - if (sizeof(void *) == 64) { - union { - void *p; - uint64 u; - } pu; - pu.p = unaligned; - pu.u = (pu.u + 15) & ~15; - return pu.p; - } - else { - /* 32-bit pointers */ - union { - void *p; - uint u; - } pu; - pu.p = unaligned; - pu.u = (pu.u + 15) & ~15; - return pu.p; - } + return align_pointer( unaligned, 16 ); } +static INLINE int align_int(int x, int align) +{ + return (x + align - 1) & ~(align - 1); +} + + + #if defined(__MSC__) && defined(__WIN32__) static INLINE unsigned ffs( unsigned u ) { diff --git a/src/mesa/pipe/p_winsys.h b/src/mesa/pipe/p_winsys.h index aa9362ec0b..75c6dc7e85 100644 --- a/src/mesa/pipe/p_winsys.h +++ b/src/mesa/pipe/p_winsys.h @@ -79,7 +79,10 @@ struct pipe_winsys /** allocate a new surface (no context dependency) */ struct pipe_surface *(*surface_alloc)(struct pipe_winsys *ws); - /** allocate storage for a pipe_surface */ + /** + * Allocate storage for a pipe_surface. + * Returns 0 if succeeds. + */ int (*surface_alloc_storage)(struct pipe_winsys *ws, struct pipe_surface *surf, unsigned width, unsigned height, diff --git a/src/mesa/pipe/softpipe/sp_prim_setup.c b/src/mesa/pipe/softpipe/sp_prim_setup.c index 7847027cae..89f8df945c 100644 --- a/src/mesa/pipe/softpipe/sp_prim_setup.c +++ b/src/mesa/pipe/softpipe/sp_prim_setup.c @@ -488,7 +488,7 @@ setup_fragcoord_coeff(struct setup_stage *setup) if (setup->softpipe->rasterizer->origin_lower_left) { /* y=0=bottom */ const int winHeight = setup->softpipe->framebuffer.cbufs[0]->height; - setup->coef[0].a0[1] = winHeight - 1; + setup->coef[0].a0[1] = (float) (winHeight - 1); setup->coef[0].dady[1] = -1.0; } else { diff --git a/src/mesa/pipe/softpipe/sp_quad_fs.c b/src/mesa/pipe/softpipe/sp_quad_fs.c index 921dfbaccb..0001c76a80 100644 --- a/src/mesa/pipe/softpipe/sp_quad_fs.c +++ b/src/mesa/pipe/softpipe/sp_quad_fs.c @@ -133,7 +133,7 @@ shade_quad( machine->InterpCoefs = quad->coef; /* Compute X, Y, Z, W vals for this quad */ - setup_pos_vector(quad->posCoef, quad->x0, quad->y0, &machine->QuadPos); + setup_pos_vector(quad->posCoef, (float) quad->x0, (float) quad->y0, &machine->QuadPos); /* run shader */ #if defined(__i386__) || defined(__386__) diff --git a/src/mesa/pipe/softpipe/sp_quad_stipple.c b/src/mesa/pipe/softpipe/sp_quad_stipple.c index 0c42963dfe..8660432259 100644 --- a/src/mesa/pipe/softpipe/sp_quad_stipple.c +++ b/src/mesa/pipe/softpipe/sp_quad_stipple.c @@ -36,6 +36,7 @@ stipple_quad(struct quad_stage *qs, struct quad_header *quad) stipple1 = softpipe->poly_stipple.stipple[y1 % 32]; #if 1 + { const int col0 = quad->x0 % 32; if ((stipple0 & (bit31 >> col0)) == 0) quad->mask &= ~MASK_TOP_LEFT; @@ -48,6 +49,7 @@ stipple_quad(struct quad_stage *qs, struct quad_header *quad) if ((stipple1 & (bit30 >> col0)) == 0) quad->mask &= ~MASK_BOTTOM_RIGHT; + } #else /* We'd like to use this code, but we'd need to redefine * MASK_TOP_LEFT to be (1 << 1) and MASK_TOP_RIGHT to be (1 << 0), diff --git a/src/mesa/pipe/softpipe/sp_surface.c b/src/mesa/pipe/softpipe/sp_surface.c index 6c080d5b5c..a580fb3e82 100644 --- a/src/mesa/pipe/softpipe/sp_surface.c +++ b/src/mesa/pipe/softpipe/sp_surface.c @@ -50,6 +50,7 @@ softpipe_get_tex_surface(struct pipe_context *pipe, ps = pipe->winsys->surface_alloc(pipe->winsys); if (ps) { assert(ps->refcount); + assert(ps->winsys); pipe->winsys->buffer_reference(pipe->winsys, &ps->buffer, spt->buffer); ps->format = pt->format; ps->cpp = pt->cpp; diff --git a/src/mesa/pipe/softpipe/sp_texture.c b/src/mesa/pipe/softpipe/sp_texture.c index e5e6bfe01b..532bcfcc51 100644 --- a/src/mesa/pipe/softpipe/sp_texture.c +++ b/src/mesa/pipe/softpipe/sp_texture.c @@ -126,7 +126,7 @@ softpipe_texture_release(struct pipe_context *pipe, struct pipe_texture **pt) pipe->winsys->buffer_reference(pipe->winsys, &spt->buffer, NULL); - free(spt); + FREE(spt); } *pt = NULL; } diff --git a/src/mesa/pipe/softpipe/sp_tile_cache.c b/src/mesa/pipe/softpipe/sp_tile_cache.c index 6515ce668c..1974f77459 100644 --- a/src/mesa/pipe/softpipe/sp_tile_cache.c +++ b/src/mesa/pipe/softpipe/sp_tile_cache.c @@ -286,7 +286,7 @@ clear_tile(struct softpipe_cached_tile *tile, else { for (i = 0; i < TILE_SIZE; i++) { for (j = 0; j < TILE_SIZE; j++) { - tile->data.depth16[i][j] = clear_value; + tile->data.depth16[i][j] = (ushort) clear_value; } } } @@ -564,10 +564,10 @@ sp_tile_cache_clear(struct softpipe_tile_cache *tc, uint clearValue) r = g = b = a = 0; } - tc->clear_color[0] = r / 255.0; - tc->clear_color[1] = g / 255.0; - tc->clear_color[2] = b / 255.0; - tc->clear_color[3] = a / 255.0; + tc->clear_color[0] = r / 255.0f; + tc->clear_color[1] = g / 255.0f; + tc->clear_color[2] = b / 255.0f; + tc->clear_color[3] = a / 255.0f; #if TILE_CLEAR_OPTIMIZATION /* set flags to indicate all the tiles are cleared */ diff --git a/src/mesa/pipe/tgsi/util/tgsi_build.c b/src/mesa/pipe/tgsi/util/tgsi_build.c index 19b2aad921..67f7d2c2c2 100644 --- a/src/mesa/pipe/tgsi/util/tgsi_build.c +++ b/src/mesa/pipe/tgsi/util/tgsi_build.c @@ -365,7 +365,7 @@ tgsi_build_immediate( immediate = tgsi_default_immediate(); - header_bodysize_grow( header ); + header_bodysize_grow( header ); return immediate; } @@ -415,7 +415,7 @@ tgsi_build_full_immediate( struct tgsi_header *header, unsigned maxsize ) { - unsigned size = 0, i; + unsigned size = 0, i; struct tgsi_immediate *immediate; if( maxsize <= size ) @@ -433,7 +433,7 @@ tgsi_build_full_immediate( if32 = (struct tgsi_immediate_float32 *) &tokens[size]; size++; - *if32 = tgsi_build_immediate_float32( + *if32 = tgsi_build_immediate_float32( full_imm->u.ImmediateFloat32[i].Float, immediate, header ); diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 2d6b3fc749..f02cb3d133 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -93,6 +93,8 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, if (!strb->surface) { strb->surface = pipe->winsys->surface_alloc(pipe->winsys); assert(strb->surface); + assert(strb->surface->refcount); + assert(strb->surface->winsys); if (!strb->surface) return GL_FALSE; } diff --git a/src/mesa/state_tracker/st_public.h b/src/mesa/state_tracker/st_public.h index ed5ef1f159..78a8fde82b 100644 --- a/src/mesa/state_tracker/st_public.h +++ b/src/mesa/state_tracker/st_public.h @@ -28,6 +28,9 @@ #ifndef ST_PUBLIC_H #define ST_PUBLIC_H +#include "GL/gl.h" +#include "GL/internal/glcore.h" /* for __GLcontextModes */ + #include "pipe/p_compiler.h" #include "pipe/p_format.h" -- cgit v1.2.3 From 1e0d30a515e4cac891b6c590f12a33e0e8a8e295 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Fri, 25 Jan 2008 20:53:31 +0000 Subject: gallium: rename pipe_buffer_handle to pipe_buffer, rework pipebuffer/ code Provide an actual definition of the pipe_buffer struct, containing the parameters used to create the buffer, and its refcount. Shift refcounting buffers out of the winsys interface, similar to surfaces & textures. Rework pipebuffer/ to reflect the fact these changes, and also Michel's reworking of the buffer interface. --- src/mesa/drivers/dri/intel_winsys/intel_winsys.h | 23 ++-- .../drivers/dri/intel_winsys/intel_winsys_i915.c | 2 +- .../drivers/dri/intel_winsys/intel_winsys_pipe.c | 53 ++++---- src/mesa/drivers/x11/xm_winsys.c | 24 ++-- src/mesa/pipe/cell/ppu/cell_draw_arrays.c | 2 +- src/mesa/pipe/cell/ppu/cell_draw_arrays.h | 2 +- src/mesa/pipe/cell/ppu/cell_texture.h | 2 +- src/mesa/pipe/failover/fo_context.c | 2 +- src/mesa/pipe/i915simple/i915_blit.c | 6 +- src/mesa/pipe/i915simple/i915_blit.h | 6 +- src/mesa/pipe/i915simple/i915_context.c | 2 +- src/mesa/pipe/i915simple/i915_context.h | 4 +- src/mesa/pipe/i915simple/i915_prim_vbuf.c | 3 +- src/mesa/pipe/i915simple/i915_state_emit.c | 2 +- src/mesa/pipe/i915simple/i915_surface.c | 2 +- src/mesa/pipe/i915simple/i915_texture.c | 2 +- src/mesa/pipe/i915simple/i915_winsys.h | 4 +- src/mesa/pipe/i965simple/brw_blit.c | 6 +- src/mesa/pipe/i965simple/brw_blit.h | 8 +- src/mesa/pipe/i965simple/brw_context.h | 6 +- src/mesa/pipe/i965simple/brw_draw.c | 4 +- src/mesa/pipe/i965simple/brw_draw.h | 2 +- src/mesa/pipe/i965simple/brw_draw_upload.c | 4 +- src/mesa/pipe/i965simple/brw_state.h | 2 +- src/mesa/pipe/i965simple/brw_state_pool.c | 7 +- src/mesa/pipe/i965simple/brw_surface.c | 2 +- src/mesa/pipe/i965simple/brw_tex_layout.c | 3 +- src/mesa/pipe/i965simple/brw_winsys.h | 8 +- src/mesa/pipe/i965simple/brw_wm_surface_state.c | 2 +- src/mesa/pipe/p_context.h | 2 +- src/mesa/pipe/p_inlines.h | 43 +++++-- src/mesa/pipe/p_state.h | 23 +++- src/mesa/pipe/p_winsys.h | 17 +-- src/mesa/pipe/pipebuffer/Makefile | 2 - src/mesa/pipe/pipebuffer/pb_buffer.c | 49 ++++++-- src/mesa/pipe/pipebuffer/pb_buffer.h | 111 ++++++++-------- src/mesa/pipe/pipebuffer/pb_buffer_client.c | 60 ++++----- src/mesa/pipe/pipebuffer/pb_buffer_fenced.c | 102 ++++++--------- src/mesa/pipe/pipebuffer/pb_buffer_fenced.h | 10 +- src/mesa/pipe/pipebuffer/pb_buffer_handle.c | 140 --------------------- src/mesa/pipe/pipebuffer/pb_buffer_handle.h | 120 ------------------ src/mesa/pipe/pipebuffer/pb_buffer_malloc.c | 41 +++--- src/mesa/pipe/pipebuffer/pb_buffer_null.c | 98 --------------- src/mesa/pipe/pipebuffer/pb_bufmgr.h | 24 ++-- src/mesa/pipe/pipebuffer/pb_bufmgr_fenced.c | 36 +++--- src/mesa/pipe/pipebuffer/pb_bufmgr_mm.c | 88 ++++++------- src/mesa/pipe/pipebuffer/pb_bufmgr_pool.c | 75 +++++------ src/mesa/pipe/softpipe/sp_context.c | 2 +- src/mesa/pipe/softpipe/sp_draw_arrays.c | 2 +- src/mesa/pipe/softpipe/sp_state.h | 2 +- src/mesa/pipe/softpipe/sp_state_fs.c | 7 +- src/mesa/pipe/softpipe/sp_texture.c | 4 +- src/mesa/pipe/softpipe/sp_texture.h | 2 +- src/mesa/pipe/xlib/xm_winsys.c | 80 +++++------- src/mesa/pipe/xlib/xm_winsys_aub.c | 44 +++---- src/mesa/pipe/xlib/xm_winsys_aub.h | 4 +- src/mesa/state_tracker/st_atom_constbuf.c | 3 +- src/mesa/state_tracker/st_cb_bufferobjects.c | 5 +- src/mesa/state_tracker/st_cb_bufferobjects.h | 4 +- src/mesa/state_tracker/st_cb_fbo.c | 4 +- src/mesa/state_tracker/st_context.c | 3 +- src/mesa/state_tracker/st_draw.c | 21 ++-- 62 files changed, 529 insertions(+), 894 deletions(-) delete mode 100644 src/mesa/pipe/pipebuffer/pb_buffer_handle.c delete mode 100644 src/mesa/pipe/pipebuffer/pb_buffer_handle.h delete mode 100644 src/mesa/pipe/pipebuffer/pb_buffer_null.c (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/drivers/dri/intel_winsys/intel_winsys.h b/src/mesa/drivers/dri/intel_winsys/intel_winsys.h index 89e63e0a79..ffc40782be 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_winsys.h +++ b/src/mesa/drivers/dri/intel_winsys/intel_winsys.h @@ -28,10 +28,12 @@ #ifndef INTEL_WINSYS_H #define INTEL_WINSYS_H +#include "pipe/p_state.h" + struct intel_context; struct pipe_context; struct pipe_winsys; -struct pipe_buffer_handle; +struct pipe_buffer; struct _DriBufferObject; struct pipe_winsys * @@ -49,20 +51,21 @@ intel_create_i915simple( struct intel_context *intel, struct pipe_winsys *winsys ); +struct intel_buffer { + struct pipe_buffer base; + struct _DriBufferObject *driBO; +}; -/* Turn the pipe opaque buffer pointer into a dri_bufmgr opaque - * buffer pointer... - */ -static INLINE struct _DriBufferObject * -dri_bo( struct pipe_buffer_handle *bo ) +static INLINE struct intel_buffer * +intel_buffer( struct pipe_buffer *buf ) { - return (struct _DriBufferObject *)bo; + return (struct intel_buffer *)buf; } -static INLINE struct pipe_buffer_handle * -pipe_bo( struct _DriBufferObject *bo ) +static INLINE struct _DriBufferObject * +dri_bo( struct pipe_buffer *buf ) { - return (struct pipe_buffer_handle *)bo; + return intel_buffer(buf)->driBO; } diff --git a/src/mesa/drivers/dri/intel_winsys/intel_winsys_i915.c b/src/mesa/drivers/dri/intel_winsys/intel_winsys_i915.c index 8e0eea4392..1ba6a9e1b2 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_winsys_i915.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_winsys_i915.c @@ -85,7 +85,7 @@ static void intel_i915_batch_dword( struct i915_winsys *sws, } static void intel_i915_batch_reloc( struct i915_winsys *sws, - struct pipe_buffer_handle *buf, + struct pipe_buffer *buf, unsigned access_flags, unsigned delta ) { diff --git a/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c b/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c index 43ed0602a4..910c0d2cc5 100644 --- a/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c +++ b/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c @@ -43,6 +43,7 @@ #include "pipe/p_defines.h" #include "pipe/p_state.h" #include "pipe/p_util.h" +#include "pipe/p_inlines.h" @@ -65,7 +66,7 @@ intel_pipe_winsys( struct pipe_winsys *winsys ) /* Most callbacks map direcly onto dri_bufmgr operations: */ static void *intel_buffer_map(struct pipe_winsys *winsys, - struct pipe_buffer_handle *buf, + struct pipe_buffer *buf, unsigned flags ) { unsigned drm_flags = 0; @@ -80,26 +81,17 @@ static void *intel_buffer_map(struct pipe_winsys *winsys, } static void intel_buffer_unmap(struct pipe_winsys *winsys, - struct pipe_buffer_handle *buf) + struct pipe_buffer *buf) { driBOUnmap( dri_bo(buf) ); } static void -intel_buffer_reference(struct pipe_winsys *winsys, - struct pipe_buffer_handle **ptr, - struct pipe_buffer_handle *buf) +intel_buffer_destroy(struct pipe_winsys *winsys, + struct pipe_buffer *buf) { - if (*ptr) { - driBOUnReference( dri_bo(*ptr) ); - *ptr = NULL; - } - - if (buf) { - driBOReference( dri_bo(buf) ); - *ptr = buf; - } + driBOUnReference( dri_bo(buf) ); } @@ -107,16 +99,21 @@ intel_buffer_reference(struct pipe_winsys *winsys, * for all buffers. * Grabs the hardware lock! */ -static struct pipe_buffer_handle * +static struct pipe_buffer * intel_buffer_create(struct pipe_winsys *winsys, unsigned alignment, unsigned usage, unsigned size ) { - struct _DriBufferObject *buffer; + struct intel_buffer *buffer = CALLOC_STRUCT( intel_buffer ); struct intel_pipe_winsys *iws = intel_pipe_winsys(winsys); unsigned flags = 0; + buffer->base.refcount = 1; + buffer->base.alignment = alignment; + buffer->base.usage = usage; + buffer->base.size = size; + if (usage & (PIPE_BUFFER_USAGE_VERTEX /*| IWS_BUFFER_USAGE_LOCAL*/)) { flags |= DRM_BO_FLAG_MEM_LOCAL | DRM_BO_FLAG_CACHED; } else { @@ -143,20 +140,24 @@ intel_buffer_create(struct pipe_winsys *winsys, #endif driGenBuffers( iws->regionPool, - "pipe buffer", 1, &buffer, alignment, flags, 0 ); - driBOData( buffer, size, NULL, 0 ); - return pipe_bo(buffer); + "pipe buffer", 1, &buffer->driBO, alignment, flags, 0 ); + + driBOData( buffer->driBO, size, NULL, 0 ); + + return &buffer->base; } -static struct pipe_buffer_handle * +static struct pipe_buffer * intel_user_buffer_create(struct pipe_winsys *winsys, void *ptr, unsigned bytes) { - struct _DriBufferObject *buffer; + struct intel_buffer *buffer = CALLOC_STRUCT( intel_buffer ); struct intel_pipe_winsys *iws = intel_pipe_winsys(winsys); + driGenUserBuffer( iws->regionPool, - "pipe user buffer", &buffer, ptr, bytes); - return pipe_bo(buffer); + "pipe user buffer", &buffer->driBO, ptr, bytes); + + return &buffer->base; } @@ -224,7 +225,7 @@ intel_i915_surface_alloc_storage(struct pipe_winsys *winsys, return -1; if(ret) { - winsys->buffer_reference(winsys, &surf->buffer, NULL); + pipe_buffer_reference(winsys, &surf->buffer, NULL); return ret; } @@ -239,7 +240,7 @@ intel_i915_surface_release(struct pipe_winsys *winsys, struct pipe_surface **s) surf->refcount--; if (surf->refcount == 0) { if (surf->buffer) - winsys->buffer_reference(winsys, &surf->buffer, NULL); + pipe_buffer_reference(winsys, &surf->buffer, NULL); free(surf); } *s = NULL; @@ -279,7 +280,7 @@ intel_create_pipe_winsys( int fd ) iws->winsys.user_buffer_create = intel_user_buffer_create; iws->winsys.buffer_map = intel_buffer_map; iws->winsys.buffer_unmap = intel_buffer_unmap; - iws->winsys.buffer_reference = intel_buffer_reference; + iws->winsys.buffer_destroy = intel_buffer_destroy; iws->winsys.flush_frontbuffer = intel_flush_frontbuffer; iws->winsys.printf = intel_printf; iws->winsys.get_name = intel_get_name; diff --git a/src/mesa/drivers/x11/xm_winsys.c b/src/mesa/drivers/x11/xm_winsys.c index dafbe96a1e..a690df2772 100644 --- a/src/mesa/drivers/x11/xm_winsys.c +++ b/src/mesa/drivers/x11/xm_winsys.c @@ -71,15 +71,15 @@ struct xm_buffer * buffer pointer... */ static inline struct xm_buffer * -xm_bo( struct pipe_buffer_handle *bo ) +xm_bo( struct pipe_buffer *bo ) { return (struct xm_buffer *) bo; } -static inline struct pipe_buffer_handle * +static inline struct pipe_buffer * pipe_bo( struct xm_buffer *bo ) { - return (struct pipe_buffer_handle *) bo; + return (struct pipe_buffer *) bo; } /* Turn a softpipe winsys into an xm/softpipe winsys: @@ -94,7 +94,7 @@ xm_winsys(struct softpipe_winsys *sws) /* Most callbacks map direcly onto dri_bufmgr operations: */ static void * -xm_buffer_map(struct pipe_winsys *pws, struct pipe_buffer_handle *buf, +xm_buffer_map(struct pipe_winsys *pws, struct pipe_buffer *buf, unsigned flags) { struct xm_buffer *xm_buf = xm_bo(buf); @@ -103,7 +103,7 @@ xm_buffer_map(struct pipe_winsys *pws, struct pipe_buffer_handle *buf, } static void -xm_buffer_unmap(struct pipe_winsys *pws, struct pipe_buffer_handle *buf) +xm_buffer_unmap(struct pipe_winsys *pws, struct pipe_buffer *buf) { struct xm_buffer *xm_buf = xm_bo(buf); xm_buf->mapped = NULL; @@ -111,8 +111,8 @@ xm_buffer_unmap(struct pipe_winsys *pws, struct pipe_buffer_handle *buf) static void xm_buffer_reference(struct pipe_winsys *pws, - struct pipe_buffer_handle **ptr, - struct pipe_buffer_handle *buf) + struct pipe_buffer **ptr, + struct pipe_buffer *buf) { if (*ptr) { struct xm_buffer *oldBuf = xm_bo(*ptr); @@ -139,7 +139,7 @@ xm_buffer_reference(struct pipe_winsys *pws, } static void -xm_buffer_data(struct pipe_winsys *pws, struct pipe_buffer_handle *buf, +xm_buffer_data(struct pipe_winsys *pws, struct pipe_buffer *buf, unsigned size, const void *data, unsigned usage) { struct xm_buffer *xm_buf = xm_bo(buf); @@ -155,7 +155,7 @@ xm_buffer_data(struct pipe_winsys *pws, struct pipe_buffer_handle *buf, } static void -xm_buffer_subdata(struct pipe_winsys *pws, struct pipe_buffer_handle *buf, +xm_buffer_subdata(struct pipe_winsys *pws, struct pipe_buffer *buf, unsigned long offset, unsigned long size, const void *data) { struct xm_buffer *xm_buf = xm_bo(buf); @@ -166,7 +166,7 @@ xm_buffer_subdata(struct pipe_winsys *pws, struct pipe_buffer_handle *buf, } static void -xm_buffer_get_subdata(struct pipe_winsys *pws, struct pipe_buffer_handle *buf, +xm_buffer_get_subdata(struct pipe_winsys *pws, struct pipe_buffer *buf, unsigned long offset, unsigned long size, void *data) { const struct xm_buffer *xm_buf = xm_bo(buf); @@ -209,7 +209,7 @@ xm_get_name(struct pipe_winsys *pws) } -static struct pipe_buffer_handle * +static struct pipe_buffer * xm_buffer_create(struct pipe_winsys *pws, unsigned alignment, unsigned flags, @@ -224,7 +224,7 @@ xm_buffer_create(struct pipe_winsys *pws, /** * Create buffer which wraps user-space data. */ -static struct pipe_buffer_handle * +static struct pipe_buffer * xm_user_buffer_create(struct pipe_winsys *pws, void *ptr, unsigned bytes) { struct xm_buffer *buffer = CALLOC_STRUCT(xm_buffer); diff --git a/src/mesa/pipe/cell/ppu/cell_draw_arrays.c b/src/mesa/pipe/cell/ppu/cell_draw_arrays.c index 537cec8785..8286da712c 100644 --- a/src/mesa/pipe/cell/ppu/cell_draw_arrays.c +++ b/src/mesa/pipe/cell/ppu/cell_draw_arrays.c @@ -89,7 +89,7 @@ cell_draw_arrays(struct pipe_context *pipe, unsigned mode, */ boolean cell_draw_elements(struct pipe_context *pipe, - struct pipe_buffer_handle *indexBuffer, + struct pipe_buffer *indexBuffer, unsigned indexSize, unsigned mode, unsigned start, unsigned count) { diff --git a/src/mesa/pipe/cell/ppu/cell_draw_arrays.h b/src/mesa/pipe/cell/ppu/cell_draw_arrays.h index bd5b703f3b..d5df4aa05f 100644 --- a/src/mesa/pipe/cell/ppu/cell_draw_arrays.h +++ b/src/mesa/pipe/cell/ppu/cell_draw_arrays.h @@ -33,7 +33,7 @@ boolean cell_draw_arrays(struct pipe_context *pipe, unsigned mode, unsigned start, unsigned count); boolean cell_draw_elements(struct pipe_context *pipe, - struct pipe_buffer_handle *indexBuffer, + struct pipe_buffer *indexBuffer, unsigned indexSize, unsigned mode, unsigned start, unsigned count); diff --git a/src/mesa/pipe/cell/ppu/cell_texture.h b/src/mesa/pipe/cell/ppu/cell_texture.h index 97d8bd1230..ef5808c086 100644 --- a/src/mesa/pipe/cell/ppu/cell_texture.h +++ b/src/mesa/pipe/cell/ppu/cell_texture.h @@ -44,7 +44,7 @@ struct cell_texture /* The data is held here: */ - struct pipe_buffer_handle *buffer; + struct pipe_buffer *buffer; unsigned long buffer_size; }; diff --git a/src/mesa/pipe/failover/fo_context.c b/src/mesa/pipe/failover/fo_context.c index a1291f583b..3799c4dfb0 100644 --- a/src/mesa/pipe/failover/fo_context.c +++ b/src/mesa/pipe/failover/fo_context.c @@ -46,7 +46,7 @@ static void failover_destroy( struct pipe_context *pipe ) static boolean failover_draw_elements( struct pipe_context *pipe, - struct pipe_buffer_handle *indexBuffer, + struct pipe_buffer *indexBuffer, unsigned indexSize, unsigned prim, unsigned start, unsigned count) { diff --git a/src/mesa/pipe/i915simple/i915_blit.c b/src/mesa/pipe/i915simple/i915_blit.c index 6e95313a0d..d49876f970 100644 --- a/src/mesa/pipe/i915simple/i915_blit.c +++ b/src/mesa/pipe/i915simple/i915_blit.c @@ -38,7 +38,7 @@ void i915_fill_blit(struct i915_context *i915, unsigned cpp, short dst_pitch, - struct pipe_buffer_handle *dst_buffer, + struct pipe_buffer *dst_buffer, unsigned dst_offset, short x, short y, short w, short h, @@ -87,10 +87,10 @@ void i915_copy_blit( struct i915_context *i915, unsigned cpp, short src_pitch, - struct pipe_buffer_handle *src_buffer, + struct pipe_buffer *src_buffer, unsigned src_offset, short dst_pitch, - struct pipe_buffer_handle *dst_buffer, + struct pipe_buffer *dst_buffer, unsigned dst_offset, short src_x, short src_y, short dst_x, short dst_y, diff --git a/src/mesa/pipe/i915simple/i915_blit.h b/src/mesa/pipe/i915simple/i915_blit.h index 7ea4e979ec..d7a66be10a 100644 --- a/src/mesa/pipe/i915simple/i915_blit.h +++ b/src/mesa/pipe/i915simple/i915_blit.h @@ -33,10 +33,10 @@ extern void i915_copy_blit(struct i915_context *i915, unsigned cpp, short src_pitch, - struct pipe_buffer_handle *src_buffer, + struct pipe_buffer *src_buffer, unsigned src_offset, short dst_pitch, - struct pipe_buffer_handle *dst_buffer, + struct pipe_buffer *dst_buffer, unsigned dst_offset, short srcx, short srcy, short dstx, short dsty, @@ -45,7 +45,7 @@ extern void i915_copy_blit(struct i915_context *i915, extern void i915_fill_blit(struct i915_context *i915, unsigned cpp, short dst_pitch, - struct pipe_buffer_handle *dst_buffer, + struct pipe_buffer *dst_buffer, unsigned dst_offset, short x, short y, short w, short h, unsigned color); diff --git a/src/mesa/pipe/i915simple/i915_context.c b/src/mesa/pipe/i915simple/i915_context.c index c2b96d2554..497623a700 100644 --- a/src/mesa/pipe/i915simple/i915_context.c +++ b/src/mesa/pipe/i915simple/i915_context.c @@ -166,7 +166,7 @@ static void i915_destroy( struct pipe_context *pipe ) static boolean i915_draw_elements( struct pipe_context *pipe, - struct pipe_buffer_handle *indexBuffer, + struct pipe_buffer *indexBuffer, unsigned indexSize, unsigned prim, unsigned start, unsigned count) { diff --git a/src/mesa/pipe/i915simple/i915_context.h b/src/mesa/pipe/i915simple/i915_context.h index 2f1f036993..b4ea63c3e7 100644 --- a/src/mesa/pipe/i915simple/i915_context.h +++ b/src/mesa/pipe/i915simple/i915_context.h @@ -172,7 +172,7 @@ struct i915_texture { /* The data is held here: */ - struct pipe_buffer_handle *buffer; + struct pipe_buffer *buffer; }; struct i915_context @@ -204,7 +204,7 @@ struct i915_context unsigned *batch_start; /** Vertex buffer */ - struct pipe_buffer_handle *vbo; + struct pipe_buffer *vbo; struct i915_state current; unsigned hardware_dirty; diff --git a/src/mesa/pipe/i915simple/i915_prim_vbuf.c b/src/mesa/pipe/i915simple/i915_prim_vbuf.c index 0887f9a1c6..39154b2488 100644 --- a/src/mesa/pipe/i915simple/i915_prim_vbuf.c +++ b/src/mesa/pipe/i915simple/i915_prim_vbuf.c @@ -42,6 +42,7 @@ #include "pipe/draw/draw_vbuf.h" #include "pipe/p_util.h" +#include "pipe/p_inlines.h" #include "pipe/p_winsys.h" #include "i915_context.h" @@ -192,7 +193,7 @@ i915_vbuf_render_release_vertices( struct vbuf_render *render, assert(i915->vbo); winsys->buffer_unmap(winsys, i915->vbo); - winsys->buffer_reference(winsys, &i915->vbo, NULL); + pipe_buffer_reference(winsys, &i915->vbo, NULL); } diff --git a/src/mesa/pipe/i915simple/i915_state_emit.c b/src/mesa/pipe/i915simple/i915_state_emit.c index 8598eacc9c..657f523893 100644 --- a/src/mesa/pipe/i915simple/i915_state_emit.c +++ b/src/mesa/pipe/i915simple/i915_state_emit.c @@ -278,7 +278,7 @@ i915_emit_hardware_state(struct i915_context *i915 ) OUT_BATCH(enabled); for (unit = 0; unit < I915_TEX_UNITS; unit++) { if (enabled & (1 << unit)) { - struct pipe_buffer_handle *buf = + struct pipe_buffer *buf = i915->texture[unit]->buffer; uint offset = 0; assert(buf); diff --git a/src/mesa/pipe/i915simple/i915_surface.c b/src/mesa/pipe/i915simple/i915_surface.c index e625f5a68c..8ef02b99cd 100644 --- a/src/mesa/pipe/i915simple/i915_surface.c +++ b/src/mesa/pipe/i915simple/i915_surface.c @@ -65,7 +65,7 @@ i915_get_tex_surface(struct pipe_context *pipe, if (ps) { assert(ps->refcount); assert(ps->winsys); - pipe->winsys->buffer_reference(pipe->winsys, &ps->buffer, tex->buffer); + pipe_buffer_reference(pipe->winsys, &ps->buffer, tex->buffer); ps->format = pt->format; ps->cpp = pt->cpp; ps->width = pt->width[level]; diff --git a/src/mesa/pipe/i915simple/i915_texture.c b/src/mesa/pipe/i915simple/i915_texture.c index bf80e18233..61944fe7d9 100644 --- a/src/mesa/pipe/i915simple/i915_texture.c +++ b/src/mesa/pipe/i915simple/i915_texture.c @@ -523,7 +523,7 @@ i915_texture_release(struct pipe_context *pipe, struct pipe_texture **pt) DBG("%s deleting %p\n", __FUNCTION__, (void *) tex); */ - pipe->winsys->buffer_reference(pipe->winsys, &tex->buffer, NULL); + pipe_buffer_reference(pipe->winsys, &tex->buffer, NULL); for (i = 0; i < PIPE_MAX_TEXTURE_LEVELS; i++) if (tex->image_offset[i]) diff --git a/src/mesa/pipe/i915simple/i915_winsys.h b/src/mesa/pipe/i915simple/i915_winsys.h index 2c0f335d34..fe49710852 100644 --- a/src/mesa/pipe/i915simple/i915_winsys.h +++ b/src/mesa/pipe/i915simple/i915_winsys.h @@ -50,7 +50,7 @@ * etc. */ -struct pipe_buffer_handle; +struct pipe_buffer; struct pipe_winsys; @@ -93,7 +93,7 @@ struct i915_winsys { * I915_BUFFER_ACCESS_READ macros. */ void (*batch_reloc)( struct i915_winsys *sws, - struct pipe_buffer_handle *buf, + struct pipe_buffer *buf, unsigned access_flags, unsigned delta ); diff --git a/src/mesa/pipe/i965simple/brw_blit.c b/src/mesa/pipe/i965simple/brw_blit.c index 4692129e40..bbd366294f 100644 --- a/src/mesa/pipe/i965simple/brw_blit.c +++ b/src/mesa/pipe/i965simple/brw_blit.c @@ -42,7 +42,7 @@ void brw_fill_blit(struct brw_context *brw, unsigned cpp, short dst_pitch, - struct pipe_buffer_handle *dst_buffer, + struct pipe_buffer *dst_buffer, unsigned dst_offset, boolean dst_tiled, short x, short y, @@ -113,11 +113,11 @@ static unsigned translate_raster_op(unsigned logicop) void brw_copy_blit(struct brw_context *brw, unsigned cpp, short src_pitch, - struct pipe_buffer_handle *src_buffer, + struct pipe_buffer *src_buffer, unsigned src_offset, boolean src_tiled, short dst_pitch, - struct pipe_buffer_handle *dst_buffer, + struct pipe_buffer *dst_buffer, unsigned dst_offset, boolean dst_tiled, short src_x, short src_y, diff --git a/src/mesa/pipe/i965simple/brw_blit.h b/src/mesa/pipe/i965simple/brw_blit.h index 371a135375..7f17a70173 100644 --- a/src/mesa/pipe/i965simple/brw_blit.h +++ b/src/mesa/pipe/i965simple/brw_blit.h @@ -3,13 +3,13 @@ #include "pipe/p_compiler.h" -struct pipe_buffer_handle; +struct pipe_buffer; struct brw_context; void brw_fill_blit(struct brw_context *intel, unsigned cpp, short dst_pitch, - struct pipe_buffer_handle *dst_buffer, + struct pipe_buffer *dst_buffer, unsigned dst_offset, boolean dst_tiled, short x, short y, @@ -18,11 +18,11 @@ void brw_fill_blit(struct brw_context *intel, void brw_copy_blit(struct brw_context *intel, unsigned cpp, short src_pitch, - struct pipe_buffer_handle *src_buffer, + struct pipe_buffer *src_buffer, unsigned src_offset, boolean src_tiled, short dst_pitch, - struct pipe_buffer_handle *dst_buffer, + struct pipe_buffer *dst_buffer, unsigned dst_offset, boolean dst_tiled, short src_x, short src_y, diff --git a/src/mesa/pipe/i965simple/brw_context.h b/src/mesa/pipe/i965simple/brw_context.h index c610a435e0..65664d853d 100644 --- a/src/mesa/pipe/i965simple/brw_context.h +++ b/src/mesa/pipe/i965simple/brw_context.h @@ -260,7 +260,7 @@ struct brw_texture { /* The data is held here: */ - struct pipe_buffer_handle *buffer; + struct pipe_buffer *buffer; }; /* Data about a particular attempt to compile a program. Note that @@ -350,7 +350,7 @@ struct brw_surface_binding_table { struct brw_cache; struct brw_mem_pool { - struct pipe_buffer_handle *buffer; + struct pipe_buffer *buffer; unsigned size; unsigned offset; /* offset of first free byte */ @@ -615,7 +615,7 @@ struct brw_context unsigned nr_surfaces; unsigned max_threads; - struct pipe_buffer_handle *scratch_buffer; + struct pipe_buffer *scratch_buffer; unsigned scratch_buffer_size; unsigned sampler_count; diff --git a/src/mesa/pipe/i965simple/brw_draw.c b/src/mesa/pipe/i965simple/brw_draw.c index acfb524a30..7598e3dc8a 100644 --- a/src/mesa/pipe/i965simple/brw_draw.c +++ b/src/mesa/pipe/i965simple/brw_draw.c @@ -144,7 +144,7 @@ static boolean brw_emit_prim( struct brw_context *brw, * fallback conditions. */ static boolean brw_try_draw_elements( struct pipe_context *pipe, - struct pipe_buffer_handle *index_buffer, + struct pipe_buffer *index_buffer, unsigned index_size, unsigned mode, unsigned start, @@ -183,7 +183,7 @@ static boolean brw_try_draw_elements( struct pipe_context *pipe, static boolean brw_draw_elements( struct pipe_context *pipe, - struct pipe_buffer_handle *indexBuffer, + struct pipe_buffer *indexBuffer, unsigned indexSize, unsigned mode, unsigned start, diff --git a/src/mesa/pipe/i965simple/brw_draw.h b/src/mesa/pipe/i965simple/brw_draw.h index 053f2efb9d..62fe0d5d0e 100644 --- a/src/mesa/pipe/i965simple/brw_draw.h +++ b/src/mesa/pipe/i965simple/brw_draw.h @@ -42,7 +42,7 @@ boolean brw_upload_vertices( struct brw_context *brw, unsigned max_index ); boolean brw_upload_indices(struct brw_context *brw, - const struct pipe_buffer_handle *index_buffer, + const struct pipe_buffer *index_buffer, int ib_size, int start, int count); boolean brw_upload_vertex_buffers( struct brw_context *brw ); diff --git a/src/mesa/pipe/i965simple/brw_draw_upload.c b/src/mesa/pipe/i965simple/brw_draw_upload.c index 43e53914e9..aa85d93866 100644 --- a/src/mesa/pipe/i965simple/brw_draw_upload.c +++ b/src/mesa/pipe/i965simple/brw_draw_upload.c @@ -47,7 +47,7 @@ struct brw_array_state { unsigned dword; } vb0; - struct pipe_buffer_handle *buffer; + struct pipe_buffer *buffer; unsigned offset; unsigned max_index; @@ -272,7 +272,7 @@ boolean brw_upload_vertex_elements( struct brw_context *brw ) } boolean brw_upload_indices( struct brw_context *brw, - const struct pipe_buffer_handle *index_buffer, + const struct pipe_buffer *index_buffer, int ib_size, int start, int count) { /* Emit the indexbuffer packet: diff --git a/src/mesa/pipe/i965simple/brw_state.h b/src/mesa/pipe/i965simple/brw_state.h index 8b4d7aabf0..258e9a556e 100644 --- a/src/mesa/pipe/i965simple/brw_state.h +++ b/src/mesa/pipe/i965simple/brw_state.h @@ -106,7 +106,7 @@ boolean brw_search_cache( struct brw_cache *cache, void brw_init_caches( struct brw_context *brw ); void brw_destroy_caches( struct brw_context *brw ); -static inline struct pipe_buffer_handle *brw_cache_buffer(struct brw_context *brw, +static inline struct pipe_buffer *brw_cache_buffer(struct brw_context *brw, enum brw_cache_id id) { return brw->cache[id].pool->buffer; diff --git a/src/mesa/pipe/i965simple/brw_state_pool.c b/src/mesa/pipe/i965simple/brw_state_pool.c index 2f930be837..7c67f0ee25 100644 --- a/src/mesa/pipe/i965simple/brw_state_pool.c +++ b/src/mesa/pipe/i965simple/brw_state_pool.c @@ -44,6 +44,7 @@ #include "pipe/p_winsys.h" #include "pipe/p_util.h" +#include "pipe/p_inlines.h" #include "brw_context.h" #include "brw_state.h" @@ -101,9 +102,9 @@ static void brw_destroy_pool( struct brw_context *brw, { struct brw_mem_pool *pool = &brw->pool[pool_id]; - pool->brw->pipe.winsys->buffer_reference( pool->brw->pipe.winsys, - &pool->buffer, - NULL ); + pipe_buffer_reference( pool->brw->pipe.winsys, + &pool->buffer, + NULL ); } diff --git a/src/mesa/pipe/i965simple/brw_surface.c b/src/mesa/pipe/i965simple/brw_surface.c index 76b8c73d5c..252aec7d29 100644 --- a/src/mesa/pipe/i965simple/brw_surface.c +++ b/src/mesa/pipe/i965simple/brw_surface.c @@ -64,7 +64,7 @@ brw_get_tex_surface(struct pipe_context *pipe, if (ps) { assert(ps->format); assert(ps->refcount); - pipe->winsys->buffer_reference(pipe->winsys, &ps->buffer, tex->buffer); + pipe_buffer_reference(pipe->winsys, &ps->buffer, tex->buffer); ps->format = pt->format; ps->cpp = pt->cpp; ps->width = pt->width[level]; diff --git a/src/mesa/pipe/i965simple/brw_tex_layout.c b/src/mesa/pipe/i965simple/brw_tex_layout.c index eadacbf09e..b8b6b579e2 100644 --- a/src/mesa/pipe/i965simple/brw_tex_layout.c +++ b/src/mesa/pipe/i965simple/brw_tex_layout.c @@ -39,6 +39,7 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_util.h" +#include "pipe/p_inlines.h" #include "pipe/p_winsys.h" #include "brw_context.h" @@ -341,7 +342,7 @@ brw_texture_release(struct pipe_context *pipe, struct pipe_texture **pt) DBG("%s deleting %p\n", __FUNCTION__, (void *) tex); */ - pipe->winsys->buffer_reference(pipe->winsys, &tex->buffer, NULL); + pipe_buffer_reference(pipe->winsys, &tex->buffer, NULL); for (i = 0; i < PIPE_MAX_TEXTURE_LEVELS; i++) if (tex->image_offset[i]) diff --git a/src/mesa/pipe/i965simple/brw_winsys.h b/src/mesa/pipe/i965simple/brw_winsys.h index b60f63aa5b..3523a58614 100644 --- a/src/mesa/pipe/i965simple/brw_winsys.h +++ b/src/mesa/pipe/i965simple/brw_winsys.h @@ -50,7 +50,7 @@ * etc. */ -struct pipe_buffer_handle; +struct pipe_buffer; struct pipe_fence_handle; struct pipe_winsys; @@ -136,7 +136,7 @@ struct brw_winsys { * I915_BUFFER_ACCESS_READ macros. */ void (*batch_reloc)(struct brw_winsys *sws, - struct pipe_buffer_handle *buf, + struct pipe_buffer *buf, unsigned access_flags, unsigned delta); @@ -159,7 +159,7 @@ struct brw_winsys { * simulator: */ void (*buffer_subdata_typed)(struct brw_winsys *sws, - struct pipe_buffer_handle *buf, + struct pipe_buffer *buf, unsigned long offset, unsigned long size, const void *data, @@ -170,7 +170,7 @@ struct brw_winsys { * of places yet: */ unsigned (*get_buffer_offset)( struct brw_winsys *sws, - struct pipe_buffer_handle *buf, + struct pipe_buffer *buf, unsigned flags ); }; diff --git a/src/mesa/pipe/i965simple/brw_wm_surface_state.c b/src/mesa/pipe/i965simple/brw_wm_surface_state.c index fc40e0438c..cbb4f2efd3 100644 --- a/src/mesa/pipe/i965simple/brw_wm_surface_state.c +++ b/src/mesa/pipe/i965simple/brw_wm_surface_state.c @@ -127,7 +127,7 @@ static unsigned translate_tex_format( enum pipe_format pipe_format ) } static unsigned brw_buffer_offset(struct brw_context *brw, - struct pipe_buffer_handle *buffer) + struct pipe_buffer *buffer) { return brw->winsys->get_buffer_offset(brw->winsys, buffer, diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index 7a18d48865..37464c88a1 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -74,7 +74,7 @@ struct pipe_context { unsigned mode, unsigned start, unsigned count); boolean (*draw_elements)( struct pipe_context *pipe, - struct pipe_buffer_handle *indexBuffer, + struct pipe_buffer *indexBuffer, unsigned indexSize, unsigned mode, unsigned start, unsigned count); diff --git a/src/mesa/pipe/p_inlines.h b/src/mesa/pipe/p_inlines.h index 8ee0820f92..ebf6ed86bc 100644 --- a/src/mesa/pipe/p_inlines.h +++ b/src/mesa/pipe/p_inlines.h @@ -56,20 +56,38 @@ pipe_surface_unmap(struct pipe_surface *surface) static INLINE void pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf) { - assert(ptr); - if (*ptr) { + /* bump the refcount first */ + if (surf) + surf->refcount++; + + if (*ptr /* && --(*ptr)->refcount == 0 */) { struct pipe_winsys *winsys = (*ptr)->winsys; winsys->surface_release(winsys, ptr); assert(!*ptr); } - if (surf) { - /* reference the new thing */ - surf->refcount++; - *ptr = surf; - } + + *ptr = surf; +} + + +/* XXX: thread safety issues! + */ +static INLINE void +pipe_buffer_reference(struct pipe_winsys *winsys, + struct pipe_buffer **ptr, + struct pipe_buffer *buf) +{ + if (buf) + buf->refcount++; + + if (*ptr && --(*ptr)->refcount == 0) + winsys->buffer_destroy( winsys, *ptr ); + + *ptr = buf; } + /** * \sa pipe_surface_reference */ @@ -78,15 +96,16 @@ pipe_texture_reference(struct pipe_context *pipe, struct pipe_texture **ptr, struct pipe_texture *pt) { assert(ptr); + + if (pt) + pt->refcount++; + if (*ptr) { pipe->texture_release(pipe, ptr); assert(!*ptr); } - if (pt) { - /* reference the new thing */ - pt->refcount++; - *ptr = pt; - } + + *ptr = pt; } diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index 146a479cf3..83ca43f678 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -60,8 +60,21 @@ struct pipe_surface; struct pipe_winsys; -/* opaque type */ -struct pipe_buffer_handle; + + +/** + * The driver will certainly subclass this to include actual memory + * management information. + */ +struct pipe_buffer { + unsigned alignment; + unsigned usage; + unsigned size; + + /** Reference count */ + unsigned refcount; +}; + @@ -129,7 +142,7 @@ struct pipe_clip_state { * Constants for vertex/fragment shaders */ struct pipe_constant_buffer { - struct pipe_buffer_handle *buffer; + struct pipe_buffer *buffer; unsigned size; /** in bytes */ }; @@ -240,7 +253,7 @@ struct pipe_sampler_state */ struct pipe_surface { - struct pipe_buffer_handle *buffer; /**< driver private buffer handle */ + struct pipe_buffer *buffer; /**< driver private buffer handle */ enum pipe_format format; /**< PIPE_FORMAT_x */ unsigned status; /**< PIPE_SURFACE_STATUS_x */ unsigned clear_value; /**< may be temporary */ @@ -290,7 +303,7 @@ struct pipe_vertex_buffer unsigned pitch:11; /**< stride to same attrib in next vertex, in bytes */ unsigned max_index; /**< number of vertices in this buffer */ unsigned buffer_offset; /**< offset to start of data in buffer, in bytes */ - struct pipe_buffer_handle *buffer; /**< the actual buffer */ + struct pipe_buffer *buffer; /**< the actual buffer */ }; diff --git a/src/mesa/pipe/p_winsys.h b/src/mesa/pipe/p_winsys.h index 9742f59a4d..95e3684008 100644 --- a/src/mesa/pipe/p_winsys.h +++ b/src/mesa/pipe/p_winsys.h @@ -39,9 +39,6 @@ */ -/** Opaque type for a buffer */ -struct pipe_buffer_handle; - /** Opaque type */ struct pipe_fence_handle; @@ -103,13 +100,13 @@ struct pipe_winsys * usage argument is only an optimization hint, not a guarantee, therefore * proper behavior must be observed in all circumstances. */ - struct pipe_buffer_handle *(*buffer_create)( struct pipe_winsys *sws, + struct pipe_buffer *(*buffer_create)( struct pipe_winsys *sws, unsigned alignment, unsigned usage, unsigned size ); /** Create a buffer that wraps user-space data */ - struct pipe_buffer_handle *(*user_buffer_create)(struct pipe_winsys *sws, + struct pipe_buffer *(*user_buffer_create)(struct pipe_winsys *sws, void *ptr, unsigned bytes); @@ -118,16 +115,14 @@ struct pipe_winsys * flags is bitmask of PIPE_BUFFER_FLAG_READ/WRITE. */ void *(*buffer_map)( struct pipe_winsys *sws, - struct pipe_buffer_handle *buf, + struct pipe_buffer *buf, unsigned usage ); void (*buffer_unmap)( struct pipe_winsys *sws, - struct pipe_buffer_handle *buf ); + struct pipe_buffer *buf ); - /** Set ptr = buf, with reference counting */ - void (*buffer_reference)( struct pipe_winsys *sws, - struct pipe_buffer_handle **ptr, - struct pipe_buffer_handle *buf ); + void (*buffer_destroy)( struct pipe_winsys *sws, + struct pipe_buffer *buf ); /** Set ptr = fence, with reference counting */ diff --git a/src/mesa/pipe/pipebuffer/Makefile b/src/mesa/pipe/pipebuffer/Makefile index 061d8a060f..0d23e8b8f1 100644 --- a/src/mesa/pipe/pipebuffer/Makefile +++ b/src/mesa/pipe/pipebuffer/Makefile @@ -8,10 +8,8 @@ LIBNAME = pipebuffer DRIVER_SOURCES = \ pb_buffer.c \ pb_buffer_client.c \ - pb_buffer_handle.c \ pb_buffer_fenced.c \ pb_buffer_malloc.c \ - pb_buffer_null.c \ pb_bufmgr_fenced.c \ pb_bufmgr_mm.c \ pb_bufmgr_pool.c diff --git a/src/mesa/pipe/pipebuffer/pb_buffer.c b/src/mesa/pipe/pipebuffer/pb_buffer.c index 99c960b697..90ab9044ff 100644 --- a/src/mesa/pipe/pipebuffer/pb_buffer.c +++ b/src/mesa/pipe/pipebuffer/pb_buffer.c @@ -34,19 +34,44 @@ #include "pb_buffer.h" +#include "pipe/p_winsys.h" -void -buffer_reference(struct pipe_buffer **dst, - struct pipe_buffer *src) + +static void * +pb_winsys_map(struct pipe_winsys *winsys, + struct pipe_buffer *ws_buf, + unsigned flags) +{ + struct pb_buffer *buf = pb_buffer(ws_buf); + + return buf->vtbl->map(buf, flags); +} + +static void +pb_winsys_unmap(struct pipe_winsys *winsys, + struct pipe_buffer *ws_buf) +{ + struct pb_buffer *buf = pb_buffer(ws_buf); + + buf->vtbl->unmap(buf); +} + +static void +pb_winsys_destroy(struct pipe_winsys *winsys, + struct pipe_buffer *ws_buf) +{ + struct pb_buffer *buf = pb_buffer(ws_buf); + + buf->vtbl->destroy(buf); +} + + + +void +pb_init_winsys(struct pipe_winsys *winsys) { - if(*dst != src) { - if (src) - src->vtbl->reference(src); - - if (*dst) - (*dst)->vtbl->release(*dst); - - *dst = src; - } + winsys->buffer_map = pb_winsys_map; + winsys->buffer_unmap = pb_winsys_unmap; + winsys->buffer_destroy = pb_winsys_destroy; } diff --git a/src/mesa/pipe/pipebuffer/pb_buffer.h b/src/mesa/pipe/pipebuffer/pb_buffer.h index 0523531395..f909bded0d 100644 --- a/src/mesa/pipe/pipebuffer/pb_buffer.h +++ b/src/mesa/pipe/pipebuffer/pb_buffer.h @@ -47,53 +47,43 @@ #include #include +#include "pipe/p_state.h" -struct pipe_buffer_vtbl; - +struct pb_vtbl; /** - * Base class for all pipe buffers. + * Base class for all pb_* buffers. */ -struct pipe_buffer +struct pb_buffer { + struct pipe_buffer base; + /** * Pointer to the virtual function table. * * Avoid accessing this table directly. Use the inline functions below * instead to avoid mistakes. */ - const struct pipe_buffer_vtbl *vtbl; + const struct pb_vtbl *vtbl; }; - /** * Virtual function table for the buffer storage operations. * * Note that creation is not done through this table. */ -struct pipe_buffer_vtbl +struct pb_vtbl { - /** - * Add a reference to the buffer. - * - * This method can be a no-op for buffers that don't need reference - * counting. - */ - void (*reference)( struct pipe_buffer *buf ); - - /** - * Release a reference to this buffer and destroy it. - */ - void (*release)( struct pipe_buffer *buf ); + void (*destroy)( struct pb_buffer *buf ); /** * Map the entire data store of a buffer object into the client's address. * flags is bitmask of PIPE_BUFFER_FLAG_READ/WRITE. */ - void *(*map)( struct pipe_buffer *buf, + void *(*map)( struct pb_buffer *buf, unsigned flags ); - void (*unmap)( struct pipe_buffer *buf ); + void (*unmap)( struct pb_buffer *buf ); /** * Get the base buffer and the offset. @@ -106,29 +96,17 @@ struct pipe_buffer_vtbl * * Note that this will increase the reference count of the base buffer. */ - void (*get_base_buffer)( struct pipe_buffer *buf, - struct pipe_buffer **base_buf, + void (*get_base_buffer)( struct pb_buffer *buf, + struct pb_buffer **base_buf, unsigned *offset ); }; -/** *dst = src with reference counting */ -void -buffer_reference(struct pipe_buffer **dst, - struct pipe_buffer *src); - - -static inline void -buffer_release(struct pipe_buffer *buf) -{ - assert(buf); - buf->vtbl->release(buf); -} - - +/* Accessor functions for pb->vtbl: + */ static inline void * -buffer_map(struct pipe_buffer *buf, - unsigned flags) +pb_map(struct pb_buffer *buf, + unsigned flags) { assert(buf); return buf->vtbl->map(buf, flags); @@ -136,7 +114,7 @@ buffer_map(struct pipe_buffer *buf, static inline void -buffer_unmap(struct pipe_buffer *buf) +pb_unmap(struct pb_buffer *buf) { assert(buf); buf->vtbl->unmap(buf); @@ -144,32 +122,63 @@ buffer_unmap(struct pipe_buffer *buf) static inline void -buffer_get_base_buffer( struct pipe_buffer *buf, - struct pipe_buffer **base_buf, - unsigned *offset ) +pb_get_base_buffer( struct pb_buffer *buf, + struct pb_buffer **base_buf, + unsigned *offset ) { buf->vtbl->get_base_buffer(buf, base_buf, offset); } +static inline void +pb_destroy(struct pb_buffer *buf) +{ + assert(buf); + buf->vtbl->destroy(buf); +} + -/** Placeholder for empty buffers. */ -extern struct pipe_buffer null_buffer; /** - * Client buffers (also designated as user buffers) are just for convenience - * of the state tracker, so that it can masquerade its own data as a buffer. + * User buffers are special buffers that initially reference memory + * held by the user but which may if necessary copy that memory into + * device memory behind the scenes, for submission to hardware. + * + * These are particularly useful when the referenced data is never + * submitted to hardware at all, in the particular case of software + * vertex processing. */ -struct pipe_buffer * -client_buffer_create(void *data); +struct pb_buffer * +pb_user_buffer_create(void *data, unsigned bytes); /** * Malloc-based buffer to store data that can't be used by the graphics * hardware. */ -struct pipe_buffer * -malloc_buffer_create(unsigned size); +struct pb_buffer * +pb_malloc_buffer_create( unsigned alignment, + unsigned usage, + unsigned size ); + + + +static inline struct pipe_buffer * +pb_pipe_buffer( struct pb_buffer *pbuf ) +{ + return &pbuf->base; +} + +static inline struct pb_buffer * +pb_buffer( struct pipe_buffer *buf ) +{ + /* Could add a magic cookie check on debug builds. + */ + return (struct pb_buffer *)buf; +} + +void +pb_init_winsys(struct pipe_winsys *winsys); #endif /*PB_BUFFER_H_*/ diff --git a/src/mesa/pipe/pipebuffer/pb_buffer_client.c b/src/mesa/pipe/pipebuffer/pb_buffer_client.c index bb7f5a9a94..6bf4745301 100644 --- a/src/mesa/pipe/pipebuffer/pb_buffer_client.c +++ b/src/mesa/pipe/pipebuffer/pb_buffer_client.c @@ -35,36 +35,30 @@ #include "pb_buffer.h" +#include "pipe/p_util.h" -struct client_buffer +struct pb_user_buffer { - struct pipe_buffer base; + struct pb_buffer base; void *data; }; -extern const struct pipe_buffer_vtbl client_buffer_vtbl; +extern const struct pb_vtbl pb_user_buffer_vtbl; -static inline struct client_buffer * -client_buffer(struct pipe_buffer *buf) +static INLINE struct pb_user_buffer * +pb_user_buffer(struct pb_buffer *buf) { assert(buf); - assert(buf->vtbl == &client_buffer_vtbl); - return (struct client_buffer *)buf; + assert(buf->vtbl == &pb_user_buffer_vtbl); + return (struct pb_user_buffer *)buf; } static void -client_buffer_reference(struct pipe_buffer *buf) -{ - /* No-op */ -} - - -static void -client_buffer_release(struct pipe_buffer *buf) +pb_user_buffer_destroy(struct pb_buffer *buf) { assert(buf); free(buf); @@ -72,23 +66,23 @@ client_buffer_release(struct pipe_buffer *buf) static void * -client_buffer_map(struct pipe_buffer *buf, +pb_user_buffer_map(struct pb_buffer *buf, unsigned flags) { - return client_buffer(buf)->data; + return pb_user_buffer(buf)->data; } static void -client_buffer_unmap(struct pipe_buffer *buf) +pb_user_buffer_unmap(struct pb_buffer *buf) { /* No-op */ } static void -client_buffer_get_base_buffer(struct pipe_buffer *buf, - struct pipe_buffer **base_buf, +pb_user_buffer_get_base_buffer(struct pb_buffer *buf, + struct pb_buffer **base_buf, unsigned *offset) { *base_buf = buf; @@ -96,27 +90,25 @@ client_buffer_get_base_buffer(struct pipe_buffer *buf, } -const struct pipe_buffer_vtbl -client_buffer_vtbl = { - client_buffer_reference, - client_buffer_release, - client_buffer_map, - client_buffer_unmap, - client_buffer_get_base_buffer +const struct pb_vtbl +pb_user_buffer_vtbl = { + pb_user_buffer_destroy, + pb_user_buffer_map, + pb_user_buffer_unmap, + pb_user_buffer_get_base_buffer }; -struct pipe_buffer * -client_buffer_create(void *data) +struct pb_buffer * +pb_user_buffer_create(void *data, unsigned bytes) { - struct client_buffer *buf; - - buf = (struct client_buffer *)malloc(sizeof(struct client_buffer)); + struct pb_user_buffer *buf = CALLOC_STRUCT(pb_user_buffer); + if(!buf) return NULL; - buf->base.vtbl = &client_buffer_vtbl; - + buf->base.vtbl = &pb_user_buffer_vtbl; + buf->base.base.size = bytes; buf->data = data; return &buf->base; diff --git a/src/mesa/pipe/pipebuffer/pb_buffer_fenced.c b/src/mesa/pipe/pipebuffer/pb_buffer_fenced.c index dfb80b1dcf..625120d714 100644 --- a/src/mesa/pipe/pipebuffer/pb_buffer_fenced.c +++ b/src/mesa/pipe/pipebuffer/pb_buffer_fenced.c @@ -72,9 +72,9 @@ struct fenced_buffer_list */ struct fenced_buffer { - struct pipe_buffer base; + struct pb_buffer base; - struct pipe_buffer *buffer; + struct pb_buffer *buffer; unsigned refcount; struct pipe_fence_handle *fence; @@ -84,8 +84,8 @@ struct fenced_buffer }; -static inline struct fenced_buffer * -fenced_buffer(struct pipe_buffer *buf) +static INLINE struct fenced_buffer * +fenced_buffer(struct pb_buffer *buf) { assert(buf); assert(buf->vtbl == &fenced_buffer_vtbl); @@ -93,12 +93,6 @@ fenced_buffer(struct pipe_buffer *buf) } -static void -_fenced_buffer_destroy(struct fenced_buffer *fenced_buf) -{ - buffer_release(fenced_buf->buffer); - free(fenced_buf); -} static void @@ -143,97 +137,81 @@ _fenced_buffer_list_check_free(struct fenced_buffer_list *fenced_list, LIST_DEL(list); fenced_list->numDelayed--; - - _fenced_buffer_destroy(fenced_buf); - } -} - -static void -fenced_buffer_reference(struct pipe_buffer *buf) -{ - struct fenced_buffer *fenced_buf = fenced_buffer(buf); - struct fenced_buffer_list *fenced_list = fenced_buf->list; - - _glthread_LOCK_MUTEX(fenced_list->mutex); - fenced_buf->refcount++; - _glthread_UNLOCK_MUTEX(fenced_list->mutex); + /* Do the delayed destroy: + */ + pb_destroy(fenced_buf->buffer); + free(fenced_buf); + } } static void -fenced_buffer_release(struct pipe_buffer *buf) +fenced_buffer_destroy(struct pb_buffer *buf) { struct fenced_buffer *fenced_buf = fenced_buffer(buf); struct fenced_buffer_list *fenced_list = fenced_buf->list; - _glthread_LOCK_MUTEX(fenced_list->mutex); - - fenced_buf->refcount--; - if(!fenced_buf->refcount) { - if (fenced_buf->fence) { - LIST_ADDTAIL(&fenced_buf->head, &fenced_list->delayed); - fenced_list->numDelayed++; - } - else { - _fenced_buffer_destroy(fenced_buf); - } - - if ((fenced_list->numDelayed % fenced_list->checkDelayed) == 0) - _fenced_buffer_list_check_free(fenced_list, 0); + if (fenced_buf->fence) { + LIST_ADDTAIL(&fenced_buf->head, &fenced_list->delayed); + fenced_list->numDelayed++; + } + else { + pb_destroy(fenced_buf->buffer); + free(fenced_buf); } - _glthread_UNLOCK_MUTEX(fenced_list->mutex); + if ((fenced_list->numDelayed % fenced_list->checkDelayed) == 0) + _fenced_buffer_list_check_free(fenced_list, 0); } static void * -fenced_buffer_map(struct pipe_buffer *buf, +fenced_buffer_map(struct pb_buffer *buf, unsigned flags) { struct fenced_buffer *fenced_buf = fenced_buffer(buf); - return buffer_map(fenced_buf->buffer, flags); + return pb_map(fenced_buf->buffer, flags); } static void -fenced_buffer_unmap(struct pipe_buffer *buf) +fenced_buffer_unmap(struct pb_buffer *buf) { struct fenced_buffer *fenced_buf = fenced_buffer(buf); - buffer_unmap(fenced_buf->buffer); + pb_unmap(fenced_buf->buffer); } static void -fenced_buffer_get_base_buffer(struct pipe_buffer *buf, - struct pipe_buffer **base_buf, +fenced_buffer_get_base_buffer(struct pb_buffer *buf, + struct pb_buffer **base_buf, unsigned *offset) { struct fenced_buffer *fenced_buf = fenced_buffer(buf); - buffer_get_base_buffer(fenced_buf->buffer, base_buf, offset); + pb_get_base_buffer(fenced_buf->buffer, base_buf, offset); } -const struct pipe_buffer_vtbl +const struct pb_vtbl fenced_buffer_vtbl = { - fenced_buffer_reference, - fenced_buffer_release, + fenced_buffer_destroy, fenced_buffer_map, fenced_buffer_unmap, fenced_buffer_get_base_buffer }; -struct pipe_buffer * +struct pb_buffer * fenced_buffer_create(struct fenced_buffer_list *fenced_list, - struct pipe_buffer *buffer) + struct pb_buffer *buffer) { struct fenced_buffer *buf; if(!buffer) return NULL; - buf = (struct fenced_buffer *)calloc(1, sizeof(struct fenced_buffer)); + buf = CALLOC_STRUCT(fenced_buffer); if(!buf) return NULL; @@ -247,20 +225,16 @@ fenced_buffer_create(struct fenced_buffer_list *fenced_list, void -buffer_fence(struct pipe_buffer *buf, +buffer_fence(struct pb_buffer *buf, struct pipe_fence_handle *fence) { - if(buf->vtbl == &fenced_buffer_vtbl) { - struct fenced_buffer *fenced_buf = fenced_buffer(buf); - struct fenced_buffer_list *fenced_list = fenced_buf->list; - struct pipe_winsys *winsys = fenced_list->winsys; + struct fenced_buffer *fenced_buf = fenced_buffer(buf); + struct fenced_buffer_list *fenced_list = fenced_buf->list; + struct pipe_winsys *winsys = fenced_list->winsys; - _glthread_LOCK_MUTEX(fenced_list->mutex); - winsys->fence_reference(winsys, &fenced_buf->fence, fence); - _glthread_UNLOCK_MUTEX(fenced_list->mutex); - } - else - assert(0); + _glthread_LOCK_MUTEX(fenced_list->mutex); + winsys->fence_reference(winsys, &fenced_buf->fence, fence); + _glthread_UNLOCK_MUTEX(fenced_list->mutex); } diff --git a/src/mesa/pipe/pipebuffer/pb_buffer_fenced.h b/src/mesa/pipe/pipebuffer/pb_buffer_fenced.h index 07e42a67f8..09082a5390 100644 --- a/src/mesa/pipe/pipebuffer/pb_buffer_fenced.h +++ b/src/mesa/pipe/pipebuffer/pb_buffer_fenced.h @@ -70,7 +70,7 @@ struct fenced_buffer_list; * * NOTE: Made public for debugging purposes. */ -extern const struct pipe_buffer_vtbl fenced_buffer_vtbl; +extern const struct pb_vtbl fenced_buffer_vtbl; /** @@ -98,19 +98,19 @@ fenced_buffer_list_destroy(struct fenced_buffer_list *fenced_list); * * NOTE: this will not increase the buffer reference count. */ -struct pipe_buffer * +struct pb_buffer * fenced_buffer_create(struct fenced_buffer_list *fenced, - struct pipe_buffer *buffer); + struct pb_buffer *buffer); /** * Set a buffer's fence. * - * NOTE: Although it takes a generic pipe buffer argument, it will fail + * NOTE: Although it takes a generic pb_buffer argument, it will fail * on everything but buffers returned by fenced_buffer_create. */ void -buffer_fence(struct pipe_buffer *buf, +buffer_fence(struct pb_buffer *buf, struct pipe_fence_handle *fence); diff --git a/src/mesa/pipe/pipebuffer/pb_buffer_handle.c b/src/mesa/pipe/pipebuffer/pb_buffer_handle.c deleted file mode 100644 index 9aeff976f3..0000000000 --- a/src/mesa/pipe/pipebuffer/pb_buffer_handle.c +++ /dev/null @@ -1,140 +0,0 @@ -/************************************************************************** - * - * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -/** - * \file - * Drop-in implementation of the winsys driver functions for buffer handles. - * - * \author José Fonseca - */ - - -#include -#include - -#include "pipe/p_winsys.h" -#include "pipe/p_defines.h" - -#include "pb_buffer.h" -#include "pb_buffer_handle.h" - - -static struct pipe_buffer_handle * -buffer_handle_create(struct pipe_winsys *winsys, - unsigned alignment, - unsigned usage, - unsigned size) -{ - struct pipe_buffer_handle *handle; - - handle = (struct pipe_buffer_handle *)malloc(sizeof(struct pipe_buffer_handle)); - if(!handle) - return NULL; - - handle->refcount = 1; - handle->alignment = alignment; - handle->usage = usage; - handle->size = size; - - handle->buf = &null_buffer; - - return handle; -} - - -static struct pipe_buffer_handle * -buffer_handle_create_user(struct pipe_winsys *winsys, - void *data, unsigned size) -{ - struct pipe_buffer_handle *handle; - struct pipe_buffer *buf; - - handle = buffer_handle_create(winsys, 1, 0, size); - if(!handle) - return NULL; - - buf = client_buffer_create(data); - if(!buf) { - free(handle); - return NULL; - } - - buffer_handle_data(handle, buf); - - return handle; -} - - -static void * -buffer_handle_map(struct pipe_winsys *winsys, - struct pipe_buffer_handle *handle, - unsigned flags) -{ - return buffer_map(handle->buf, flags); -} - - -static void -buffer_handle_unmap(struct pipe_winsys *winsys, - struct pipe_buffer_handle *handle) -{ - buffer_unmap(handle->buf); -} - - -static void -buffer_handle_reference(struct pipe_winsys *winsys, - struct pipe_buffer_handle **dst, - struct pipe_buffer_handle *src) -{ - /* XXX: should this be thread safe? */ - - if (src) { - src->refcount++; - } - - if (*dst) { - (*dst)->refcount--; - if ((*dst)->refcount == 0) { - buffer_release((*dst)->buf); - free(*dst); - } - } - - *dst = src; -} - - -void -buffer_handle_init_winsys(struct pipe_winsys *winsys) -{ - winsys->buffer_create = buffer_handle_create; - winsys->user_buffer_create = buffer_handle_create_user; - winsys->buffer_map = buffer_handle_map; - winsys->buffer_unmap = buffer_handle_unmap; - winsys->buffer_reference = buffer_handle_reference; -} diff --git a/src/mesa/pipe/pipebuffer/pb_buffer_handle.h b/src/mesa/pipe/pipebuffer/pb_buffer_handle.h deleted file mode 100644 index 34133c9fba..0000000000 --- a/src/mesa/pipe/pipebuffer/pb_buffer_handle.h +++ /dev/null @@ -1,120 +0,0 @@ -/************************************************************************** - * - * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -/** - * \file - * Buffer handle interface. - * - * \author José Fonseca - */ - -#ifndef PB_BUFFER_HANDLE_H_ -#define PB_BUFFER_HANDLE_H_ - - -#include - -#include "pb_buffer.h" - - -/** - * Buffer handle. - * - * The buffer handle and the buffer data storage are separate entities. This - * is modelled after ARB_vertex_buffer_object, which is the interface that - * Gallium requires. See p_winsys.h for more information. - */ -struct pipe_buffer_handle -{ - /** Reference count */ - unsigned refcount; - - /** Allocation characteristics */ - unsigned alignment; - unsigned usage; - unsigned size; - - /** - * The actual buffer. - * - * It should never be NULL. Use null_buffer instead. - */ - struct pipe_buffer *buf; -}; - - -/** - * Set buffer storage. - * - * NOTE: this will not increase the buffer reference count. - */ -static inline void -buffer_handle_data(struct pipe_buffer_handle *handle, - struct pipe_buffer *buf) -{ - assert(handle); - assert(handle->buf); - buffer_release(handle->buf); - assert(buf); - handle->buf = buf; -} - - -static inline void -buffer_handle_clear(struct pipe_buffer_handle *handle) -{ - buffer_handle_data(handle, &null_buffer); -} - - -static inline int -buffer_handle_has_data(struct pipe_buffer_handle *handle) { - assert(handle); - assert(handle->buf); - return handle->buf != &null_buffer; -} - - -/** - * Fill in the pipe_winsys' buffer-related callbacks. - * - * Specifically, the fullfilled functions are: - * - buffer_create - * - user_buffer_create - * - buffer_map - * - buffer_unmap - * - buffer_reference - * - buffer_subdata - * - buffer_get_subdata - * - * NOTE: buffer_data is left untouched. - */ -void -buffer_handle_init_winsys(struct pipe_winsys *winsys); - - -#endif /*PB_BUFFER_HANDLE_H_*/ diff --git a/src/mesa/pipe/pipebuffer/pb_buffer_malloc.c b/src/mesa/pipe/pipebuffer/pb_buffer_malloc.c index 65ad51e1e7..e02eb1eebd 100644 --- a/src/mesa/pipe/pipebuffer/pb_buffer_malloc.c +++ b/src/mesa/pipe/pipebuffer/pb_buffer_malloc.c @@ -42,15 +42,15 @@ struct malloc_buffer { - struct pipe_buffer base; + struct pb_buffer base; void *data; }; -extern const struct pipe_buffer_vtbl malloc_buffer_vtbl; +extern const struct pb_vtbl malloc_buffer_vtbl; -static inline struct malloc_buffer * -malloc_buffer(struct pipe_buffer *buf) +static INLINE struct malloc_buffer * +malloc_buffer(struct pb_buffer *buf) { assert(buf); assert(buf->vtbl == &malloc_buffer_vtbl); @@ -59,14 +59,7 @@ malloc_buffer(struct pipe_buffer *buf) static void -malloc_buffer_reference(struct pipe_buffer *buf) -{ - /* no-op */ -} - - -static void -malloc_buffer_release(struct pipe_buffer *buf) +malloc_buffer_destroy(struct pb_buffer *buf) { free(malloc_buffer(buf)->data); free(buf); @@ -74,7 +67,7 @@ malloc_buffer_release(struct pipe_buffer *buf) static void * -malloc_buffer_map(struct pipe_buffer *buf, +malloc_buffer_map(struct pb_buffer *buf, unsigned flags) { return malloc_buffer(buf)->data; @@ -82,15 +75,15 @@ malloc_buffer_map(struct pipe_buffer *buf, static void -malloc_buffer_unmap(struct pipe_buffer *buf) +malloc_buffer_unmap(struct pb_buffer *buf) { /* No-op */ } static void -malloc_buffer_get_base_buffer(struct pipe_buffer *buf, - struct pipe_buffer **base_buf, +malloc_buffer_get_base_buffer(struct pb_buffer *buf, + struct pb_buffer **base_buf, unsigned *offset) { *base_buf = buf; @@ -98,18 +91,19 @@ malloc_buffer_get_base_buffer(struct pipe_buffer *buf, } -const struct pipe_buffer_vtbl +const struct pb_vtbl malloc_buffer_vtbl = { - malloc_buffer_reference, - malloc_buffer_release, + malloc_buffer_destroy, malloc_buffer_map, malloc_buffer_unmap, malloc_buffer_get_base_buffer }; -struct pipe_buffer * -malloc_buffer_create(unsigned size) +struct pb_buffer * +pb_malloc_buffer_create( unsigned alignment, + unsigned usage, + unsigned size ) { struct malloc_buffer *buf; @@ -121,7 +115,10 @@ malloc_buffer_create(unsigned size) return NULL; buf->base.vtbl = &malloc_buffer_vtbl; - + buf->base.base.alignment = alignment; + buf->base.base.usage = usage; + buf->base.base.size = size; + buf->data = malloc(size); if(!buf->data) { free(buf); diff --git a/src/mesa/pipe/pipebuffer/pb_buffer_null.c b/src/mesa/pipe/pipebuffer/pb_buffer_null.c deleted file mode 100644 index a356c6b2d5..0000000000 --- a/src/mesa/pipe/pipebuffer/pb_buffer_null.c +++ /dev/null @@ -1,98 +0,0 @@ -/************************************************************************** - * - * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -/** - * \file - * Null buffer implementation. - * - * We have a special null buffer object so that we can safely call buffer - * operations without having to check whether the buffer pointer is null or not. - * - * \author José Fonseca - */ - - -#include "pipe/p_winsys.h" -#include "pipe/p_defines.h" - -#include "pb_buffer.h" - - -static void -null_buffer_reference(struct pipe_buffer *buf) -{ - /* No-op */ -} - - -static void -null_buffer_release(struct pipe_buffer *buf) -{ - /* No-op */ -} - - -static void * -null_buffer_map(struct pipe_buffer *buf, - unsigned flags) -{ - assert(0); - return NULL; -} - - -static void -null_buffer_unmap(struct pipe_buffer *buf) -{ - assert(0); -} - - -static void -null_buffer_get_base_buffer(struct pipe_buffer *buf, - struct pipe_buffer **base_buf, - unsigned *offset) -{ - *base_buf = buf; - *offset = 0; -} - - -const struct pipe_buffer_vtbl -pipe_buffer_vtbl = { - null_buffer_reference, - null_buffer_release, - null_buffer_map, - null_buffer_unmap, - null_buffer_get_base_buffer -}; - - -struct pipe_buffer -null_buffer = { - &pipe_buffer_vtbl -}; diff --git a/src/mesa/pipe/pipebuffer/pb_bufmgr.h b/src/mesa/pipe/pipebuffer/pb_bufmgr.h index 12e36323a8..13d4ea7545 100644 --- a/src/mesa/pipe/pipebuffer/pb_bufmgr.h +++ b/src/mesa/pipe/pipebuffer/pb_bufmgr.h @@ -60,15 +60,15 @@ struct pipe_winsys; /** * Abstract base class for all buffer managers. */ -struct buffer_manager +struct pb_manager { /* XXX: we will likely need more allocation flags */ - struct pipe_buffer * - (*create_buffer)( struct buffer_manager *mgr, + struct pb_buffer * + (*create_buffer)( struct pb_manager *mgr, size_t size ); void - (*destroy)( struct buffer_manager *mgr ); + (*destroy)( struct pb_manager *mgr ); }; @@ -80,8 +80,8 @@ struct buffer_manager * * It is meant to manage the allocation of batch buffer pools. */ -struct buffer_manager * -pool_bufmgr_create(struct buffer_manager *provider, +struct pb_manager * +pool_bufmgr_create(struct pb_manager *provider, size_t n, size_t size); @@ -92,8 +92,8 @@ pool_bufmgr_create(struct buffer_manager *provider, * with the size of the heap, and then using the old mm memory manager to manage * that heap. */ -struct buffer_manager * -mm_bufmgr_create(struct buffer_manager *provider, +struct pb_manager * +mm_bufmgr_create(struct pb_manager *provider, size_t size, size_t align2); /** @@ -101,8 +101,8 @@ mm_bufmgr_create(struct buffer_manager *provider, * * Buffer will be release when the manager is destroyed. */ -struct buffer_manager * -mm_bufmgr_create_from_buffer(struct pipe_buffer *buffer, +struct pb_manager * +mm_bufmgr_create_from_buffer(struct pb_buffer *buffer, size_t size, size_t align2); @@ -115,8 +115,8 @@ mm_bufmgr_create_from_buffer(struct pipe_buffer *buffer, * NOTE: the buffer manager that provides the buffers will be destroyed * at the same time. */ -struct buffer_manager * -fenced_bufmgr_create(struct buffer_manager *provider, +struct pb_manager * +fenced_bufmgr_create(struct pb_manager *provider, struct pipe_winsys *winsys); diff --git a/src/mesa/pipe/pipebuffer/pb_bufmgr_fenced.c b/src/mesa/pipe/pipebuffer/pb_bufmgr_fenced.c index defd8e4df7..8cdbbed272 100644 --- a/src/mesa/pipe/pipebuffer/pb_bufmgr_fenced.c +++ b/src/mesa/pipe/pipebuffer/pb_bufmgr_fenced.c @@ -42,30 +42,30 @@ #include "pb_bufmgr.h" -struct fenced_buffer_manager +struct fenced_pb_manager { - struct buffer_manager base; + struct pb_manager base; - struct buffer_manager *provider; + struct pb_manager *provider; struct fenced_buffer_list *fenced_list; }; -static inline struct fenced_buffer_manager * -fenced_buffer_manager(struct buffer_manager *mgr) +static inline struct fenced_pb_manager * +fenced_pb_manager(struct pb_manager *mgr) { assert(mgr); - return (struct fenced_buffer_manager *)mgr; + return (struct fenced_pb_manager *)mgr; } -static struct pipe_buffer * -fenced_bufmgr_create_buffer(struct buffer_manager *mgr, size_t size) +static struct pb_buffer * +fenced_bufmgr_create_buffer(struct pb_manager *mgr, size_t size) { - struct fenced_buffer_manager *fenced_mgr = fenced_buffer_manager(mgr); - struct pipe_buffer *buf; - struct pipe_buffer *fenced_buf; + struct fenced_pb_manager *fenced_mgr = fenced_pb_manager(mgr); + struct pb_buffer *buf; + struct pb_buffer *fenced_buf; /* check for free buffers before allocating new ones */ fenced_buffer_list_check_free(fenced_mgr->fenced_list, 0); @@ -84,7 +84,7 @@ fenced_bufmgr_create_buffer(struct buffer_manager *mgr, size_t size) fenced_buf = fenced_buffer_create(fenced_mgr->fenced_list, buf); if(!fenced_buf) { - buffer_release(buf); + pb_destroy(buf); } return fenced_buf; @@ -92,9 +92,9 @@ fenced_bufmgr_create_buffer(struct buffer_manager *mgr, size_t size) static void -fenced_bufmgr_destroy(struct buffer_manager *mgr) +fenced_bufmgr_destroy(struct pb_manager *mgr) { - struct fenced_buffer_manager *fenced_mgr = fenced_buffer_manager(mgr); + struct fenced_pb_manager *fenced_mgr = fenced_pb_manager(mgr); fenced_buffer_list_destroy(fenced_mgr->fenced_list); @@ -104,13 +104,13 @@ fenced_bufmgr_destroy(struct buffer_manager *mgr) } -struct buffer_manager * -fenced_bufmgr_create(struct buffer_manager *provider, +struct pb_manager * +fenced_bufmgr_create(struct pb_manager *provider, struct pipe_winsys *winsys) { - struct fenced_buffer_manager *fenced_mgr; + struct fenced_pb_manager *fenced_mgr; - fenced_mgr = (struct fenced_buffer_manager *)calloc(1, sizeof(*fenced_mgr)); + fenced_mgr = (struct fenced_pb_manager *)calloc(1, sizeof(*fenced_mgr)); if (!fenced_mgr) return NULL; diff --git a/src/mesa/pipe/pipebuffer/pb_bufmgr_mm.c b/src/mesa/pipe/pipebuffer/pb_bufmgr_mm.c index d174f24e32..f456b571d9 100644 --- a/src/mesa/pipe/pipebuffer/pb_bufmgr_mm.c +++ b/src/mesa/pipe/pipebuffer/pb_bufmgr_mm.c @@ -53,9 +53,9 @@ #define SUPER(__derived) (&(__derived)->base) -struct mm_buffer_manager +struct mm_pb_manager { - struct buffer_manager base; + struct pb_manager base; _glthread_Mutex mutex; @@ -64,31 +64,31 @@ struct mm_buffer_manager size_t align2; - struct pipe_buffer *buffer; + struct pb_buffer *buffer; void *map; }; -static inline struct mm_buffer_manager * -mm_buffer_manager(struct buffer_manager *mgr) +static inline struct mm_pb_manager * +mm_pb_manager(struct pb_manager *mgr) { assert(mgr); - return (struct mm_buffer_manager *)mgr; + return (struct mm_pb_manager *)mgr; } struct mm_buffer { - struct pipe_buffer base; + struct pb_buffer base; - struct mm_buffer_manager *mgr; + struct mm_pb_manager *mgr; struct mem_block *block; }; static inline struct mm_buffer * -mm_buffer(struct pipe_buffer *buf) +mm_buffer(struct pb_buffer *buf) { assert(buf); return (struct mm_buffer *)buf; @@ -96,17 +96,10 @@ mm_buffer(struct pipe_buffer *buf) static void -mm_buffer_reference(struct pipe_buffer *buf) -{ - /* No-op */ -} - - -static void -mm_buffer_release(struct pipe_buffer *buf) +mm_buffer_destroy(struct pb_buffer *buf) { struct mm_buffer *mm_buf = mm_buffer(buf); - struct mm_buffer_manager *mm = mm_buf->mgr; + struct mm_pb_manager *mm = mm_buf->mgr; _glthread_LOCK_MUTEX(mm->mutex); mmFreeMem(mm_buf->block); @@ -116,50 +109,49 @@ mm_buffer_release(struct pipe_buffer *buf) static void * -mm_buffer_map(struct pipe_buffer *buf, +mm_buffer_map(struct pb_buffer *buf, unsigned flags) { struct mm_buffer *mm_buf = mm_buffer(buf); - struct mm_buffer_manager *mm = mm_buf->mgr; + struct mm_pb_manager *mm = mm_buf->mgr; return (unsigned char *) mm->map + mm_buf->block->ofs; } static void -mm_buffer_unmap(struct pipe_buffer *buf) +mm_buffer_unmap(struct pb_buffer *buf) { /* No-op */ } static void -mm_buffer_get_base_buffer(struct pipe_buffer *buf, - struct pipe_buffer **base_buf, +mm_buffer_get_base_buffer(struct pb_buffer *buf, + struct pb_buffer **base_buf, unsigned *offset) { struct mm_buffer *mm_buf = mm_buffer(buf); - struct mm_buffer_manager *mm = mm_buf->mgr; - buffer_get_base_buffer(mm->buffer, base_buf, offset); + struct mm_pb_manager *mm = mm_buf->mgr; + pb_get_base_buffer(mm->buffer, base_buf, offset); *offset += mm_buf->block->ofs; } -static const struct pipe_buffer_vtbl +static const struct pb_vtbl mm_buffer_vtbl = { - mm_buffer_reference, - mm_buffer_release, + mm_buffer_destroy, mm_buffer_map, mm_buffer_unmap, mm_buffer_get_base_buffer }; -static struct pipe_buffer * -mm_bufmgr_create_buffer(struct buffer_manager *mgr, +static struct pb_buffer * +mm_bufmgr_create_buffer(struct pb_manager *mgr, size_t size) { - struct mm_buffer_manager *mm = mm_buffer_manager(mgr); + struct mm_pb_manager *mm = mm_pb_manager(mgr); struct mm_buffer *mm_buf; _glthread_LOCK_MUTEX(mm->mutex); @@ -200,16 +192,16 @@ mm_bufmgr_create_buffer(struct buffer_manager *mgr, static void -mm_bufmgr_destroy(struct buffer_manager *mgr) +mm_bufmgr_destroy(struct pb_manager *mgr) { - struct mm_buffer_manager *mm = mm_buffer_manager(mgr); + struct mm_pb_manager *mm = mm_pb_manager(mgr); _glthread_LOCK_MUTEX(mm->mutex); mmDestroy(mm->heap); - buffer_unmap(mm->buffer); - buffer_release(mm->buffer); + pb_unmap(mm->buffer); + pb_destroy(mm->buffer); _glthread_UNLOCK_MUTEX(mm->mutex); @@ -217,16 +209,16 @@ mm_bufmgr_destroy(struct buffer_manager *mgr) } -struct buffer_manager * -mm_bufmgr_create_from_buffer(struct pipe_buffer *buffer, +struct pb_manager * +mm_bufmgr_create_from_buffer(struct pb_buffer *buffer, size_t size, size_t align2) { - struct mm_buffer_manager *mm; + struct mm_pb_manager *mm; if(!buffer) return NULL; - mm = (struct mm_buffer_manager *)calloc(1, sizeof(*mm)); + mm = (struct mm_pb_manager *)calloc(1, sizeof(*mm)); if (!mm) return NULL; @@ -240,9 +232,9 @@ mm_bufmgr_create_from_buffer(struct pipe_buffer *buffer, mm->buffer = buffer; - mm->map = buffer_map(mm->buffer, - PIPE_BUFFER_USAGE_CPU_READ | - PIPE_BUFFER_USAGE_CPU_WRITE); + mm->map = pb_map(mm->buffer, + PIPE_BUFFER_USAGE_CPU_READ | + PIPE_BUFFER_USAGE_CPU_WRITE); if(!mm->map) goto failure; @@ -256,19 +248,19 @@ failure: if(mm->heap) mmDestroy(mm->heap); if(mm->map) - buffer_unmap(mm->buffer); + pb_unmap(mm->buffer); if(mm) free(mm); return NULL; } -struct buffer_manager * -mm_bufmgr_create(struct buffer_manager *provider, +struct pb_manager * +mm_bufmgr_create(struct pb_manager *provider, size_t size, size_t align2) { - struct pipe_buffer *buffer; - struct buffer_manager *mgr; + struct pb_buffer *buffer; + struct pb_manager *mgr; assert(provider); assert(provider->create_buffer); @@ -278,7 +270,7 @@ mm_bufmgr_create(struct buffer_manager *provider, mgr = mm_bufmgr_create_from_buffer(buffer, size, align2); if (!mgr) { - buffer_release(buffer); + pb_destroy(buffer); return NULL; } diff --git a/src/mesa/pipe/pipebuffer/pb_bufmgr_pool.c b/src/mesa/pipe/pipebuffer/pb_bufmgr_pool.c index e6a8c78668..7e8494f615 100644 --- a/src/mesa/pipe/pipebuffer/pb_bufmgr_pool.c +++ b/src/mesa/pipe/pipebuffer/pb_bufmgr_pool.c @@ -55,9 +55,9 @@ #define SUPER(__derived) (&(__derived)->base) -struct pool_buffer_manager +struct pool_pb_manager { - struct buffer_manager base; + struct pb_manager base; _glthread_Mutex mutex; @@ -68,26 +68,26 @@ struct pool_buffer_manager struct list_head free; - struct pipe_buffer *buffer; + struct pb_buffer *buffer; void *map; struct pool_buffer *bufs; }; -static inline struct pool_buffer_manager * -pool_buffer_manager(struct buffer_manager *mgr) +static inline struct pool_pb_manager * +pool_pb_manager(struct pb_manager *mgr) { assert(mgr); - return (struct pool_buffer_manager *)mgr; + return (struct pool_pb_manager *)mgr; } struct pool_buffer { - struct pipe_buffer base; + struct pb_buffer base; - struct pool_buffer_manager *mgr; + struct pool_pb_manager *mgr; struct list_head head; @@ -96,25 +96,19 @@ struct pool_buffer static inline struct pool_buffer * -pool_buffer(struct pipe_buffer *buf) +pool_buffer(struct pb_buffer *buf) { assert(buf); return (struct pool_buffer *)buf; } -static void -pool_buffer_reference(struct pipe_buffer *buf) -{ - /* No-op */ -} - static void -pool_buffer_release(struct pipe_buffer *buf) +pool_buffer_destroy(struct pb_buffer *buf) { struct pool_buffer *pool_buf = pool_buffer(buf); - struct pool_buffer_manager *pool = pool_buf->mgr; + struct pool_pb_manager *pool = pool_buf->mgr; _glthread_LOCK_MUTEX(pool->mutex); LIST_ADD(&pool_buf->head, &pool->free); @@ -124,10 +118,10 @@ pool_buffer_release(struct pipe_buffer *buf) static void * -pool_buffer_map(struct pipe_buffer *buf, unsigned flags) +pool_buffer_map(struct pb_buffer *buf, unsigned flags) { struct pool_buffer *pool_buf = pool_buffer(buf); - struct pool_buffer_manager *pool = pool_buf->mgr; + struct pool_pb_manager *pool = pool_buf->mgr; void *map; _glthread_LOCK_MUTEX(pool->mutex); @@ -138,38 +132,37 @@ pool_buffer_map(struct pipe_buffer *buf, unsigned flags) static void -pool_buffer_unmap(struct pipe_buffer *buf) +pool_buffer_unmap(struct pb_buffer *buf) { /* No-op */ } static void -pool_buffer_get_base_buffer(struct pipe_buffer *buf, - struct pipe_buffer **base_buf, +pool_buffer_get_base_buffer(struct pb_buffer *buf, + struct pb_buffer **base_buf, unsigned *offset) { struct pool_buffer *pool_buf = pool_buffer(buf); - struct pool_buffer_manager *pool = pool_buf->mgr; - buffer_get_base_buffer(pool->buffer, base_buf, offset); + struct pool_pb_manager *pool = pool_buf->mgr; + pb_get_base_buffer(pool->buffer, base_buf, offset); *offset += pool_buf->start; } -static const struct pipe_buffer_vtbl +static const struct pb_vtbl pool_buffer_vtbl = { - pool_buffer_reference, - pool_buffer_release, + pool_buffer_destroy, pool_buffer_map, pool_buffer_unmap, pool_buffer_get_base_buffer }; -static struct pipe_buffer * -pool_bufmgr_create_buffer(struct buffer_manager *mgr, size_t size) +static struct pb_buffer * +pool_bufmgr_create_buffer(struct pb_manager *mgr, size_t size) { - struct pool_buffer_manager *pool = pool_buffer_manager(mgr); + struct pool_pb_manager *pool = pool_pb_manager(mgr); struct pool_buffer *pool_buf; struct list_head *item; @@ -201,15 +194,15 @@ pool_bufmgr_create_buffer(struct buffer_manager *mgr, size_t size) static void -pool_bufmgr_destroy(struct buffer_manager *mgr) +pool_bufmgr_destroy(struct pb_manager *mgr) { - struct pool_buffer_manager *pool = pool_buffer_manager(mgr); + struct pool_pb_manager *pool = pool_pb_manager(mgr); _glthread_LOCK_MUTEX(pool->mutex); free(pool->bufs); - buffer_unmap(pool->buffer); - buffer_release(pool->buffer); + pb_unmap(pool->buffer); + pb_destroy(pool->buffer); _glthread_UNLOCK_MUTEX(pool->mutex); @@ -217,16 +210,16 @@ pool_bufmgr_destroy(struct buffer_manager *mgr) } -struct buffer_manager * -pool_bufmgr_create(struct buffer_manager *provider, +struct pb_manager * +pool_bufmgr_create(struct pb_manager *provider, size_t numBufs, size_t bufSize) { - struct pool_buffer_manager *pool; + struct pool_pb_manager *pool; struct pool_buffer *pool_buf; int i; - pool = (struct pool_buffer_manager *)calloc(1, sizeof(*pool)); + pool = (struct pool_pb_manager *)calloc(1, sizeof(*pool)); if (!pool) return NULL; @@ -245,7 +238,7 @@ pool_bufmgr_create(struct buffer_manager *provider, if (!pool->buffer) goto failure; - pool->map = buffer_map(pool->buffer, + pool->map = pb_map(pool->buffer, PIPE_BUFFER_USAGE_CPU_READ | PIPE_BUFFER_USAGE_CPU_WRITE); if(!pool->map) @@ -270,9 +263,9 @@ failure: if(pool->bufs) free(pool->bufs); if(pool->map) - buffer_unmap(pool->buffer); + pb_unmap(pool->buffer); if(pool->buffer) - buffer_release(pool->buffer); + pb_destroy(pool->buffer); if(pool) free(pool); return NULL; diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c index 8dadd9aa74..cea6b90104 100644 --- a/src/mesa/pipe/softpipe/sp_context.c +++ b/src/mesa/pipe/softpipe/sp_context.c @@ -135,7 +135,7 @@ static void softpipe_destroy( struct pipe_context *pipe ) for (i = 0; i < Elements(softpipe->constants); i++) { if (softpipe->constants[i].buffer) { - ws->buffer_reference(ws, &softpipe->constants[i].buffer, NULL); + pipe_buffer_reference(ws, &softpipe->constants[i].buffer, NULL); } } diff --git a/src/mesa/pipe/softpipe/sp_draw_arrays.c b/src/mesa/pipe/softpipe/sp_draw_arrays.c index 8ee9177e5b..423c91d4b8 100644 --- a/src/mesa/pipe/softpipe/sp_draw_arrays.c +++ b/src/mesa/pipe/softpipe/sp_draw_arrays.c @@ -88,7 +88,7 @@ softpipe_draw_arrays(struct pipe_context *pipe, unsigned mode, */ boolean softpipe_draw_elements(struct pipe_context *pipe, - struct pipe_buffer_handle *indexBuffer, + struct pipe_buffer *indexBuffer, unsigned indexSize, unsigned mode, unsigned start, unsigned count) { diff --git a/src/mesa/pipe/softpipe/sp_state.h b/src/mesa/pipe/softpipe/sp_state.h index bac7b0876f..af955c1e17 100644 --- a/src/mesa/pipe/softpipe/sp_state.h +++ b/src/mesa/pipe/softpipe/sp_state.h @@ -157,7 +157,7 @@ boolean softpipe_draw_arrays(struct pipe_context *pipe, unsigned mode, unsigned start, unsigned count); boolean softpipe_draw_elements(struct pipe_context *pipe, - struct pipe_buffer_handle *indexBuffer, + struct pipe_buffer *indexBuffer, unsigned indexSize, unsigned mode, unsigned start, unsigned count); diff --git a/src/mesa/pipe/softpipe/sp_state_fs.c b/src/mesa/pipe/softpipe/sp_state_fs.c index 945c93411f..1430be7869 100644 --- a/src/mesa/pipe/softpipe/sp_state_fs.c +++ b/src/mesa/pipe/softpipe/sp_state_fs.c @@ -30,6 +30,7 @@ #include "pipe/p_defines.h" #include "pipe/p_util.h" +#include "pipe/p_inlines.h" #include "pipe/p_winsys.h" #include "pipe/draw/draw_context.h" #include "pipe/p_shader_tokens.h" @@ -165,9 +166,9 @@ softpipe_set_constant_buffer(struct pipe_context *pipe, assert(index == 0); /* note: reference counting */ - ws->buffer_reference(ws, - &softpipe->constants[shader].buffer, - buf->buffer); + pipe_buffer_reference(ws, + &softpipe->constants[shader].buffer, + buf->buffer); softpipe->constants[shader].size = buf->size; softpipe->dirty |= SP_NEW_CONSTANTS; diff --git a/src/mesa/pipe/softpipe/sp_texture.c b/src/mesa/pipe/softpipe/sp_texture.c index 23e9c1b376..172234843d 100644 --- a/src/mesa/pipe/softpipe/sp_texture.c +++ b/src/mesa/pipe/softpipe/sp_texture.c @@ -121,7 +121,7 @@ softpipe_texture_release(struct pipe_context *pipe, struct pipe_texture **pt) DBG("%s deleting %p\n", __FUNCTION__, (void *) spt); */ - pipe->winsys->buffer_reference(pipe->winsys, &spt->buffer, NULL); + pipe_buffer_reference(pipe->winsys, &spt->buffer, NULL); FREE(spt); } @@ -144,7 +144,7 @@ softpipe_get_tex_surface(struct pipe_context *pipe, if (ps) { assert(ps->refcount); assert(ps->winsys); - pipe->winsys->buffer_reference(pipe->winsys, &ps->buffer, spt->buffer); + pipe_buffer_reference(pipe->winsys, &ps->buffer, spt->buffer); ps->format = pt->format; ps->cpp = pt->cpp; ps->width = pt->width[level]; diff --git a/src/mesa/pipe/softpipe/sp_texture.h b/src/mesa/pipe/softpipe/sp_texture.h index 0494bf365b..c6cf370351 100644 --- a/src/mesa/pipe/softpipe/sp_texture.h +++ b/src/mesa/pipe/softpipe/sp_texture.h @@ -41,7 +41,7 @@ struct softpipe_texture /* The data is held here: */ - struct pipe_buffer_handle *buffer; + struct pipe_buffer *buffer; unsigned long buffer_size; }; diff --git a/src/mesa/pipe/xlib/xm_winsys.c b/src/mesa/pipe/xlib/xm_winsys.c index cb043ef394..c3cd22eea3 100644 --- a/src/mesa/pipe/xlib/xm_winsys.c +++ b/src/mesa/pipe/xlib/xm_winsys.c @@ -40,6 +40,7 @@ #include "pipe/p_format.h" #include "pipe/p_context.h" #include "pipe/p_util.h" +#include "pipe/p_inlines.h" #include "pipe/softpipe/sp_winsys.h" #ifdef GALLIUM_CELL @@ -57,9 +58,8 @@ */ struct xm_buffer { + struct pipe_buffer base; boolean userBuffer; /** Is this a user-space buffer? */ - int refcount; - unsigned size; void *data; void *mapped; }; @@ -106,63 +106,44 @@ xmesa_softpipe_winsys(struct softpipe_winsys *spws) * buffer pointer... */ static INLINE struct xm_buffer * -xm_bo( struct pipe_buffer_handle *bo ) +xm_buffer( struct pipe_buffer *buf ) { - return (struct xm_buffer *) bo; + return (struct xm_buffer *)buf; } -static INLINE struct pipe_buffer_handle * -pipe_bo( struct xm_buffer *bo ) -{ - return (struct pipe_buffer_handle *) bo; -} /* Most callbacks map direcly onto dri_bufmgr operations: */ static void * -xm_buffer_map(struct pipe_winsys *pws, struct pipe_buffer_handle *buf, +xm_buffer_map(struct pipe_winsys *pws, struct pipe_buffer *buf, unsigned flags) { - struct xm_buffer *xm_buf = xm_bo(buf); + struct xm_buffer *xm_buf = xm_buffer(buf); xm_buf->mapped = xm_buf->data; return xm_buf->mapped; } static void -xm_buffer_unmap(struct pipe_winsys *pws, struct pipe_buffer_handle *buf) +xm_buffer_unmap(struct pipe_winsys *pws, struct pipe_buffer *buf) { - struct xm_buffer *xm_buf = xm_bo(buf); + struct xm_buffer *xm_buf = xm_buffer(buf); xm_buf->mapped = NULL; } static void -xm_buffer_reference(struct pipe_winsys *pws, - struct pipe_buffer_handle **ptr, - struct pipe_buffer_handle *buf) +xm_buffer_destroy(struct pipe_winsys *pws, + struct pipe_buffer *buf) { - if (*ptr) { - struct xm_buffer *oldBuf = xm_bo(*ptr); - oldBuf->refcount--; - assert(oldBuf->refcount >= 0); - if (oldBuf->refcount == 0) { - if (oldBuf->data) { - if (!oldBuf->userBuffer) - align_free(oldBuf->data); - oldBuf->data = NULL; - } - free(oldBuf); - } - *ptr = NULL; - } + struct xm_buffer *oldBuf = xm_buffer(buf); - assert(!(*ptr)); - - if (buf) { - struct xm_buffer *newBuf = xm_bo(buf); - newBuf->refcount++; - *ptr = buf; + if (oldBuf->data) { + if (!oldBuf->userBuffer) + align_free(oldBuf->data); + oldBuf->data = NULL; } + + free(oldBuf); } @@ -174,7 +155,7 @@ static void xmesa_display_surface_tiled(XMesaBuffer b, const struct pipe_surface *surf) { XImage *ximage = b->tempImage; - struct xm_buffer *xm_buf = xm_bo(surf->buffer); + struct xm_buffer *xm_buf = xm_buffer(surf->buffer); const uint tilesPerRow = (surf->width + TILE_SIZE - 1) / TILE_SIZE; uint x, y; @@ -214,7 +195,7 @@ void xmesa_display_surface(XMesaBuffer b, const struct pipe_surface *surf) { XImage *ximage = b->tempImage; - struct xm_buffer *xm_buf = xm_bo(surf->buffer); + struct xm_buffer *xm_buf = xm_buffer(surf->buffer); const struct xmesa_surface *xm_surf = xmesa_surface((struct pipe_surface *) surf); @@ -272,35 +253,38 @@ xm_get_name(struct pipe_winsys *pws) } -static struct pipe_buffer_handle * +static struct pipe_buffer * xm_buffer_create(struct pipe_winsys *pws, unsigned alignment, unsigned usage, unsigned size) { struct xm_buffer *buffer = CALLOC_STRUCT(xm_buffer); - buffer->refcount = 1; + buffer->base.refcount = 1; + buffer->base.alignment = alignment; + buffer->base.usage = usage; + buffer->base.size = size; /* align to 16-byte multiple for Cell */ buffer->data = align_malloc(size, max(alignment, 16)); - buffer->size = size; - return pipe_bo(buffer); + return &buffer->base; } /** * Create buffer which wraps user-space data. */ -static struct pipe_buffer_handle * +static struct pipe_buffer * xm_user_buffer_create(struct pipe_winsys *pws, void *ptr, unsigned bytes) { struct xm_buffer *buffer = CALLOC_STRUCT(xm_buffer); + buffer->base.refcount = 1; + buffer->base.size = bytes; buffer->userBuffer = TRUE; - buffer->refcount = 1; buffer->data = ptr; - buffer->size = bytes; - return pipe_bo(buffer); + + return &buffer->base; } @@ -376,7 +360,7 @@ xm_surface_release(struct pipe_winsys *winsys, struct pipe_surface **s) surf->refcount--; if (surf->refcount == 0) { if (surf->buffer) - winsys->buffer_reference(winsys, &surf->buffer, NULL); + pipe_buffer_reference(winsys, &surf->buffer, NULL); free(surf); } *s = NULL; @@ -407,7 +391,7 @@ xmesa_get_pipe_winsys_aub(void) ws->user_buffer_create = xm_user_buffer_create; ws->buffer_map = xm_buffer_map; ws->buffer_unmap = xm_buffer_unmap; - ws->buffer_reference = xm_buffer_reference; + ws->buffer_destroy = xm_buffer_destroy; ws->surface_alloc = xm_surface_alloc; ws->surface_alloc_storage = xm_surface_alloc_storage; diff --git a/src/mesa/pipe/xlib/xm_winsys_aub.c b/src/mesa/pipe/xlib/xm_winsys_aub.c index 28dd07bc6e..bf41570257 100644 --- a/src/mesa/pipe/xlib/xm_winsys_aub.c +++ b/src/mesa/pipe/xlib/xm_winsys_aub.c @@ -38,6 +38,7 @@ #include "pipe/p_winsys.h" #include "pipe/p_util.h" +#include "pipe/p_inlines.h" #include "pipe/i965simple/brw_winsys.h" #include "brw_aub.h" #include "xm_winsys_aub.h" @@ -79,22 +80,22 @@ aub_pipe_winsys( struct pipe_winsys *winsys ) static INLINE struct aub_buffer * -aub_bo( struct pipe_buffer_handle *bo ) +aub_bo( struct pipe_buffer *bo ) { return (struct aub_buffer *)bo; } -static INLINE struct pipe_buffer_handle * +static INLINE struct pipe_buffer * pipe_bo( struct aub_buffer *bo ) { - return (struct pipe_buffer_handle *)bo; + return (struct pipe_buffer *)bo; } static void *aub_buffer_map(struct pipe_winsys *winsys, - struct pipe_buffer_handle *buf, + struct pipe_buffer *buf, unsigned flags ) { struct aub_buffer *sbo = aub_bo(buf); @@ -109,7 +110,7 @@ static void *aub_buffer_map(struct pipe_winsys *winsys, } static void aub_buffer_unmap(struct pipe_winsys *winsys, - struct pipe_buffer_handle *buf) + struct pipe_buffer *buf) { struct aub_pipe_winsys *iws = aub_pipe_winsys(winsys); struct aub_buffer *sbo = aub_bo(buf); @@ -132,26 +133,15 @@ static void aub_buffer_unmap(struct pipe_winsys *winsys, static void -aub_buffer_reference(struct pipe_winsys *winsys, - struct pipe_buffer_handle **ptr, - struct pipe_buffer_handle *buf) +aub_buffer_destroy(struct pipe_winsys *winsys, + struct pipe_buffer *buf) { - if (*ptr) { - assert(aub_bo(*ptr)->refcount != 0); - if (--(aub_bo(*ptr)->refcount) == 0) - free(*ptr); - *ptr = NULL; - } - - if (buf) { - aub_bo(buf)->refcount++; - *ptr = buf; - } + free(buf); } void xmesa_buffer_subdata_aub(struct pipe_winsys *winsys, - struct pipe_buffer_handle *buf, + struct pipe_buffer *buf, unsigned long offset, unsigned long size, const void *data, @@ -206,7 +196,7 @@ void xmesa_display_aub( /* struct pipe_winsys *winsys, */ /* Pipe has no concept of pools. We choose the tex/region pool * for all buffers. */ -static struct pipe_buffer_handle * +static struct pipe_buffer * aub_buffer_create(struct pipe_winsys *winsys, unsigned alignment, unsigned usage, @@ -231,7 +221,7 @@ aub_buffer_create(struct pipe_winsys *winsys, } -static struct pipe_buffer_handle * +static struct pipe_buffer * aub_user_buffer_create(struct pipe_winsys *winsys, void *ptr, unsigned bytes) { struct aub_buffer *sbo; @@ -312,7 +302,7 @@ aub_i915_surface_release(struct pipe_winsys *winsys, struct pipe_surface **s) surf->refcount--; if (surf->refcount == 0) { if (surf->buffer) - winsys->buffer_reference(winsys, &surf->buffer, NULL); + pipe_buffer_reference(winsys, &surf->buffer, NULL); free(surf); } *s = NULL; @@ -351,7 +341,7 @@ xmesa_create_pipe_winsys_aub( void ) iws->winsys.user_buffer_create = aub_user_buffer_create; iws->winsys.buffer_map = aub_buffer_map; iws->winsys.buffer_unmap = aub_buffer_unmap; - iws->winsys.buffer_reference = aub_buffer_reference; + iws->winsys.buffer_destroy = aub_buffer_destroy; iws->winsys.flush_frontbuffer = aub_flush_frontbuffer; iws->winsys.printf = aub_printf; iws->winsys.get_name = aub_get_name; @@ -439,7 +429,7 @@ static void aub_i965_batch_dword( struct brw_winsys *sws, } static void aub_i965_batch_reloc( struct brw_winsys *sws, - struct pipe_buffer_handle *buf, + struct pipe_buffer *buf, unsigned access_flags, unsigned delta ) { @@ -450,7 +440,7 @@ static void aub_i965_batch_reloc( struct brw_winsys *sws, } static unsigned aub_i965_get_buffer_offset( struct brw_winsys *sws, - struct pipe_buffer_handle *buf, + struct pipe_buffer *buf, unsigned access_flags ) { return aub_bo(buf)->offset; @@ -482,7 +472,7 @@ static void aub_i965_batch_flush( struct brw_winsys *sws, static void aub_i965_buffer_subdata_typed(struct brw_winsys *winsys, - struct pipe_buffer_handle *buf, + struct pipe_buffer *buf, unsigned long offset, unsigned long size, const void *data, diff --git a/src/mesa/pipe/xlib/xm_winsys_aub.h b/src/mesa/pipe/xlib/xm_winsys_aub.h index c0fe449107..7bee199116 100644 --- a/src/mesa/pipe/xlib/xm_winsys_aub.h +++ b/src/mesa/pipe/xlib/xm_winsys_aub.h @@ -30,7 +30,7 @@ struct pipe_context; struct pipe_winsys; -struct pipe_buffer_handle; +struct pipe_buffer; struct pipe_surface; struct pipe_winsys * @@ -47,7 +47,7 @@ xmesa_create_i965simple( struct pipe_winsys *winsys ); void xmesa_buffer_subdata_aub(struct pipe_winsys *winsys, - struct pipe_buffer_handle *buf, + struct pipe_buffer *buf, unsigned long offset, unsigned long size, const void *data, diff --git a/src/mesa/state_tracker/st_atom_constbuf.c b/src/mesa/state_tracker/st_atom_constbuf.c index c9d63136b5..21416da2e0 100644 --- a/src/mesa/state_tracker/st_atom_constbuf.c +++ b/src/mesa/state_tracker/st_atom_constbuf.c @@ -37,6 +37,7 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_winsys.h" +#include "pipe/p_inlines.h" #include "st_context.h" #include "st_atom.h" @@ -70,7 +71,7 @@ void st_upload_constants( struct st_context *st, _mesa_load_state_parameters(st->ctx, params); if (cbuf->buffer && cbuf->size != paramBytes) - ws->buffer_reference( ws, &cbuf->buffer, NULL ); + pipe_buffer_reference( ws, &cbuf->buffer, NULL ); if (!cbuf->buffer) { cbuf->buffer = ws->buffer_create(ws, 1, PIPE_BUFFER_USAGE_CONSTANT, diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c index 60bd1d5f0d..fa1254ff7c 100644 --- a/src/mesa/state_tracker/st_cb_bufferobjects.c +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c @@ -36,6 +36,7 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_winsys.h" +#include "pipe/p_inlines.h" @@ -78,7 +79,7 @@ st_bufferobj_free(GLcontext *ctx, struct gl_buffer_object *obj) struct st_buffer_object *st_obj = st_buffer_object(obj); if (st_obj->buffer) - pipe->winsys->buffer_reference(pipe->winsys, &st_obj->buffer, NULL); + pipe_buffer_reference(pipe->winsys, &st_obj->buffer, NULL); free(st_obj); } @@ -173,7 +174,7 @@ st_bufferobj_data(GLcontext *ctx, buffer_usage = 0; } - pipe->winsys->buffer_reference( pipe->winsys, &st_obj->buffer, NULL ); + pipe_buffer_reference( pipe->winsys, &st_obj->buffer, NULL ); st_obj->buffer = pipe->winsys->buffer_create( pipe->winsys, 32, buffer_usage, size ); diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.h b/src/mesa/state_tracker/st_cb_bufferobjects.h index 15003ae15d..dcbb5a5233 100644 --- a/src/mesa/state_tracker/st_cb_bufferobjects.h +++ b/src/mesa/state_tracker/st_cb_bufferobjects.h @@ -30,7 +30,7 @@ struct st_context; struct gl_buffer_object; -struct pipe_buffer_handle; +struct pipe_buffer; /** * State_tracker vertex/pixel buffer object, derived from Mesa's @@ -39,7 +39,7 @@ struct pipe_buffer_handle; struct st_buffer_object { struct gl_buffer_object Base; - struct pipe_buffer_handle *buffer; + struct pipe_buffer *buffer; GLsizeiptrARB size; }; diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index f02cb3d133..4341623267 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -100,8 +100,8 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, } if (strb->surface->buffer) - pipe->winsys->buffer_reference(pipe->winsys, &strb->surface->buffer, - NULL); + pipe_buffer_reference(pipe->winsys, &strb->surface->buffer, + NULL); /* Determine surface format here */ if (strb->format != PIPE_FORMAT_NONE) { diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 668ac139f7..9c206c057a 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -52,6 +52,7 @@ #include "st_program.h" #include "pipe/p_context.h" #include "pipe/p_winsys.h" +#include "pipe/p_inlines.h" #include "pipe/draw/draw_context.h" #include "pipe/cso_cache/cso_cache.h" @@ -152,7 +153,7 @@ static void st_destroy_context_priv( struct st_context *st ) for (i = 0; i < Elements(st->state.constants); i++) { if (st->state.constants[i].buffer) { - ws->buffer_reference(ws, &st->state.constants[i].buffer, NULL); + pipe_buffer_reference(ws, &st->state.constants[i].buffer, NULL); } } diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index 371d4e7966..8ef50ee768 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -45,6 +45,7 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_winsys.h" +#include "pipe/p_inlines.h" #include "pipe/draw/draw_private.h" #include "pipe/draw/draw_context.h" @@ -237,7 +238,7 @@ st_draw_vbo(GLcontext *ctx, assert(stobj->buffer); vbuffer[attr].buffer = NULL; - winsys->buffer_reference(winsys, &vbuffer[attr].buffer, stobj->buffer); + pipe_buffer_reference(winsys, &vbuffer[attr].buffer, stobj->buffer); vbuffer[attr].buffer_offset = (unsigned) arrays[0]->Ptr;/* in bytes */ velement.src_offset = arrays[mesaAttr]->Ptr - arrays[0]->Ptr; assert(velement.src_offset <= 2048); /* 11-bit field */ @@ -282,7 +283,7 @@ st_draw_vbo(GLcontext *ctx, if (ib) { /* indexed primitive */ struct gl_buffer_object *bufobj = ib->obj; - struct pipe_buffer_handle *indexBuf = NULL; + struct pipe_buffer *indexBuf = NULL; unsigned indexSize, indexOffset, i; switch (ib->type) { @@ -303,7 +304,7 @@ st_draw_vbo(GLcontext *ctx, if (bufobj && bufobj->Name) { /* elements/indexes are in a real VBO */ struct st_buffer_object *stobj = st_buffer_object(bufobj); - winsys->buffer_reference(winsys, &indexBuf, stobj->buffer); + pipe_buffer_reference(winsys, &indexBuf, stobj->buffer); indexOffset = (unsigned) ib->ptr / indexSize; } else { @@ -321,7 +322,7 @@ st_draw_vbo(GLcontext *ctx, prims[i].start + indexOffset, prims[i].count); } - winsys->buffer_reference(winsys, &indexBuf, NULL); + pipe_buffer_reference(winsys, &indexBuf, NULL); } else { /* non-indexed */ @@ -333,7 +334,7 @@ st_draw_vbo(GLcontext *ctx, /* unreference buffers (frees wrapped user-space buffer objects) */ for (attr = 0; attr < vs->num_inputs; attr++) { - winsys->buffer_reference(winsys, &vbuffer[attr].buffer, NULL); + pipe_buffer_reference(winsys, &vbuffer[attr].buffer, NULL); assert(!vbuffer[attr].buffer); pipe->set_vertex_buffer(pipe, attr, &vbuffer[attr]); } @@ -358,7 +359,7 @@ st_draw_vertices(GLcontext *ctx, unsigned prim, const float height = ctx->DrawBuffer->Height; const unsigned vertex_bytes = numVertex * numAttribs * 4 * sizeof(float); struct pipe_context *pipe = ctx->st->pipe; - struct pipe_buffer_handle *vbuf; + struct pipe_buffer *vbuf; struct pipe_vertex_buffer vbuffer; struct pipe_vertex_element velement; unsigned i; @@ -404,7 +405,7 @@ st_draw_vertices(GLcontext *ctx, unsigned prim, pipe->draw_arrays(pipe, prim, 0, numVertex); /* XXX: do one-time */ - pipe->winsys->buffer_reference(pipe->winsys, &vbuf, NULL); + pipe_buffer_reference(pipe->winsys, &vbuf, NULL); } @@ -465,7 +466,7 @@ st_feedback_draw_vbo(GLcontext *ctx, struct pipe_winsys *winsys = pipe->winsys; const struct st_vertex_program *vp; const struct pipe_shader_state *vs; - struct pipe_buffer_handle *index_buffer_handle = 0; + struct pipe_buffer *index_buffer_handle = 0; struct pipe_vertex_buffer vbuffer[PIPE_MAX_SHADER_INPUTS]; GLuint attr, i; ubyte *mapped_constants; @@ -513,7 +514,7 @@ st_feedback_draw_vbo(GLcontext *ctx, assert(stobj->buffer); vbuffer[attr].buffer = NULL; - winsys->buffer_reference(winsys, &vbuffer[attr].buffer, stobj->buffer); + pipe_buffer_reference(winsys, &vbuffer[attr].buffer, stobj->buffer); vbuffer[attr].buffer_offset = (unsigned) arrays[0]->Ptr;/* in bytes */ velement.src_offset = arrays[mesaAttr]->Ptr - arrays[0]->Ptr; } @@ -605,7 +606,7 @@ st_feedback_draw_vbo(GLcontext *ctx, if (draw->vertex_buffer[i].buffer) { pipe->winsys->buffer_unmap(pipe->winsys, draw->vertex_buffer[i].buffer); - winsys->buffer_reference(winsys, &draw->vertex_buffer[i].buffer, NULL); + pipe_buffer_reference(winsys, &draw->vertex_buffer[i].buffer, NULL); draw_set_mapped_vertex_buffer(draw, i, NULL); } } -- cgit v1.2.3 From 58edb0683db45c449b219988a8715cf8fd69e42d Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 20 Feb 2008 11:20:25 -0700 Subject: gallium: state tracker didn't always notify drivers of texobj data changes Calling glTexSubImage() or glTexImage() to replace texture data didn't reliably cause pipe->set_sampler_texture() to get called so drivers didn't always get notified of new texture data. The st_texture_object->pt pointer doesn't always indicate changed data so added a dirtyData field. --- src/mesa/state_tracker/st_atom_texture.c | 18 ++++----- src/mesa/state_tracker/st_cb_drawpixels.c | 3 +- src/mesa/state_tracker/st_cb_fbo.c | 1 + src/mesa/state_tracker/st_cb_texture.c | 42 ++++---------------- src/mesa/state_tracker/st_cb_texture.h | 32 ++++++++++++++-- src/mesa/state_tracker/st_context.h | 22 +---------- src/mesa/state_tracker/st_gen_mipmap.c | 4 +- src/mesa/state_tracker/st_texture.h | 64 +++++++++++++++++++++++++++++++ 8 files changed, 115 insertions(+), 71 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c index 2a836d630b..9fead7e314 100644 --- a/src/mesa/state_tracker/st_atom_texture.c +++ b/src/mesa/state_tracker/st_atom_texture.c @@ -34,6 +34,7 @@ #include "st_context.h" #include "st_atom.h" +#include "st_texture.h" #include "st_cb_texture.h" #include "pipe/p_context.h" @@ -53,27 +54,26 @@ update_textures(struct st_context *st) for (unit = 0; unit < st->ctx->Const.MaxTextureCoordUnits; unit++) { const GLuint su = fprog->Base.SamplerUnits[unit]; struct gl_texture_object *texObj = st->ctx->Texture.Unit[su]._Current; - struct pipe_texture *pt; + struct st_texture_object *stObj = st_texture_object(texObj); if (texObj) { GLboolean flush, retval; retval = st_finalize_texture(st->ctx, st->pipe, texObj, &flush); /* XXX retval indicates whether there's a texture border */ - - pt = st_get_texobj_texture(texObj); - } - else { - pt = NULL; } /* XXX: need to ensure that textures are unbound/removed from * this table before being deleted, otherwise the pointer * comparison below could fail. */ - if (st->state.sampler_texture[unit] != pt) { - st->state.sampler_texture[unit] = pt; - st->pipe->set_sampler_texture(st->pipe, unit, pt); + if (st->state.sampler_texture[unit] != stObj || + (stObj && stObj->dirtyData)) { + struct pipe_texture *pt = st_get_stobj_texture(stObj); + st->state.sampler_texture[unit] = stObj; + st->pipe->set_sampler_texture(st->pipe, unit, pt); + if (stObj) + stObj->dirtyData = GL_FALSE; } } } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index e2d4e06da1..585cae3743 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -726,7 +726,8 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, pipe->bind_rasterizer_state(pipe, ctx->st->state.rasterizer->data); pipe->bind_fs_state(pipe, ctx->st->state.fs->data); pipe->bind_vs_state(pipe, ctx->st->state.vs->cso->data); - pipe->set_sampler_texture(pipe, unit, ctx->st->state.sampler_texture[unit]); + pipe->set_sampler_texture(pipe, unit, + st_get_stobj_texture(ctx->st->state.sampler_texture[unit])); pipe->bind_sampler_state(pipe, unit, ctx->st->state.sampler[unit]->data); pipe->set_viewport_state(pipe, &ctx->st->state.viewport); } diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 4341623267..781425b546 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -48,6 +48,7 @@ #include "st_cb_texture.h" #include "st_format.h" #include "st_public.h" +#include "st_texture.h" diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 03dbb30b0f..7226b0dd98 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -53,33 +53,6 @@ #define DBG if (0) printf -struct st_texture_object -{ - struct gl_texture_object base; /* The "parent" object */ - - /* The texture must include at levels [0..lastLevel] once validated: - */ - GLuint lastLevel; - - /* On validation any active images held in main memory or in other - * textures will be copied to this texture and the old storage freed. - */ - struct pipe_texture *pt; - - GLboolean imageOverride; - GLint depthOverride; - GLuint pitchOverride; -}; - - - -static INLINE struct st_texture_object * -st_texture_object(struct gl_texture_object *obj) -{ - return (struct st_texture_object *) obj; -} - - static INLINE struct st_texture_image * st_texture_image(struct gl_texture_image *img) { @@ -87,14 +60,6 @@ st_texture_image(struct gl_texture_image *img) } -struct pipe_texture * -st_get_texobj_texture(struct gl_texture_object *texObj) -{ - struct st_texture_object *stObj = st_texture_object(texObj); - return stObj->pt; -} - - static enum pipe_texture_target gl_target_to_pipe(GLenum target) { @@ -725,6 +690,9 @@ st_TexImage(GLcontext * ctx, texImage->Data = NULL; } + /* flag data as dirty */ + stObj->dirtyData = GL_TRUE; + #if 01 if (level == texObj->BaseLevel && texObj->GenerateMipmap) { ctx->Driver.GenerateMipmap(ctx, target, texObj); @@ -900,6 +868,7 @@ st_TexSubimage(GLcontext * ctx, struct gl_texture_object *texObj, struct gl_texture_image *texImage) { + struct st_texture_object *stObj = st_texture_object(texObj); struct st_texture_image *stImage = st_texture_image(texImage); GLuint dstRowStride; GLuint srcImageStride = _mesa_image_image_stride(packing, width, height, @@ -961,6 +930,9 @@ st_TexSubimage(GLcontext * ctx, st_texture_image_unmap(stImage); texImage->Data = NULL; } + + /* flag data as dirty */ + stObj->dirtyData = GL_TRUE; } diff --git a/src/mesa/state_tracker/st_cb_texture.h b/src/mesa/state_tracker/st_cb_texture.h index 878256ec26..843745fcd6 100644 --- a/src/mesa/state_tracker/st_cb_texture.h +++ b/src/mesa/state_tracker/st_cb_texture.h @@ -1,9 +1,33 @@ -#ifndef ST_CB_TEXTURE_H -#define ST_CB_TEXTURE_H +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ -extern struct pipe_texture * -st_get_texobj_texture(struct gl_texture_object *texObj); +#ifndef ST_CB_TEXTURE_H +#define ST_CB_TEXTURE_H extern GLboolean diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 59d1590f05..5be4769be4 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -59,26 +59,6 @@ struct st_tracked_state { -struct st_texture_image -{ - struct gl_texture_image base; - - /* These aren't stored in gl_texture_image - */ - GLuint level; - GLuint face; - - /* If stImage->pt != NULL, image data is stored here. - * Else if stImage->base.Data != NULL, image is stored there. - * Else there is no image data. - */ - struct pipe_texture *pt; - - struct pipe_surface *surface; -}; - - - struct st_context { GLcontext *ctx; @@ -106,7 +86,7 @@ struct st_context struct pipe_clip_state clip; struct pipe_constant_buffer constants[2]; struct pipe_framebuffer_state framebuffer; - struct pipe_texture *sampler_texture[PIPE_MAX_SAMPLERS]; + struct st_texture_object *sampler_texture[PIPE_MAX_SAMPLERS]; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; struct pipe_viewport_state viewport; diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c index 6c09b86033..a0b4b973aa 100644 --- a/src/mesa/state_tracker/st_gen_mipmap.c +++ b/src/mesa/state_tracker/st_gen_mipmap.c @@ -43,6 +43,7 @@ #include "st_draw.h" #include "st_gen_mipmap.h" #include "st_program.h" +#include "st_texture.h" #include "st_cb_drawpixels.h" #include "st_cb_texture.h" @@ -302,7 +303,8 @@ st_render_mipmap(struct st_context *st, pipe->bind_vs_state(pipe, st->state.vs->cso->data); if (st->state.sampler[0]) pipe->bind_sampler_state(pipe, 0, st->state.sampler[0]->data); - pipe->set_sampler_texture(pipe, 0, st->state.sampler_texture[0]); + pipe->set_sampler_texture(pipe, 0, + st_get_stobj_texture(st->state.sampler_texture[0])); pipe->set_viewport_state(pipe, &st->state.viewport); return TRUE; diff --git a/src/mesa/state_tracker/st_texture.h b/src/mesa/state_tracker/st_texture.h index 72324cd9ab..78f5f451ed 100644 --- a/src/mesa/state_tracker/st_texture.h +++ b/src/mesa/state_tracker/st_texture.h @@ -35,6 +35,70 @@ struct pipe_context; struct pipe_texture; +struct st_texture_image +{ + struct gl_texture_image base; + + /* These aren't stored in gl_texture_image + */ + GLuint level; + GLuint face; + + /* If stImage->pt != NULL, image data is stored here. + * Else if stImage->base.Data != NULL, image is stored there. + * Else there is no image data. + */ + struct pipe_texture *pt; + + struct pipe_surface *surface; +}; + + + +struct st_texture_object +{ + struct gl_texture_object base; /* The "parent" object */ + + /* The texture must include at levels [0..lastLevel] once validated: + */ + GLuint lastLevel; + + /* On validation any active images held in main memory or in other + * textures will be copied to this texture and the old storage freed. + */ + struct pipe_texture *pt; + + GLboolean imageOverride; + GLint depthOverride; + GLuint pitchOverride; + + GLboolean dirtyData; +}; + + +static INLINE struct st_texture_object * +st_texture_object(struct gl_texture_object *obj) +{ + return (struct st_texture_object *) obj; +} + + +static INLINE struct pipe_texture * +st_get_texobj_texture(struct gl_texture_object *texObj) +{ + struct st_texture_object *stObj = st_texture_object(texObj); + return stObj ? stObj->pt : NULL; +} + + +static INLINE struct pipe_texture * +st_get_stobj_texture(struct st_texture_object *stObj) +{ + return stObj ? stObj->pt : NULL; +} + + + extern struct pipe_texture * st_texture_create(struct st_context *st, enum pipe_texture_target target, -- cgit v1.2.3 From 6f715dcc219071e574e363a9db4365c9c31ebbd3 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 27 Feb 2008 14:21:12 -0700 Subject: gallium: remove pipe_context->texture_create/release/get_tex_surface() These functions are now per-screen, not per-context. --- src/gallium/auxiliary/draw/draw_aaline.c | 5 ++- src/gallium/auxiliary/draw/draw_pstipple.c | 6 ++- src/gallium/drivers/cell/ppu/cell_texture.c | 30 ------------- src/gallium/drivers/failover/fo_context.c | 4 +- src/gallium/drivers/i915simple/i915_texture.c | 28 ------------ src/gallium/drivers/i965simple/brw_tex_layout.c | 30 ------------- src/gallium/drivers/softpipe/sp_texture.c | 60 ++++++------------------- src/gallium/drivers/softpipe/sp_tile_cache.c | 3 +- src/gallium/include/pipe/p_context.h | 18 +------- src/gallium/include/pipe/p_inlines.h | 18 +++----- src/mesa/state_tracker/st_cb_drawpixels.c | 8 ++-- src/mesa/state_tracker/st_cb_fbo.c | 9 ++-- src/mesa/state_tracker/st_cb_texture.c | 28 ++++++------ src/mesa/state_tracker/st_gen_mipmap.c | 7 +-- src/mesa/state_tracker/st_texture.c | 16 ++++--- 15 files changed, 71 insertions(+), 199 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/gallium/auxiliary/draw/draw_aaline.c b/src/gallium/auxiliary/draw/draw_aaline.c index 73a02a32e4..be6cfd3b6a 100644 --- a/src/gallium/auxiliary/draw/draw_aaline.c +++ b/src/gallium/auxiliary/draw/draw_aaline.c @@ -362,6 +362,7 @@ static void aaline_create_texture(struct aaline_stage *aaline) { struct pipe_context *pipe = aaline->pipe; + struct pipe_screen *screen = pipe->screen; struct pipe_texture texTemp; uint level; @@ -374,7 +375,7 @@ aaline_create_texture(struct aaline_stage *aaline) texTemp.depth[0] = 1; texTemp.cpp = 1; - aaline->texture = pipe->texture_create(pipe, &texTemp); + aaline->texture = screen->texture_create(screen, &texTemp); /* Fill in mipmap images. * Basically each level is solid opaque, except for the outermost @@ -388,7 +389,7 @@ aaline_create_texture(struct aaline_stage *aaline) assert(aaline->texture->width[level] == aaline->texture->height[level]); - surface = pipe->get_tex_surface(pipe, aaline->texture, 0, level, 0); + surface = screen->get_tex_surface(screen, aaline->texture, 0, level, 0); data = pipe_surface_map(surface); for (i = 0; i < size; i++) { diff --git a/src/gallium/auxiliary/draw/draw_pstipple.c b/src/gallium/auxiliary/draw/draw_pstipple.c index 1ab04cd959..efc88bf038 100644 --- a/src/gallium/auxiliary/draw/draw_pstipple.c +++ b/src/gallium/auxiliary/draw/draw_pstipple.c @@ -348,12 +348,13 @@ pstip_update_texture(struct pstip_stage *pstip) { static const uint bit31 = 1 << 31; struct pipe_context *pipe = pstip->pipe; + struct pipe_screen *screen = pipe->screen; struct pipe_surface *surface; const uint *stipple = pstip->state.stipple->stipple; uint i, j; ubyte *data; - surface = pipe->get_tex_surface(pipe, pstip->texture, 0, 0, 0); + surface = screen->get_tex_surface(screen, pstip->texture, 0, 0, 0); data = pipe_surface_map(surface); /* @@ -389,6 +390,7 @@ static void pstip_create_texture(struct pstip_stage *pstip) { struct pipe_context *pipe = pstip->pipe; + struct pipe_screen *screen = pipe->screen; struct pipe_texture texTemp; memset(&texTemp, 0, sizeof(texTemp)); @@ -400,7 +402,7 @@ pstip_create_texture(struct pstip_stage *pstip) texTemp.depth[0] = 1; texTemp.cpp = 1; - pstip->texture = pipe->texture_create(pipe, &texTemp); + pstip->texture = screen->texture_create(screen, &texTemp); //pstip_update_texture(pstip); } diff --git a/src/gallium/drivers/cell/ppu/cell_texture.c b/src/gallium/drivers/cell/ppu/cell_texture.c index e6398a85fa..28cadad6ed 100644 --- a/src/gallium/drivers/cell/ppu/cell_texture.c +++ b/src/gallium/drivers/cell/ppu/cell_texture.c @@ -79,14 +79,6 @@ cell_texture_layout(struct cell_texture * spt) } -static struct pipe_texture * -cell_texture_create(struct pipe_context *pipe, - const struct pipe_texture *templat) -{ - return pipe->screen->texture_create(pipe->screen, templat); - -} - static struct pipe_texture * cell_texture_create_screen(struct pipe_screen *screen, const struct pipe_texture *templat) @@ -116,13 +108,6 @@ cell_texture_create_screen(struct pipe_screen *screen, } -static void -cell_texture_release(struct pipe_context *pipe, struct pipe_texture **pt) -{ - return pipe->screen->texture_release(pipe->screen, pt); -} - - static void cell_texture_release_screen(struct pipe_screen *screen, struct pipe_texture **pt) @@ -157,18 +142,6 @@ cell_texture_update(struct pipe_context *pipe, struct pipe_texture *texture) } -/** - * Called via pipe->get_tex_surface() - */ -static struct pipe_surface * -cell_get_tex_surface(struct pipe_context *pipe, - struct pipe_texture *pt, - unsigned face, unsigned level, unsigned zslice) -{ - return pipe->screen->get_tex_surface(pipe->screen, pt, face, level, zslice); -} - - static struct pipe_surface * cell_get_tex_surface_screen(struct pipe_screen *screen, struct pipe_texture *pt, @@ -294,10 +267,7 @@ cell_update_texture_mapping(struct cell_context *cell) void cell_init_texture_functions(struct cell_context *cell) { - cell->pipe.texture_create = cell_texture_create; - cell->pipe.texture_release = cell_texture_release; cell->pipe.texture_update = cell_texture_update; - cell->pipe.get_tex_surface = cell_get_tex_surface; } void diff --git a/src/gallium/drivers/failover/fo_context.c b/src/gallium/drivers/failover/fo_context.c index f559cc0d47..afc0d7eb1e 100644 --- a/src/gallium/drivers/failover/fo_context.c +++ b/src/gallium/drivers/failover/fo_context.c @@ -143,10 +143,12 @@ struct pipe_context *failover_create( struct pipe_context *hw, failover->pipe.surface_copy = hw->surface_copy; failover->pipe.surface_fill = hw->surface_fill; +#if 0 failover->pipe.texture_create = hw->texture_create; failover->pipe.texture_release = hw->texture_release; - failover->pipe.texture_update = hw->texture_update; failover->pipe.get_tex_surface = hw->get_tex_surface; +#endif + failover->pipe.texture_update = hw->texture_update; failover->pipe.flush = hw->flush; diff --git a/src/gallium/drivers/i915simple/i915_texture.c b/src/gallium/drivers/i915simple/i915_texture.c index 3c9509dee3..9cdf3418a9 100644 --- a/src/gallium/drivers/i915simple/i915_texture.c +++ b/src/gallium/drivers/i915simple/i915_texture.c @@ -511,14 +511,6 @@ i915_texture_create_screen(struct pipe_screen *screen, } -static struct pipe_texture * -i915_texture_create(struct pipe_context *pipe, - const struct pipe_texture *templat) -{ - return pipe->screen->texture_create(pipe->screen, templat); -} - - static void i915_texture_release_screen(struct pipe_screen *screen, struct pipe_texture **pt) @@ -550,13 +542,6 @@ i915_texture_release_screen(struct pipe_screen *screen, } -static void -i915_texture_release(struct pipe_context *pipe, struct pipe_texture **pt) -{ - i915_texture_release_screen(pipe->screen, pt); -} - - static void i915_texture_update(struct pipe_context *pipe, struct pipe_texture *texture) { @@ -606,26 +591,13 @@ i915_get_tex_surface_screen(struct pipe_screen *screen, } -static struct pipe_surface * -i915_get_tex_surface(struct pipe_context *pipe, - struct pipe_texture *pt, - unsigned face, unsigned level, unsigned zslice) -{ - return i915_get_tex_surface_screen(pipe->screen, pt, face, level, zslice); -} - - void i915_init_texture_functions(struct i915_context *i915) { - i915->pipe.texture_create = i915_texture_create; - i915->pipe.texture_release = i915_texture_release; i915->pipe.texture_update = i915_texture_update; - i915->pipe.get_tex_surface = i915_get_tex_surface; } - void i915_init_screen_texture_functions(struct pipe_screen *screen) { diff --git a/src/gallium/drivers/i965simple/brw_tex_layout.c b/src/gallium/drivers/i965simple/brw_tex_layout.c index 9753c50143..b24ac87c37 100644 --- a/src/gallium/drivers/i965simple/brw_tex_layout.c +++ b/src/gallium/drivers/i965simple/brw_tex_layout.c @@ -298,14 +298,6 @@ static boolean brw_miptree_layout(struct brw_texture *tex) } -static struct pipe_texture * -brw_texture_create(struct pipe_context *pipe, - const struct pipe_texture *templat) -{ - return pipe->screen->texture_create(pipe->screen, templat); -} - - static struct pipe_texture * brw_texture_create_screen(struct pipe_screen *screen, const struct pipe_texture *templat) @@ -333,13 +325,6 @@ brw_texture_create_screen(struct pipe_screen *screen, } -static void -brw_texture_release(struct pipe_context *pipe, struct pipe_texture **pt) -{ - pipe->screen->texture_release(pipe->screen, pt); -} - - static void brw_texture_release_screen(struct pipe_screen *screen, struct pipe_texture **pt) @@ -379,18 +364,6 @@ brw_texture_update(struct pipe_context *pipe, struct pipe_texture *texture) } -/* - * XXX note: same as code in sp_surface.c - */ -static struct pipe_surface * -brw_get_tex_surface(struct pipe_context *pipe, - struct pipe_texture *pt, - unsigned face, unsigned level, unsigned zslice) -{ - return pipe->screen->get_tex_surface(pipe->screen, pt, face, level, zslice); -} - - static struct pipe_surface * brw_get_tex_surface_screen(struct pipe_screen *screen, struct pipe_texture *pt, @@ -433,10 +406,7 @@ brw_get_tex_surface_screen(struct pipe_screen *screen, void brw_init_texture_functions(struct brw_context *brw) { - brw->pipe.texture_create = brw_texture_create; - brw->pipe.texture_release = brw_texture_release; brw->pipe.texture_update = brw_texture_update; - brw->pipe.get_tex_surface = brw_get_tex_surface; } diff --git a/src/gallium/drivers/softpipe/sp_texture.c b/src/gallium/drivers/softpipe/sp_texture.c index f0e8350a4a..7c02765313 100644 --- a/src/gallium/drivers/softpipe/sp_texture.c +++ b/src/gallium/drivers/softpipe/sp_texture.c @@ -80,15 +80,6 @@ softpipe_texture_layout(struct softpipe_texture * spt) } -/* XXX temporary */ -static struct pipe_texture * -softpipe_texture_create(struct pipe_context *pipe, - const struct pipe_texture *templat) -{ - return pipe->screen->texture_create(pipe->screen, templat); -} - - static struct pipe_texture * softpipe_texture_create_screen(struct pipe_screen *screen, const struct pipe_texture *templat) @@ -119,14 +110,6 @@ softpipe_texture_create_screen(struct pipe_screen *screen, } -/* XXX temporary */ -static void -softpipe_texture_release(struct pipe_context *pipe, struct pipe_texture **pt) -{ - return pipe->screen->texture_release(pipe->screen, pt); -} - - static void softpipe_texture_release_screen(struct pipe_screen *screen, struct pipe_texture **pt) @@ -153,33 +136,6 @@ softpipe_texture_release_screen(struct pipe_screen *screen, } -static void -softpipe_texture_update(struct pipe_context *pipe, - struct pipe_texture *texture) -{ - struct softpipe_context *softpipe = softpipe_context(pipe); - uint unit; - for (unit = 0; unit < PIPE_MAX_SAMPLERS; unit++) { - if (softpipe->texture[unit] == texture) { - sp_flush_tile_cache(softpipe, softpipe->tex_cache[unit]); - } - } -} - - -/** - * Called via pipe->get_tex_surface() - */ -/* XXX temporary */ -static struct pipe_surface * -softpipe_get_tex_surface(struct pipe_context *pipe, - struct pipe_texture *pt, - unsigned face, unsigned level, unsigned zslice) -{ - return pipe->screen->get_tex_surface(pipe->screen, pt, face, level, zslice); -} - - static struct pipe_surface * softpipe_get_tex_surface_screen(struct pipe_screen *screen, struct pipe_texture *pt, @@ -217,14 +173,24 @@ softpipe_get_tex_surface_screen(struct pipe_screen *screen, } +static void +softpipe_texture_update(struct pipe_context *pipe, + struct pipe_texture *texture) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + uint unit; + for (unit = 0; unit < PIPE_MAX_SAMPLERS; unit++) { + if (softpipe->texture[unit] == texture) { + sp_flush_tile_cache(softpipe, softpipe->tex_cache[unit]); + } + } +} + void softpipe_init_texture_funcs( struct softpipe_context *softpipe ) { - softpipe->pipe.texture_create = softpipe_texture_create; - softpipe->pipe.texture_release = softpipe_texture_release; softpipe->pipe.texture_update = softpipe_texture_update; - softpipe->pipe.get_tex_surface = softpipe_get_tex_surface; } diff --git a/src/gallium/drivers/softpipe/sp_tile_cache.c b/src/gallium/drivers/softpipe/sp_tile_cache.c index 0ff93c5527..4caf2dd3fc 100644 --- a/src/gallium/drivers/softpipe/sp_tile_cache.c +++ b/src/gallium/drivers/softpipe/sp_tile_cache.c @@ -489,6 +489,7 @@ sp_get_cached_tile_tex(struct pipe_context *pipe, struct softpipe_tile_cache *tc, int x, int y, int z, int face, int level) { + struct pipe_screen *screen = pipe->screen; /* tile pos in framebuffer: */ const int tile_x = x & ~(TILE_SIZE - 1); const int tile_y = y & ~(TILE_SIZE - 1); @@ -514,7 +515,7 @@ sp_get_cached_tile_tex(struct pipe_context *pipe, if (tc->tex_surf_map) pipe_surface_unmap(tc->tex_surf); - tc->tex_surf = pipe->get_tex_surface(pipe, tc->texture, face, level, z); + tc->tex_surf = screen->get_tex_surface(screen, tc->texture, face, level, z); tc->tex_surf_map = pipe_surface_map(tc->tex_surf); tc->tex_face = face; diff --git a/src/gallium/include/pipe/p_context.h b/src/gallium/include/pipe/p_context.h index bb345df153..d0f25d7d46 100644 --- a/src/gallium/include/pipe/p_context.h +++ b/src/gallium/include/pipe/p_context.h @@ -189,30 +189,16 @@ struct pipe_context { struct pipe_surface *ps, unsigned clearValue); - - /* - * Texture functions - * XXX these are moving to pipe_screen... - */ - struct pipe_texture * (*texture_create)(struct pipe_context *pipe, - const struct pipe_texture *templat); - - void (*texture_release)(struct pipe_context *pipe, - struct pipe_texture **pt); - /** * Called when texture data is changed. * Note: we could pass some hints about which mip levels or cube faces * have changed... + * XXX this may go away - could pass a 'write' flag to get_tex_surface() */ void (*texture_update)(struct pipe_context *pipe, struct pipe_texture *texture); - /** Get a surface which is a "view" into a texture */ - struct pipe_surface *(*get_tex_surface)(struct pipe_context *pipe, - struct pipe_texture *texture, - unsigned face, unsigned level, - unsigned zslice); + /* Flush rendering: */ diff --git a/src/gallium/include/pipe/p_inlines.h b/src/gallium/include/pipe/p_inlines.h index a7e97fcd7d..274f76a383 100644 --- a/src/gallium/include/pipe/p_inlines.h +++ b/src/gallium/include/pipe/p_inlines.h @@ -107,15 +107,9 @@ pipe_texture_reference(struct pipe_texture **ptr, pt->refcount++; if (*ptr) { - struct pipe_context *pipe = (*ptr)->pipe; - /* XXX temporary mess here */ - if (pipe) { - pipe->texture_release(pipe, ptr); - } - else { - struct pipe_screen *screen = (*ptr)->screen; - screen->texture_release(screen, ptr); - } + struct pipe_screen *screen = (*ptr)->screen; + assert(screen); + screen->texture_release(screen, ptr); assert(!*ptr); } @@ -127,10 +121,10 @@ pipe_texture_reference(struct pipe_texture **ptr, static INLINE void pipe_texture_release(struct pipe_texture **ptr) { - struct pipe_context *pipe; + struct pipe_screen *screen; assert(ptr); - pipe = (*ptr)->pipe; - pipe->texture_release(pipe, ptr); + screen = (*ptr)->screen; + screen->texture_release(screen, ptr); *ptr = NULL; } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 0f2c6307dd..ff236adc5c 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -456,6 +456,7 @@ make_texture(struct st_context *st, { GLcontext *ctx = st->ctx; struct pipe_context *pipe = st->pipe; + struct pipe_screen *screen = pipe->screen; const struct gl_texture_format *mformat; struct pipe_texture *pt; enum pipe_format pipeFormat; @@ -493,7 +494,7 @@ make_texture(struct st_context *st, /* we'll do pixel transfer in a fragment shader */ ctx->_ImageTransferState = 0x0; - surface = pipe->get_tex_surface(pipe, pt, 0, 0, 0); + surface = screen->get_tex_surface(screen, pt, 0, 0, 0); /* map texture surface */ dest = pipe_surface_map(surface); @@ -1031,7 +1032,7 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, printf("st_Bitmap (sourcing from PBO not implemented yet)\n"); } - surface = pipe->get_tex_surface(pipe, pt, 0, 0, 0); + surface = screen->get_tex_surface(screen, pt, 0, 0, 0); /* map texture surface */ dest = pipe_surface_map(surface); @@ -1207,6 +1208,7 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, { struct st_context *st = ctx->st; struct pipe_context *pipe = st->pipe; + struct pipe_screen *screen = pipe->screen; struct st_renderbuffer *rbRead; struct st_vertex_program *stvp; struct st_fragment_program *stfp; @@ -1248,7 +1250,7 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, if (!pt) return; - psTex = pipe->get_tex_surface(pipe, pt, 0, 0, 0); + psTex = screen->get_tex_surface(screen, pt, 0, 0, 0); if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) { srcy = ctx->DrawBuffer->Height - srcy - height; diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 781425b546..5384252a8e 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -307,6 +307,7 @@ st_render_texture(GLcontext *ctx, struct st_renderbuffer *strb; struct gl_renderbuffer *rb; struct pipe_context *pipe = st->pipe; + struct pipe_screen *screen = pipe->screen; struct pipe_texture *pt; assert(!att->Renderbuffer); @@ -332,10 +333,10 @@ st_render_texture(GLcontext *ctx, rb->Height = pt->height[att->TextureLevel]; /* the renderbuffer's surface is inside the texture */ - strb->surface = pipe->get_tex_surface(pipe, pt, - att->CubeMapFace, - att->TextureLevel, - att->Zoffset); + strb->surface = screen->get_tex_surface(screen, pt, + att->CubeMapFace, + att->TextureLevel, + att->Zoffset); assert(strb->surface); init_renderbuffer_bits(strb, pt->format); diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index f5f956f6ea..1ba3173312 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -144,12 +144,11 @@ st_NewTextureObject(GLcontext * ctx, GLuint name, GLenum target) static void st_DeleteTextureObject(GLcontext *ctx, - struct gl_texture_object *texObj) + struct gl_texture_object *texObj) { struct st_texture_object *stObj = st_texture_object(texObj); - if (stObj->pt) - ctx->st->pipe->texture_release(ctx->st->pipe, &stObj->pt); + pipe_texture_release(&stObj->pt); _mesa_delete_texture_object(ctx, texObj); } @@ -163,7 +162,7 @@ st_FreeTextureImageData(GLcontext * ctx, struct gl_texture_image *texImage) DBG("%s\n", __FUNCTION__); if (stImage->pt) { - ctx->st->pipe->texture_release(ctx->st->pipe, &stImage->pt); + pipe_texture_release(&stImage->pt); } if (texImage->Data) { @@ -537,7 +536,7 @@ st_TexImage(GLcontext * ctx, * Release any old malloced memory. */ if (stImage->pt) { - ctx->st->pipe->texture_release(ctx->st->pipe, &stImage->pt); + pipe_texture_release(&stImage->pt); assert(!texImage->Data); } else if (texImage->Data) { @@ -556,7 +555,7 @@ st_TexImage(GLcontext * ctx, stImage->face, stImage->level)) { DBG("release it\n"); - ctx->st->pipe->texture_release(ctx->st->pipe, &stObj->pt); + pipe_texture_release(&stObj->pt); assert(!stObj->pt); } @@ -1025,6 +1024,7 @@ fallback_copy_texsubimage(GLcontext *ctx, GLsizei width, GLsizei height) { struct pipe_context *pipe = ctx->st->pipe; + struct pipe_screen *screen = pipe->screen; const uint face = texture_face(target); struct pipe_texture *pt = stImage->pt; struct pipe_surface *src_surf, *dest_surf; @@ -1042,8 +1042,7 @@ fallback_copy_texsubimage(GLcontext *ctx, src_surf = strb->surface; - dest_surf = pipe->get_tex_surface(pipe, pt, - face, level, destZ); + dest_surf = screen->get_tex_surface(screen, pt, face, level, destZ); /* buffer for one row */ data = (GLfloat *) malloc(width * 4 * sizeof(GLfloat)); @@ -1096,6 +1095,7 @@ do_copy_texsubimage(GLcontext *ctx, struct gl_framebuffer *fb = ctx->ReadBuffer; struct st_renderbuffer *strb; struct pipe_context *pipe = ctx->st->pipe; + struct pipe_screen *screen = pipe->screen; struct pipe_surface *dest_surface; uint dest_format, src_format; uint do_flip = FALSE; @@ -1126,8 +1126,8 @@ do_copy_texsubimage(GLcontext *ctx, src_format = strb->surface->format; dest_format = stImage->pt->format; - dest_surface = pipe->get_tex_surface(pipe, stImage->pt, stImage->face, - stImage->level, destZ); + dest_surface = screen->get_tex_surface(screen, stImage->pt, stImage->face, + stImage->level, destZ); if (src_format == dest_format && ctx->_ImageTransferState == 0x0 && @@ -1352,7 +1352,7 @@ copy_image_data_to_texture(struct st_context *st, stImage->face ); - st->pipe->texture_release(st->pipe, &stImage->pt); + pipe_texture_release(&stImage->pt); } else { assert(stImage->base.Data != NULL); @@ -1408,7 +1408,7 @@ st_finalize_texture(GLcontext *ctx, */ if (firstImage->base.Border) { if (stObj->pt) { - ctx->st->pipe->texture_release(ctx->st->pipe, &stObj->pt); + pipe_texture_release(&stObj->pt); } return GL_FALSE; } @@ -1424,7 +1424,7 @@ st_finalize_texture(GLcontext *ctx, firstImage->pt->last_level >= stObj->lastLevel) { if (stObj->pt) - ctx->st->pipe->texture_release(ctx->st->pipe, &stObj->pt); + pipe_texture_release(&stObj->pt); pipe_texture_reference(&stObj->pt, firstImage->pt); } @@ -1450,7 +1450,7 @@ st_finalize_texture(GLcontext *ctx, stObj->pt->depth[0] != firstImage->base.Depth || stObj->pt->cpp != cpp || stObj->pt->compressed != firstImage->base.IsCompressed)) { - ctx->st->pipe->texture_release(ctx->st->pipe, &stObj->pt); + pipe_texture_release(&stObj->pt); } diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c index 2b16310602..243dc0b1d0 100644 --- a/src/mesa/state_tracker/st_gen_mipmap.c +++ b/src/mesa/state_tracker/st_gen_mipmap.c @@ -276,7 +276,7 @@ st_render_mipmap(struct st_context *st, /* * Setup framebuffer / dest surface */ - fb.cbufs[0] = pipe->get_tex_surface(pipe, pt, face, dstLevel, zslice); + fb.cbufs[0] = screen->get_tex_surface(screen, pt, face, dstLevel, zslice); pipe->set_framebuffer_state(pipe, &fb); /* @@ -325,6 +325,7 @@ fallback_generate_mipmap(GLcontext *ctx, GLenum target, struct gl_texture_object *texObj) { struct pipe_context *pipe = ctx->st->pipe; + struct pipe_screen *screen = pipe->screen; struct pipe_winsys *ws = pipe->winsys; struct pipe_texture *pt = st_get_texobj_texture(texObj); const uint baseLevel = texObj->BaseLevel; @@ -345,8 +346,8 @@ fallback_generate_mipmap(GLcontext *ctx, GLenum target, const ubyte *srcData; ubyte *dstData; - srcSurf = pipe->get_tex_surface(pipe, pt, face, srcLevel, zslice); - dstSurf = pipe->get_tex_surface(pipe, pt, face, dstLevel, zslice); + srcSurf = screen->get_tex_surface(screen, pt, face, srcLevel, zslice); + dstSurf = screen->get_tex_surface(screen, pt, face, dstLevel, zslice); srcData = (ubyte *) ws->buffer_map(ws, srcSurf->buffer, PIPE_BUFFER_USAGE_CPU_READ) diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c index ad284170e4..c2b0aa8a4a 100644 --- a/src/mesa/state_tracker/st_texture.c +++ b/src/mesa/state_tracker/st_texture.c @@ -77,6 +77,7 @@ st_texture_create(struct st_context *st, GLuint compress_byte) { struct pipe_texture pt, *newtex; + struct pipe_screen *screen = st->pipe->screen; assert(target <= PIPE_TEXTURE_CUBE); @@ -96,7 +97,7 @@ st_texture_create(struct st_context *st, pt.compressed = compress_byte ? 1 : 0; pt.cpp = pt.compressed ? compress_byte : st_sizeof_format(format); - newtex = st->pipe->texture_create(st->pipe, &pt); + newtex = screen->texture_create(screen, &pt); assert(!newtex || newtex->refcount == 1); @@ -183,11 +184,12 @@ GLubyte * st_texture_image_map(struct st_context *st, struct st_texture_image *stImage, GLuint zoffset) { + struct pipe_screen *screen = st->pipe->screen; struct pipe_texture *pt = stImage->pt; DBG("%s \n", __FUNCTION__); - stImage->surface = st->pipe->get_tex_surface(st->pipe, pt, stImage->face, - stImage->level, zoffset); + stImage->surface = screen->get_tex_surface(screen, pt, stImage->face, + stImage->level, zoffset); return pipe_surface_map(stImage->surface); } @@ -239,6 +241,7 @@ st_texture_image_data(struct pipe_context *pipe, void *src, GLuint src_row_pitch, GLuint src_image_pitch) { + struct pipe_screen *screen = pipe->screen; GLuint depth = dst->depth[level]; GLuint i; GLuint height = 0; @@ -251,7 +254,7 @@ st_texture_image_data(struct pipe_context *pipe, if(dst->compressed) height /= 4; - dst_surface = pipe->get_tex_surface(pipe, dst, face, level, i); + dst_surface = screen->get_tex_surface(screen, dst, face, level, i); st_surface_data(pipe, dst_surface, 0, 0, /* dstx, dsty */ @@ -275,6 +278,7 @@ st_texture_image_copy(struct pipe_context *pipe, struct pipe_texture *src, GLuint face) { + struct pipe_screen *screen = pipe->screen; GLuint width = dst->width[dstLevel]; GLuint height = dst->height[dstLevel]; GLuint depth = dst->depth[dstLevel]; @@ -299,8 +303,8 @@ st_texture_image_copy(struct pipe_context *pipe, assert(src->width[srcLevel] == width); assert(src->height[srcLevel] == height); - dst_surface = pipe->get_tex_surface(pipe, dst, face, dstLevel, i); - src_surface = pipe->get_tex_surface(pipe, src, face, srcLevel, i); + dst_surface = screen->get_tex_surface(screen, dst, face, dstLevel, i); + src_surface = screen->get_tex_surface(screen, src, face, srcLevel, i); pipe->surface_copy(pipe, FALSE, -- cgit v1.2.3 From 4abe1eb980ed76d2b2d3383eaab520d0aa2ae6f4 Mon Sep 17 00:00:00 2001 From: Michel Dänzer Date: Wed, 26 Mar 2008 09:36:40 +0000 Subject: gallium: Change pipe->flush() interface to optionally return a fence. The cell driver still uses an internal CELL_FLUSH_WAIT flag, in the long run proper fencing should be implemented for it. --- src/gallium/auxiliary/util/u_gen_mipmap.c | 2 +- src/gallium/drivers/cell/ppu/cell_flush.c | 15 +++++++--- src/gallium/drivers/cell/ppu/cell_flush.h | 5 +++- src/gallium/drivers/cell/ppu/cell_vbuf.c | 2 +- src/gallium/drivers/cell/ppu/cell_vertex_shader.c | 2 +- src/gallium/drivers/failover/fo_context.c | 4 +-- src/gallium/drivers/i915simple/i915_batch.h | 4 +-- src/gallium/drivers/i915simple/i915_blit.c | 4 +-- src/gallium/drivers/i915simple/i915_flush.c | 14 +++------- src/gallium/drivers/i915simple/i915_prim_emit.c | 2 +- src/gallium/drivers/i915simple/i915_prim_vbuf.c | 2 +- src/gallium/drivers/i915simple/i915_state_emit.c | 2 +- src/gallium/drivers/i915simple/i915_winsys.h | 5 ++-- src/gallium/drivers/i965simple/brw_flush.c | 13 ++------- src/gallium/drivers/softpipe/sp_flush.c | 10 +++---- src/gallium/drivers/softpipe/sp_flush.h | 4 ++- src/gallium/include/pipe/p_context.h | 5 ++-- src/gallium/include/pipe/p_defines.h | 3 +- src/gallium/winsys/dri/intel/intel_context.c | 4 +-- src/gallium/winsys/dri/intel/intel_winsys_i915.c | 25 ++++++++++------- src/gallium/winsys/xlib/xm_winsys.c | 31 +++++++++++++++++++++ src/mesa/state_tracker/st_cb_accum.c | 2 +- src/mesa/state_tracker/st_cb_drawpixels.c | 4 +-- src/mesa/state_tracker/st_cb_fbo.c | 2 +- src/mesa/state_tracker/st_cb_flush.c | 34 +++++++++++++---------- src/mesa/state_tracker/st_cb_readpixels.c | 2 +- src/mesa/state_tracker/st_framebuffer.c | 3 +- src/mesa/state_tracker/st_public.h | 5 +++- 28 files changed, 127 insertions(+), 83 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c index e129c062be..ed12768e7f 100644 --- a/src/gallium/auxiliary/util/u_gen_mipmap.c +++ b/src/gallium/auxiliary/util/u_gen_mipmap.c @@ -935,7 +935,7 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, 4, /* verts */ 2); /* attribs/vert */ - pipe->flush(pipe, PIPE_FLUSH_WAIT); + pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); /* need to signal that the texture has changed _after_ rendering to it */ pipe->texture_update(pipe, pt, face, (1 << dstLevel)); diff --git a/src/gallium/drivers/cell/ppu/cell_flush.c b/src/gallium/drivers/cell/ppu/cell_flush.c index 66a5627d84..3aaf3de668 100644 --- a/src/gallium/drivers/cell/ppu/cell_flush.c +++ b/src/gallium/drivers/cell/ppu/cell_flush.c @@ -35,12 +35,19 @@ void -cell_flush(struct pipe_context *pipe, unsigned flags) +cell_flush(struct pipe_context *pipe, unsigned flags, + struct pipe_fence_handle **fence) { struct cell_context *cell = cell_context(pipe); + if (fence) { + *fence = NULL; + /* XXX: Implement real fencing */ + flags |= CELL_FLUSH_WAIT; + } + if (flags & PIPE_FLUSH_SWAPBUFFERS) - flags |= PIPE_FLUSH_WAIT; + flags |= CELL_FLUSH_WAIT; draw_flush( cell->draw ); cell_flush_int(pipe, flags); @@ -58,7 +65,7 @@ cell_flush_int(struct pipe_context *pipe, unsigned flags) ASSERT(!flushing); flushing = TRUE; - if (flags & PIPE_FLUSH_WAIT) { + if (flags & CELL_FLUSH_WAIT) { uint64_t *cmd = (uint64_t *) cell_batch_alloc(cell, sizeof(uint64_t)); *cmd = CELL_CMD_FINISH; } @@ -72,7 +79,7 @@ cell_flush_int(struct pipe_context *pipe, unsigned flags) } #endif - if (flags & PIPE_FLUSH_WAIT) { + if (flags & CELL_FLUSH_WAIT) { /* Wait for ack */ for (i = 0; i < cell->num_spus; i++) { uint k = wait_mbox_message(cell_global.spe_contexts[i]); diff --git a/src/gallium/drivers/cell/ppu/cell_flush.h b/src/gallium/drivers/cell/ppu/cell_flush.h index 7f940ae76b..8f0645c429 100644 --- a/src/gallium/drivers/cell/ppu/cell_flush.h +++ b/src/gallium/drivers/cell/ppu/cell_flush.h @@ -29,8 +29,11 @@ #ifndef CELL_FLUSH #define CELL_FLUSH +#define CELL_FLUSH_WAIT 0x80000000 + extern void -cell_flush(struct pipe_context *pipe, unsigned flags); +cell_flush(struct pipe_context *pipe, unsigned flags, + struct pipe_fence_handle **fence); extern void cell_flush_int(struct pipe_context *pipe, unsigned flags); diff --git a/src/gallium/drivers/cell/ppu/cell_vbuf.c b/src/gallium/drivers/cell/ppu/cell_vbuf.c index cc727ff4ed..3a181b585c 100644 --- a/src/gallium/drivers/cell/ppu/cell_vbuf.c +++ b/src/gallium/drivers/cell/ppu/cell_vbuf.c @@ -243,7 +243,7 @@ cell_vbuf_draw(struct vbuf_render *vbr, #if 0 /* helpful for debug */ - cell_flush_int(&cell->pipe, PIPE_FLUSH_WAIT); + cell_flush_int(&cell->pipe, CELL_FLUSH_WAIT); #endif } diff --git a/src/gallium/drivers/cell/ppu/cell_vertex_shader.c b/src/gallium/drivers/cell/ppu/cell_vertex_shader.c index f5c27852c1..b418857ccd 100644 --- a/src/gallium/drivers/cell/ppu/cell_vertex_shader.c +++ b/src/gallium/drivers/cell/ppu/cell_vertex_shader.c @@ -133,7 +133,7 @@ cell_vertex_shader_queue_flush(struct draw_context *draw) vs->num_elts = n; send_mbox_message(cell_global.spe_contexts[0], CELL_CMD_VS_EXECUTE); - cell_flush_int(& cell->pipe, PIPE_FLUSH_WAIT); + cell_flush_int(& cell->pipe, CELL_FLUSH_WAIT); } draw->vs.post_nr = draw->vs.queue_nr; diff --git a/src/gallium/drivers/failover/fo_context.c b/src/gallium/drivers/failover/fo_context.c index afc0d7eb1e..cb95ba516f 100644 --- a/src/gallium/drivers/failover/fo_context.c +++ b/src/gallium/drivers/failover/fo_context.c @@ -69,7 +69,7 @@ static boolean failover_draw_elements( struct pipe_context *pipe, start, count )) { - failover->hw->flush( failover->hw, ~0 ); + failover->hw->flush( failover->hw, ~0, NULL ); failover->mode = FO_SW; } } @@ -92,7 +92,7 @@ static boolean failover_draw_elements( struct pipe_context *pipe, * intervening flush. Unlikely to be much performance impact to * this: */ - failover->sw->flush( failover->sw, ~0 ); + failover->sw->flush( failover->sw, ~0, NULL ); } return TRUE; diff --git a/src/gallium/drivers/i915simple/i915_batch.h b/src/gallium/drivers/i915simple/i915_batch.h index fb88cd6db0..4ea06ce02b 100644 --- a/src/gallium/drivers/i915simple/i915_batch.h +++ b/src/gallium/drivers/i915simple/i915_batch.h @@ -44,9 +44,9 @@ #define ADVANCE_BATCH() -#define FLUSH_BATCH() do { \ +#define FLUSH_BATCH(fence) do { \ if (0) i915_dump_batchbuffer( i915 ); \ - i915->winsys->batch_flush( i915->winsys ); \ + i915->winsys->batch_flush( i915->winsys, fence ); \ i915->batch_start = NULL; \ i915->hardware_dirty = ~0; \ } while (0) diff --git a/src/gallium/drivers/i915simple/i915_blit.c b/src/gallium/drivers/i915simple/i915_blit.c index db4671ff55..24449e3fb3 100644 --- a/src/gallium/drivers/i915simple/i915_blit.c +++ b/src/gallium/drivers/i915simple/i915_blit.c @@ -70,7 +70,7 @@ i915_fill_blit(struct i915_context *i915, if (!BEGIN_BATCH(6, 1)) { - FLUSH_BATCH(); + FLUSH_BATCH(NULL); assert(BEGIN_BATCH(6, 1)); } OUT_BATCH(CMD); @@ -145,7 +145,7 @@ i915_copy_blit( struct i915_context *i915, if (!BEGIN_BATCH(8, 2)) { - FLUSH_BATCH(); + FLUSH_BATCH(NULL); assert(BEGIN_BATCH(8, 2)); } OUT_BATCH(CMD); diff --git a/src/gallium/drivers/i915simple/i915_flush.c b/src/gallium/drivers/i915simple/i915_flush.c index 96a54281f1..7d23e6b6b9 100644 --- a/src/gallium/drivers/i915simple/i915_flush.c +++ b/src/gallium/drivers/i915simple/i915_flush.c @@ -37,11 +37,9 @@ #include "i915_batch.h" -/** - * In future we may want a fence-like interface instead of finish. - */ static void i915_flush( struct pipe_context *pipe, - unsigned flags ) + unsigned flags, + struct pipe_fence_handle **fence ) { struct i915_context *i915 = i915_context(pipe); @@ -60,7 +58,7 @@ static void i915_flush( struct pipe_context *pipe, flush |= FLUSH_MAP_CACHE; if (!BEGIN_BATCH(1, 0)) { - FLUSH_BATCH(); + FLUSH_BATCH(NULL); assert(BEGIN_BATCH(1, 0)); } OUT_BATCH( flush ); @@ -69,11 +67,7 @@ static void i915_flush( struct pipe_context *pipe, /* If there are no flags, just flush pending commands to hardware: */ - FLUSH_BATCH(); - - if (flags & PIPE_FLUSH_WAIT) { - i915->winsys->batch_finish(i915->winsys); - } + FLUSH_BATCH(fence); } diff --git a/src/gallium/drivers/i915simple/i915_prim_emit.c b/src/gallium/drivers/i915simple/i915_prim_emit.c index d8de5178f6..b6fb0a6d88 100644 --- a/src/gallium/drivers/i915simple/i915_prim_emit.c +++ b/src/gallium/drivers/i915simple/i915_prim_emit.c @@ -140,7 +140,7 @@ emit_prim( struct draw_stage *stage, assert(vertex_size >= 12); /* never smaller than 12 bytes */ if (!BEGIN_BATCH( 1 + nr * vertex_size / 4, 0 )) { - FLUSH_BATCH(); + FLUSH_BATCH(NULL); /* Make sure state is re-emitted after a flush: */ diff --git a/src/gallium/drivers/i915simple/i915_prim_vbuf.c b/src/gallium/drivers/i915simple/i915_prim_vbuf.c index eb64f51943..7fb2adbb53 100644 --- a/src/gallium/drivers/i915simple/i915_prim_vbuf.c +++ b/src/gallium/drivers/i915simple/i915_prim_vbuf.c @@ -161,7 +161,7 @@ i915_vbuf_render_draw( struct vbuf_render *render, i915_emit_hardware_state( i915 ); if (!BEGIN_BATCH( 1 + (nr_indices + 1)/2, 1 )) { - FLUSH_BATCH(); + FLUSH_BATCH(NULL); /* Make sure state is re-emitted after a flush: */ diff --git a/src/gallium/drivers/i915simple/i915_state_emit.c b/src/gallium/drivers/i915simple/i915_state_emit.c index a7498d22b7..6f947d4346 100644 --- a/src/gallium/drivers/i915simple/i915_state_emit.c +++ b/src/gallium/drivers/i915simple/i915_state_emit.c @@ -115,7 +115,7 @@ i915_emit_hardware_state(struct i915_context *i915 ) #endif if(!BEGIN_BATCH(dwords, relocs)) { - FLUSH_BATCH(); + FLUSH_BATCH(NULL); assert(BEGIN_BATCH(dwords, relocs)); } diff --git a/src/gallium/drivers/i915simple/i915_winsys.h b/src/gallium/drivers/i915simple/i915_winsys.h index aea3003281..5e16543f4e 100644 --- a/src/gallium/drivers/i915simple/i915_winsys.h +++ b/src/gallium/drivers/i915simple/i915_winsys.h @@ -56,6 +56,7 @@ extern "C" { */ struct pipe_buffer; +struct pipe_fence_handle; struct pipe_winsys; struct pipe_screen; @@ -103,8 +104,8 @@ struct i915_winsys { unsigned access_flags, unsigned delta ); - void (*batch_flush)( struct i915_winsys *sws ); - void (*batch_finish)( struct i915_winsys *sws ); + void (*batch_flush)( struct i915_winsys *sws, + struct pipe_fence_handle **fence ); }; #define I915_BUFFER_ACCESS_WRITE 0x1 diff --git a/src/gallium/drivers/i965simple/brw_flush.c b/src/gallium/drivers/i965simple/brw_flush.c index 5216c680cf..e6001c30d9 100644 --- a/src/gallium/drivers/i965simple/brw_flush.c +++ b/src/gallium/drivers/i965simple/brw_flush.c @@ -36,14 +36,11 @@ #include "brw_batch.h" -/** - * In future we may want a fence-like interface instead of finish. - */ static void brw_flush( struct pipe_context *pipe, - unsigned flags ) + unsigned flags, + struct pipe_fence_handle **fence ) { struct brw_context *brw = brw_context(pipe); - struct pipe_fence_handle *fence; /* Do we need to emit an MI_FLUSH command to flush the hardware * caches? @@ -65,11 +62,7 @@ static void brw_flush( struct pipe_context *pipe, /* If there are no flags, just flush pending commands to hardware: */ - FLUSH_BATCH( &fence ); - - if (flags & PIPE_FLUSH_WAIT) { -// brw->winsys->wait_fence(brw->winsys, fence); - } + FLUSH_BATCH( fence ); } diff --git a/src/gallium/drivers/softpipe/sp_flush.c b/src/gallium/drivers/softpipe/sp_flush.c index 2cbd0d7cab..0625b69099 100644 --- a/src/gallium/drivers/softpipe/sp_flush.c +++ b/src/gallium/drivers/softpipe/sp_flush.c @@ -40,13 +40,10 @@ #include "sp_winsys.h" -/* There will be actual work to do here. In future we may want a - * fence-like interface instead of finish, and perhaps flush will take - * flags to indicate what type of flush is required. - */ void softpipe_flush( struct pipe_context *pipe, - unsigned flags ) + unsigned flags, + struct pipe_fence_handle **fence ) { struct softpipe_context *softpipe = softpipe_context(pipe); uint i; @@ -72,5 +69,8 @@ softpipe_flush( struct pipe_context *pipe, * to unmap surfaces when flushing. */ softpipe_unmap_surfaces(softpipe); + + if (fence) + *fence = NULL; } diff --git a/src/gallium/drivers/softpipe/sp_flush.h b/src/gallium/drivers/softpipe/sp_flush.h index 34ec617866..68d9b5fa83 100644 --- a/src/gallium/drivers/softpipe/sp_flush.h +++ b/src/gallium/drivers/softpipe/sp_flush.h @@ -29,7 +29,9 @@ #define SP_FLUSH_H struct pipe_context; +struct pipe_fence_handle; -void softpipe_flush(struct pipe_context *pipe, unsigned flags ); +void softpipe_flush(struct pipe_context *pipe, unsigned flags, + struct pipe_fence_handle **fence); #endif diff --git a/src/gallium/include/pipe/p_context.h b/src/gallium/include/pipe/p_context.h index a3824601be..b2e49bef4c 100644 --- a/src/gallium/include/pipe/p_context.h +++ b/src/gallium/include/pipe/p_context.h @@ -37,7 +37,7 @@ extern "C" { struct pipe_screen; - +struct pipe_fence_handle; struct pipe_state_cache; /* Opaque driver handles: @@ -202,7 +202,8 @@ struct pipe_context { /* Flush rendering: */ void (*flush)( struct pipe_context *pipe, - unsigned flags ); + unsigned flags, + struct pipe_fence_handle **fence ); }; diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h index bc938ba253..586951d956 100644 --- a/src/gallium/include/pipe/p_defines.h +++ b/src/gallium/include/pipe/p_defines.h @@ -201,8 +201,7 @@ enum pipe_texture_target { */ #define PIPE_FLUSH_RENDER_CACHE 0x1 #define PIPE_FLUSH_TEXTURE_CACHE 0x2 -#define PIPE_FLUSH_WAIT 0x4 -#define PIPE_FLUSH_SWAPBUFFERS 0x8 +#define PIPE_FLUSH_SWAPBUFFERS 0x4 /** diff --git a/src/gallium/winsys/dri/intel/intel_context.c b/src/gallium/winsys/dri/intel/intel_context.c index 79b320c6bf..8eba33c313 100644 --- a/src/gallium/winsys/dri/intel/intel_context.c +++ b/src/gallium/winsys/dri/intel/intel_context.c @@ -228,7 +228,7 @@ intelDestroyContext(__DRIcontextPrivate * driContextPriv) assert(intel); /* should never be null */ if (intel) { - st_flush(intel->st, PIPE_FLUSH_WAIT); + st_finish(intel->st); intel_batchbuffer_free(intel->batch); @@ -256,7 +256,7 @@ GLboolean intelUnbindContext(__DRIcontextPrivate * driContextPriv) { struct intel_context *intel = intel_context(driContextPriv); - st_flush(intel->st, 0x0); + st_flush(intel->st, PIPE_FLUSH_RENDER_CACHE, NULL); /* XXX make_current(NULL)? */ return GL_TRUE; } diff --git a/src/gallium/winsys/dri/intel/intel_winsys_i915.c b/src/gallium/winsys/dri/intel/intel_winsys_i915.c index 2def1afc31..4d183db7c3 100644 --- a/src/gallium/winsys/dri/intel/intel_winsys_i915.c +++ b/src/gallium/winsys/dri/intel/intel_winsys_i915.c @@ -39,12 +39,14 @@ #include "intel_winsys.h" #include "pipe/p_util.h" +#include "pipe/p_winsys.h" #include "i915simple/i915_winsys.h" #include "i915simple/i915_screen.h" struct intel_i915_winsys { struct i915_winsys winsys; /**< batch buffer funcs */ + struct pipe_winsys *pws; struct intel_context *intel; }; @@ -112,19 +114,22 @@ static void intel_i915_batch_reloc( struct i915_winsys *sws, -static void intel_i915_batch_flush( struct i915_winsys *sws ) +static void intel_i915_batch_flush( struct i915_winsys *sws, + struct pipe_fence_handle **fence ) { - struct intel_context *intel = intel_i915_winsys(sws)->intel; + struct intel_i915_winsys *iws = intel_i915_winsys(sws); + struct intel_context *intel = iws->intel; + union { + struct _DriFenceObject *dri; + struct pipe_fence_handle *pipe; + } fu; - intel_batchbuffer_flush( intel->batch ); -// if (0) intel_i915_batch_wait_idle( sws ); -} + fu.dri = intel_batchbuffer_flush( intel->batch ); + if (fu.dri) + iws->pws->fence_reference(iws->pws, fence, fu.pipe); -static void intel_i915_batch_finish( struct i915_winsys *sws ) -{ - struct intel_context *intel = intel_i915_winsys(sws)->intel; - intel_batchbuffer_finish( intel->batch ); +// if (0) intel_i915_batch_wait_idle( sws ); } @@ -145,7 +150,7 @@ intel_create_i915simple( struct intel_context *intel, iws->winsys.batch_dword = intel_i915_batch_dword; iws->winsys.batch_reloc = intel_i915_batch_reloc; iws->winsys.batch_flush = intel_i915_batch_flush; - iws->winsys.batch_finish = intel_i915_batch_finish; + iws->pws = winsys; iws->intel = intel; screen = i915_create_screen(winsys, intel->intelScreen->deviceID); diff --git a/src/gallium/winsys/xlib/xm_winsys.c b/src/gallium/winsys/xlib/xm_winsys.c index 7baaae295c..c930a1d196 100644 --- a/src/gallium/winsys/xlib/xm_winsys.c +++ b/src/gallium/winsys/xlib/xm_winsys.c @@ -570,6 +570,33 @@ xm_surface_release(struct pipe_winsys *winsys, struct pipe_surface **s) } +/* + * Fence functions - basically nothing to do, as we don't create any actual + * fence objects. + */ + +static void +xm_fence_reference(struct pipe_winsys *sws, struct pipe_fence_handle **ptr, + struct pipe_fence_handle *fence) +{ +} + + +static int +xm_fence_signalled(struct pipe_winsys *sws, struct pipe_fence_handle *fence, + unsigned flag) +{ + return 0; +} + + +static int +xm_fence_finish(struct pipe_winsys *sws, struct pipe_fence_handle *fence, + unsigned flag) +{ + return 0; +} + /** * Return pointer to a pipe_winsys object. @@ -603,6 +630,10 @@ xmesa_get_pipe_winsys_aub(struct xmesa_visual *xm_vis) ws->base.surface_alloc_storage = xm_surface_alloc_storage; ws->base.surface_release = xm_surface_release; + ws->fence_reference = xm_fence_reference; + ws->fence_signalled = xm_fence_signalled; + ws->fence_finish = xm_fence_finish; + ws->base.flush_frontbuffer = xm_flush_frontbuffer; ws->base.printf = xm_printf; ws->base.get_name = xm_get_name; diff --git a/src/mesa/state_tracker/st_cb_accum.c b/src/mesa/state_tracker/st_cb_accum.c index f1fddc4e02..a623d0bcc0 100644 --- a/src/mesa/state_tracker/st_cb_accum.c +++ b/src/mesa/state_tracker/st_cb_accum.c @@ -214,7 +214,7 @@ st_Accum(GLcontext *ctx, GLenum op, GLfloat value) const GLint height = ctx->DrawBuffer->_Ymax - ypos; /* make sure color bufs aren't cached */ - pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE); + pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); switch (op) { case GL_ADD: diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 026f015fd8..43cc21d1fb 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -737,7 +737,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, GLint skipPixels; ubyte *stmap; - pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE); + pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); /* map the stencil buffer */ stmap = pipe_surface_map(ps); @@ -952,7 +952,7 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, enum pipe_format srcFormat, texFormat; /* make sure rendering has completed */ - pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE); + pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); st_validate_state(st); diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 5384252a8e..ec7788923a 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -366,7 +366,7 @@ st_finish_render_texture(GLcontext *ctx, assert(strb); - ctx->st->pipe->flush(ctx->st->pipe, PIPE_FLUSH_RENDER_CACHE); + ctx->st->pipe->flush(ctx->st->pipe, PIPE_FLUSH_RENDER_CACHE, NULL); /* printf("FINISH RENDER TO TEXTURE surf=%p\n", strb->surface); diff --git a/src/mesa/state_tracker/st_cb_flush.c b/src/mesa/state_tracker/st_cb_flush.c index dbec993f1b..a536a059bd 100644 --- a/src/mesa/state_tracker/st_cb_flush.c +++ b/src/mesa/state_tracker/st_cb_flush.c @@ -43,19 +43,21 @@ #include "pipe/p_winsys.h" -void st_flush( struct st_context *st, uint pipeFlushFlags ) +void st_flush( struct st_context *st, uint pipeFlushFlags, + struct pipe_fence_handle **fence ) { FLUSH_VERTICES(st->ctx, 0); - st->pipe->flush( st->pipe, pipeFlushFlags ); + st->pipe->flush( st->pipe, pipeFlushFlags, fence ); } -static void st_gl_flush( struct st_context *st, uint pipeFlushFlags ) +static void st_gl_flush( struct st_context *st, uint pipeFlushFlags, + struct pipe_fence_handle **fence ) { GLframebuffer *fb = st->ctx->DrawBuffer; - FLUSH_VERTICES(st->ctx, 0); + st_flush( st, pipeFlushFlags, fence ); if (!fb) return; @@ -80,15 +82,6 @@ static void st_gl_flush( struct st_context *st, uint pipeFlushFlags ) = st_renderbuffer(fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer); struct pipe_surface *front_surf = strb->surface; - /* If we aren't rendering to the frontbuffer, this is a noop. - * This should be uncontroversial for glFlush, though people may - * feel more strongly about glFinish. - * - * Additionally, need to make sure that the frontbuffer_dirty - * flag really gets set on frontbuffer rendering. - */ - st->pipe->flush( st->pipe, pipeFlushFlags ); - /* Hook for copying "fake" frontbuffer if necessary: */ st->pipe->winsys->flush_frontbuffer( st->pipe->winsys, front_surf, @@ -103,7 +96,18 @@ static void st_gl_flush( struct st_context *st, uint pipeFlushFlags ) */ static void st_glFlush(GLcontext *ctx) { - st_gl_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE); + st_gl_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); +} + + +void st_finish( struct st_context *st ) +{ + struct pipe_fence_handle *fence; + + st_gl_flush(st, PIPE_FLUSH_RENDER_CACHE, &fence); + + st->pipe->winsys->fence_finish(st->pipe->winsys, fence, 0); + st->pipe->winsys->fence_reference(st->pipe->winsys, &fence, NULL); } @@ -112,7 +116,7 @@ static void st_glFlush(GLcontext *ctx) */ static void st_glFinish(GLcontext *ctx) { - st_gl_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_WAIT); + st_finish( ctx->st ); } diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c index 4cf9adcd28..e9fcdf69a1 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -160,7 +160,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, return; /* make sure rendering has completed */ - pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE); + pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); if (format == GL_STENCIL_INDEX) { st_read_stencil_pixels(ctx, x, y, width, height, type, pack, dest); diff --git a/src/mesa/state_tracker/st_framebuffer.c b/src/mesa/state_tracker/st_framebuffer.c index d46a9178b1..075e9d1bd6 100644 --- a/src/mesa/state_tracker/st_framebuffer.c +++ b/src/mesa/state_tracker/st_framebuffer.c @@ -186,7 +186,8 @@ st_notify_swapbuffers(struct st_framebuffer *stfb) if (ctx && ctx->DrawBuffer == &stfb->Base) { st_flush( ctx->st, - PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_SWAPBUFFERS); + PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_SWAPBUFFERS, + NULL ); } } diff --git a/src/mesa/state_tracker/st_public.h b/src/mesa/state_tracker/st_public.h index 3c397b126a..9d88ce9764 100644 --- a/src/mesa/state_tracker/st_public.h +++ b/src/mesa/state_tracker/st_public.h @@ -45,6 +45,7 @@ struct st_context; struct st_framebuffer; struct pipe_context; +struct pipe_fence_handle; struct pipe_surface; @@ -78,7 +79,9 @@ void st_make_current(struct st_context *st, struct st_framebuffer *draw, struct st_framebuffer *read); -void st_flush( struct st_context *st, uint pipeFlushFlags ); +void st_flush( struct st_context *st, uint pipeFlushFlags, + struct pipe_fence_handle **fence ); +void st_finish( struct st_context *st ); void st_notify_swapbuffers(struct st_framebuffer *stfb); void st_notify_swapbuffers_complete(struct st_framebuffer *stfb); -- cgit v1.2.3 From 2b2d0e05842691e715782a64845aeca12a428427 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 7 Apr 2008 13:50:02 -0600 Subject: gallium: clean-up in st_renderbuffer_alloc_storage() --- src/mesa/state_tracker/st_cb_fbo.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index ec7788923a..e55281a430 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -80,6 +80,8 @@ init_renderbuffer_bits(struct st_renderbuffer *strb, /** * gl_renderbuffer::AllocStorage() + * This is called to allocate the original drawing surface, and + * during window resize. */ static GLboolean st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, @@ -90,8 +92,10 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, struct st_renderbuffer *strb = st_renderbuffer(rb); enum pipe_format pipeFormat; GLbitfield flags = 0x0; /* XXX needed? */ + int ret; if (!strb->surface) { + /* first time surface creation */ strb->surface = pipe->winsys->surface_alloc(pipe->winsys); assert(strb->surface); assert(strb->surface->refcount); @@ -99,10 +103,10 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, if (!strb->surface) return GL_FALSE; } - - if (strb->surface->buffer) - pipe_buffer_reference(pipe->winsys, &strb->surface->buffer, - NULL); + else if (strb->surface->buffer) { + /* release/discard the old surface buffer */ + pipe_buffer_reference(pipe->winsys, &strb->surface->buffer, NULL); + } /* Determine surface format here */ if (strb->format != PIPE_FORMAT_NONE) { @@ -116,14 +120,15 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, init_renderbuffer_bits(strb, pipeFormat); - pipe->winsys->surface_alloc_storage(pipe->winsys, - strb->surface, - width, - height, - pipeFormat, - flags); - if (!strb->surface->buffer) + ret = pipe->winsys->surface_alloc_storage(pipe->winsys, + strb->surface, + width, + height, + pipeFormat, + flags); + if (ret || !strb->surface->buffer) { return GL_FALSE; /* out of memory, try s/w buffer? */ + } ASSERT(strb->surface->buffer); ASSERT(strb->surface->format); -- cgit v1.2.3 From 0dd596fbc7f88b88467529a7f176aca70d70f731 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 7 Apr 2008 14:53:49 -0600 Subject: gallium: accum buffer fixes If the driver can't create a PIPE_FORMAT_R16G16B16A16_SNORM surface, create an accum surface using a shallower format and taller height. Since only the accum buffer code accesses the surface the actual format doesn't really matter, just that there's enough memory. --- src/mesa/state_tracker/st_cb_accum.c | 61 +++++++++++++++++++++++++++++---- src/mesa/state_tracker/st_cb_fbo.c | 29 ++++++++++++++-- src/mesa/state_tracker/st_cb_fbo.h | 3 ++ src/mesa/state_tracker/st_framebuffer.c | 2 +- 4 files changed, 84 insertions(+), 11 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_accum.c b/src/mesa/state_tracker/st_cb_accum.c index a623d0bcc0..35352351d5 100644 --- a/src/mesa/state_tracker/st_cb_accum.c +++ b/src/mesa/state_tracker/st_cb_accum.c @@ -56,6 +56,51 @@ */ +/** + * Wrapper for pipe_get_tile_rgba(). Do format/cpp override to make the + * tile util function think the surface is 16bit/channel, even if it's not. + * See also: st_renderbuffer_alloc_storage() + */ +static void +acc_get_tile_rgba(struct pipe_context *pipe, struct pipe_surface *acc_ps, + uint x, uint y, uint w, uint h, float *p) +{ + const enum pipe_format f = acc_ps->format; + const int cpp = acc_ps->cpp; + + acc_ps->format = DEFAULT_ACCUM_PIPE_FORMAT; + acc_ps->cpp = 8; + + pipe_get_tile_rgba(pipe, acc_ps, x, y, w, h, p); + + acc_ps->format = f; + acc_ps->cpp = cpp; +} + + +/** + * Wrapper for pipe_put_tile_rgba(). Do format/cpp override to make the + * tile util function think the surface is 16bit/channel, even if it's not. + * See also: st_renderbuffer_alloc_storage() + */ +static void +acc_put_tile_rgba(struct pipe_context *pipe, struct pipe_surface *acc_ps, + uint x, uint y, uint w, uint h, const float *p) +{ + enum pipe_format f = acc_ps->format; + const int cpp = acc_ps->cpp; + + acc_ps->format = DEFAULT_ACCUM_PIPE_FORMAT; + acc_ps->cpp = 8; + + pipe_put_tile_rgba(pipe, acc_ps, x, y, w, h, p); + + acc_ps->format = f; + acc_ps->cpp = cpp; +} + + + void st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { @@ -80,7 +125,9 @@ st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) accBuf[i*4+3] = a; } - pipe_put_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf); + acc_put_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf); + + free(accBuf); } @@ -95,13 +142,13 @@ accum_mad(struct pipe_context *pipe, GLfloat scale, GLfloat bias, accBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - pipe_get_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf); + acc_get_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf); for (i = 0; i < 4 * width * height; i++) { accBuf[i] = accBuf[i] * scale + bias; } - pipe_put_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf); + acc_put_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf); free(accBuf); } @@ -120,13 +167,13 @@ accum_accum(struct pipe_context *pipe, GLfloat value, accBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); pipe_get_tile_rgba(pipe, color_ps, xpos, ypos, width, height, colorBuf); - pipe_get_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf); + acc_get_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf); for (i = 0; i < 4 * width * height; i++) { accBuf[i] = accBuf[i] + colorBuf[i] * value; } - pipe_put_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf); + acc_put_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf); free(colorBuf); free(accBuf); @@ -150,7 +197,7 @@ accum_load(struct pipe_context *pipe, GLfloat value, buf[i] = buf[i] * value; } - pipe_put_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, buf); + acc_put_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, buf); free(buf); } @@ -169,7 +216,7 @@ accum_return(GLcontext *ctx, GLfloat value, abuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - pipe_get_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, abuf); + acc_get_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, abuf); if (!colormask[0] || !colormask[1] || !colormask[2] || !colormask[3]) { cbuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index e55281a430..b1a56f3ca6 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -127,14 +127,37 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, pipeFormat, flags); if (ret || !strb->surface->buffer) { - return GL_FALSE; /* out of memory, try s/w buffer? */ + if (pipeFormat == DEFAULT_ACCUM_PIPE_FORMAT) { + /* Accum buffer. Try a different surface format. Since accum + * buffers are s/w only for now, the surface pixel format doesn't + * really matter, only that the buffer is large enough. + */ + int sz, mult; + enum pipe_format accum_format; + + /* allocate a buffer of (typically) double height to get 64bpp */ + accum_format = st_choose_renderbuffer_format(pipe, GL_RGBA); + sz = pf_get_size(accum_format); + mult = pf_get_size(DEFAULT_ACCUM_PIPE_FORMAT) / sz; + + ret = pipe->winsys->surface_alloc_storage(pipe->winsys, + strb->surface, + width, height * mult, + accum_format, flags); + if (ret) + return GL_FALSE; /* we've _really_ failed */ + + } + else { + return GL_FALSE; /* out of memory, try s/w buffer? */ + } } ASSERT(strb->surface->buffer); ASSERT(strb->surface->format); ASSERT(strb->surface->cpp); ASSERT(strb->surface->width == width); - ASSERT(strb->surface->height == height); + /*ASSERT(strb->surface->height == height);*/ ASSERT(strb->surface->pitch); strb->Base.Width = width; @@ -252,7 +275,7 @@ st_new_renderbuffer_fb(enum pipe_format format) strb->Base.InternalFormat = GL_STENCIL_INDEX8_EXT; strb->Base._BaseFormat = GL_STENCIL_INDEX; break; - case PIPE_FORMAT_R16G16B16A16_SNORM: + case DEFAULT_ACCUM_PIPE_FORMAT: /*PIPE_FORMAT_R16G16B16A16_SNORM*/ strb->Base.InternalFormat = GL_RGBA16; strb->Base._BaseFormat = GL_RGBA; break; diff --git a/src/mesa/state_tracker/st_cb_fbo.h b/src/mesa/state_tracker/st_cb_fbo.h index 21e531d1d0..c1aa14f9b2 100644 --- a/src/mesa/state_tracker/st_cb_fbo.h +++ b/src/mesa/state_tracker/st_cb_fbo.h @@ -30,6 +30,9 @@ #define ST_CB_FBO_H +#define DEFAULT_ACCUM_PIPE_FORMAT PIPE_FORMAT_R16G16B16A16_SNORM + + /** * Derived renderbuffer class. Just need to add a pointer to the diff --git a/src/mesa/state_tracker/st_framebuffer.c b/src/mesa/state_tracker/st_framebuffer.c index 075e9d1bd6..ea09d9234c 100644 --- a/src/mesa/state_tracker/st_framebuffer.c +++ b/src/mesa/state_tracker/st_framebuffer.c @@ -107,7 +107,7 @@ st_create_framebuffer( const __GLcontextModes *visual, if (visual->accumRedBits > 0) { /* 16-bit/channel accum */ struct gl_renderbuffer *accumRb - = st_new_renderbuffer_fb(PIPE_FORMAT_R16G16B16A16_SNORM); + = st_new_renderbuffer_fb(DEFAULT_ACCUM_PIPE_FORMAT); _mesa_add_renderbuffer(&stfb->Base, BUFFER_ACCUM, accumRb); } -- cgit v1.2.3 From 7333578d2a5fa18f7f0101fc3fd3b03cf2f356bc Mon Sep 17 00:00:00 2001 From: Michel Dänzer Date: Thu, 24 Apr 2008 10:12:07 +0100 Subject: gallium: Initial support for pixel formats with unused storage components. Also clarify that RGB formats with no (used) alpha component are treated as having alpha = 1.0. --- src/gallium/auxiliary/util/p_tile.c | 52 ++++++++++++++ src/gallium/auxiliary/util/u_gen_mipmap.c | 2 + src/gallium/auxiliary/util/u_pack_color.h | 38 +++++++++++ src/gallium/include/pipe/p_format.h | 108 +++++++++++++++++------------- src/mesa/state_tracker/st_cb_fbo.c | 4 ++ 5 files changed, 157 insertions(+), 47 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/gallium/auxiliary/util/p_tile.c b/src/gallium/auxiliary/util/p_tile.c index 520da5cecd..91283a9ab0 100644 --- a/src/gallium/auxiliary/util/p_tile.c +++ b/src/gallium/auxiliary/util/p_tile.c @@ -169,6 +169,52 @@ a8r8g8b8_put_tile_rgba(unsigned *dst, } +/*** PIPE_FORMAT_A8R8G8B8_UNORM ***/ + +static void +x8r8g8b8_get_tile_rgba(unsigned *src, + unsigned w, unsigned h, + float *p, + unsigned dst_stride) +{ + unsigned i, j; + + for (i = 0; i < h; i++) { + float *pRow = p; + for (j = 0; j < w; j++, pRow += 4) { + const unsigned pixel = *src++; + pRow[0] = UBYTE_TO_FLOAT((pixel >> 16) & 0xff); + pRow[1] = UBYTE_TO_FLOAT((pixel >> 8) & 0xff); + pRow[2] = UBYTE_TO_FLOAT((pixel >> 0) & 0xff); + pRow[3] = UBYTE_TO_FLOAT(0xff); + } + p += dst_stride; + } +} + + +static void +x8r8g8b8_put_tile_rgba(unsigned *dst, + unsigned w, unsigned h, + const float *p, + unsigned src_stride) +{ + unsigned i, j; + + for (i = 0; i < h; i++) { + const float *pRow = p; + for (j = 0; j < w; j++, pRow += 4) { + unsigned r, g, b; + UNCLAMPED_FLOAT_TO_UBYTE(r, pRow[0]); + UNCLAMPED_FLOAT_TO_UBYTE(g, pRow[1]); + UNCLAMPED_FLOAT_TO_UBYTE(b, pRow[2]); + *dst++ = (0xff << 24) | (r << 16) | (g << 8) | b; + } + p += src_stride; + } +} + + /*** PIPE_FORMAT_B8G8R8A8_UNORM ***/ static void @@ -647,6 +693,9 @@ pipe_get_tile_rgba(struct pipe_context *pipe, case PIPE_FORMAT_A8R8G8B8_UNORM: a8r8g8b8_get_tile_rgba((unsigned *) packed, w, h, p, dst_stride); break; + case PIPE_FORMAT_X8R8G8B8_UNORM: + x8r8g8b8_get_tile_rgba((unsigned *) packed, w, h, p, dst_stride); + break; case PIPE_FORMAT_B8G8R8A8_UNORM: b8g8r8a8_get_tile_rgba((unsigned *) packed, w, h, p, dst_stride); break; @@ -723,6 +772,9 @@ pipe_put_tile_rgba(struct pipe_context *pipe, case PIPE_FORMAT_A8R8G8B8_UNORM: a8r8g8b8_put_tile_rgba((unsigned *) packed, w, h, p, src_stride); break; + case PIPE_FORMAT_X8R8G8B8_UNORM: + x8r8g8b8_put_tile_rgba((unsigned *) packed, w, h, p, src_stride); + break; case PIPE_FORMAT_B8G8R8A8_UNORM: b8g8r8a8_put_tile_rgba((unsigned *) packed, w, h, p, src_stride); break; diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c index dfdb5f16fe..b8dc6c66c0 100644 --- a/src/gallium/auxiliary/util/u_gen_mipmap.c +++ b/src/gallium/auxiliary/util/u_gen_mipmap.c @@ -475,7 +475,9 @@ format_to_type_comps(enum pipe_format pformat, { switch (pformat) { case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_X8R8G8B8_UNORM: case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: *datatype = UBYTE; *comps = 4; return; diff --git a/src/gallium/auxiliary/util/u_pack_color.h b/src/gallium/auxiliary/util/u_pack_color.h index 1f6604c554..50ef44992b 100644 --- a/src/gallium/auxiliary/util/u_pack_color.h +++ b/src/gallium/auxiliary/util/u_pack_color.h @@ -53,18 +53,36 @@ util_pack_color_ub(ubyte r, ubyte g, ubyte b, ubyte a, *d = (r << 24) | (g << 16) | (b << 8) | a; } return; + case PIPE_FORMAT_R8G8B8X8_UNORM: + { + uint *d = (uint *) dest; + *d = (r << 24) | (g << 16) | (b << 8) | 0xff; + } + return; case PIPE_FORMAT_A8R8G8B8_UNORM: { uint *d = (uint *) dest; *d = (a << 24) | (r << 16) | (g << 8) | b; } return; + case PIPE_FORMAT_X8R8G8B8_UNORM: + { + uint *d = (uint *) dest; + *d = (0xff << 24) | (r << 16) | (g << 8) | b; + } + return; case PIPE_FORMAT_B8G8R8A8_UNORM: { uint *d = (uint *) dest; *d = (b << 24) | (g << 16) | (r << 8) | a; } return; + case PIPE_FORMAT_B8G8R8X8_UNORM: + { + uint *d = (uint *) dest; + *d = (b << 24) | (g << 16) | (r << 8) | 0xff; + } + return; case PIPE_FORMAT_R5G6B5_UNORM: { ushort *d = (ushort *) dest; @@ -101,18 +119,36 @@ util_pack_color(const float rgba[4], enum pipe_format format, void *dest) *d = (r << 24) | (g << 16) | (b << 8) | a; } return; + case PIPE_FORMAT_R8G8B8X8_UNORM: + { + uint *d = (uint *) dest; + *d = (r << 24) | (g << 16) | (b << 8) | 0xff; + } + return; case PIPE_FORMAT_A8R8G8B8_UNORM: { uint *d = (uint *) dest; *d = (a << 24) | (r << 16) | (g << 8) | b; } return; + case PIPE_FORMAT_X8R8G8B8_UNORM: + { + uint *d = (uint *) dest; + *d = (0xff << 24) | (r << 16) | (g << 8) | b; + } + return; case PIPE_FORMAT_B8G8R8A8_UNORM: { uint *d = (uint *) dest; *d = (b << 24) | (g << 16) | (r << 8) | a; } return; + case PIPE_FORMAT_B8G8R8X8_UNORM: + { + uint *d = (uint *) dest; + *d = (b << 24) | (g << 16) | (r << 8) | 0xff; + } + return; case PIPE_FORMAT_R5G6B5_UNORM: { ushort *d = (ushort *) dest; @@ -159,8 +195,10 @@ util_pack_z(enum pipe_format format, double z) else return (uint) (z * 0xffffffff); case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: return (uint) (z * 0xffffff); case PIPE_FORMAT_Z24S8_UNORM: + case PIPE_FORMAT_Z24X8_UNORM: return ((uint) (z * 0xffffff)) << 8; default: debug_printf("gallium: unhandled fomrat in util_pack_z()"); diff --git a/src/gallium/include/pipe/p_format.h b/src/gallium/include/pipe/p_format.h index ef9e3a3d6c..2ee6f100bf 100644 --- a/src/gallium/include/pipe/p_format.h +++ b/src/gallium/include/pipe/p_format.h @@ -163,18 +163,21 @@ static INLINE uint pf_get(pipe_format_rgbazs_t f, uint shift, uint mask) /** * Shorthand macro for common format swizzles. */ -#define _PIPE_FORMAT_R000 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0 ) -#define _PIPE_FORMAT_RG00 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0 ) -#define _PIPE_FORMAT_RGB0 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_B, PIPE_FORMAT_COMP_0 ) +#define _PIPE_FORMAT_R001 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_1 ) +#define _PIPE_FORMAT_RG01 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_1 ) +#define _PIPE_FORMAT_RGB1 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_B, PIPE_FORMAT_COMP_1 ) #define _PIPE_FORMAT_RGBA _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_B, PIPE_FORMAT_COMP_A ) #define _PIPE_FORMAT_ARGB _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_A, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_B ) #define _PIPE_FORMAT_BGRA _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_B, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_A ) +#define _PIPE_FORMAT_1RGB _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_1, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_B ) +#define _PIPE_FORMAT_BGR1 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_B, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_1 ) #define _PIPE_FORMAT_0000 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0 ) #define _PIPE_FORMAT_000R _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_R ) #define _PIPE_FORMAT_RRR1 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_1 ) #define _PIPE_FORMAT_RRRR _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_R ) #define _PIPE_FORMAT_RRRG _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_G ) #define _PIPE_FORMAT_Z000 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_Z, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0 ) +#define _PIPE_FORMAT_0Z00 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_Z, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0 ) #define _PIPE_FORMAT_SZ00 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_S, PIPE_FORMAT_COMP_Z, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0 ) #define _PIPE_FORMAT_ZS00 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_Z, PIPE_FORMAT_COMP_S, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0 ) #define _PIPE_FORMAT_S000 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_S, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0 ) @@ -229,10 +232,12 @@ static INLINE uint pf_rev(pipe_format_ycbcr_t f) enum pipe_format { PIPE_FORMAT_NONE = _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_0000, 0, 0, 0, 0, PIPE_FORMAT_TYPE_UNKNOWN ), PIPE_FORMAT_A8R8G8B8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_ARGB, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_X8R8G8B8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_1RGB, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), PIPE_FORMAT_B8G8R8A8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_BGRA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_B8G8R8X8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_BGR1, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), PIPE_FORMAT_A1R5G5B5_UNORM = _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_ARGB, 1, 5, 5, 5, PIPE_FORMAT_TYPE_UNORM ), PIPE_FORMAT_A4R4G4B4_UNORM = _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_ARGB, 4, 4, 4, 4, PIPE_FORMAT_TYPE_UNORM ), - PIPE_FORMAT_R5G6B5_UNORM = _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_RGB0, 5, 6, 5, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R5G6B5_UNORM = _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_RGB1, 5, 6, 5, 0, PIPE_FORMAT_TYPE_UNORM ), PIPE_FORMAT_U_L8 = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRR1, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), /**< ubyte luminance */ PIPE_FORMAT_U_A8 = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_000R, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), /**< ubyte alpha */ PIPE_FORMAT_U_I8 = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRRR, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), /**< ubyte intensity */ @@ -244,68 +249,75 @@ enum pipe_format { PIPE_FORMAT_Z32_FLOAT = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_Z000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT ), PIPE_FORMAT_S8Z24_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_SZ00, 1, 3, 0, 0, PIPE_FORMAT_TYPE_UNORM ), PIPE_FORMAT_Z24S8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_ZS00, 3, 1, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_X8Z24_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_0Z00, 1, 3, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_Z24X8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_Z000, 3, 1, 0, 0, PIPE_FORMAT_TYPE_UNORM ), PIPE_FORMAT_S8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_S000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), /**< ubyte stencil */ - PIPE_FORMAT_R64_FLOAT = _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT ), - PIPE_FORMAT_R64G64_FLOAT = _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_FLOAT ), - PIPE_FORMAT_R64G64B64_FLOAT = _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_R64_FLOAT = _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_R001, 1, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_R64G64_FLOAT = _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_RG01, 1, 1, 0, 0, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_R64G64B64_FLOAT = _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_RGB1, 1, 1, 1, 0, PIPE_FORMAT_TYPE_FLOAT ), PIPE_FORMAT_R64G64B64A64_FLOAT = _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_FLOAT ), - PIPE_FORMAT_R32_FLOAT = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT ), - PIPE_FORMAT_R32G32_FLOAT = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_FLOAT ), - PIPE_FORMAT_R32G32B32_FLOAT = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_R32_FLOAT = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001, 4, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_R32G32_FLOAT = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01, 4, 4, 0, 0, PIPE_FORMAT_TYPE_FLOAT ), + PIPE_FORMAT_R32G32B32_FLOAT = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 4, 4, 4, 0, PIPE_FORMAT_TYPE_FLOAT ), PIPE_FORMAT_R32G32B32A32_FLOAT = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_FLOAT ), - PIPE_FORMAT_R32_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), - PIPE_FORMAT_R32G32_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_UNORM ), - PIPE_FORMAT_R32G32B32_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R32_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001, 4, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R32G32_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01, 4, 4, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R32G32B32_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 4, 4, 4, 0, PIPE_FORMAT_TYPE_UNORM ), PIPE_FORMAT_R32G32B32A32_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_UNORM ), - PIPE_FORMAT_R32_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_USCALED ), - PIPE_FORMAT_R32G32_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_USCALED ), - PIPE_FORMAT_R32G32B32_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R32_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001, 4, 0, 0, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R32G32_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01, 4, 4, 0, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R32G32B32_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 4, 4, 4, 0, PIPE_FORMAT_TYPE_USCALED ), PIPE_FORMAT_R32G32B32A32_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_USCALED ), - PIPE_FORMAT_R32_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_SNORM ), - PIPE_FORMAT_R32G32_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_SNORM ), - PIPE_FORMAT_R32G32B32_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R32_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001, 4, 0, 0, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R32G32_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01, 4, 4, 0, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R32G32B32_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 4, 4, 4, 0, PIPE_FORMAT_TYPE_SNORM ), PIPE_FORMAT_R32G32B32A32_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_SNORM ), - PIPE_FORMAT_R32_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 4, 0, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), - PIPE_FORMAT_R32G32_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 4, 4, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), - PIPE_FORMAT_R32G32B32_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 4, 4, 4, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R32_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001, 4, 0, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R32G32_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01, 4, 4, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R32G32B32_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 4, 4, 4, 0, PIPE_FORMAT_TYPE_SSCALED ), PIPE_FORMAT_R32G32B32A32_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 4, 4, 4, 4, PIPE_FORMAT_TYPE_SSCALED ), - PIPE_FORMAT_R16_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), - PIPE_FORMAT_R16G16_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 2, 2, 0, 0, PIPE_FORMAT_TYPE_UNORM ), - PIPE_FORMAT_R16G16B16_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 2, 2, 2, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R16_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001, 2, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R16G16_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01, 2, 2, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R16G16B16_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 2, 2, 2, 0, PIPE_FORMAT_TYPE_UNORM ), PIPE_FORMAT_R16G16B16A16_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_UNORM ), - PIPE_FORMAT_R16_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_USCALED ), - PIPE_FORMAT_R16G16_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 2, 2, 0, 0, PIPE_FORMAT_TYPE_USCALED ), - PIPE_FORMAT_R16G16B16_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 2, 2, 2, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R16_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001, 2, 0, 0, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R16G16_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01, 2, 2, 0, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R16G16B16_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 2, 2, 2, 0, PIPE_FORMAT_TYPE_USCALED ), PIPE_FORMAT_R16G16B16A16_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_USCALED ), - PIPE_FORMAT_R16_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_SNORM ), - PIPE_FORMAT_R16G16_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 2, 2, 0, 0, PIPE_FORMAT_TYPE_SNORM ), - PIPE_FORMAT_R16G16B16_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 2, 2, 2, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R16_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001, 2, 0, 0, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R16G16_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01, 2, 2, 0, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R16G16B16_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 2, 2, 2, 0, PIPE_FORMAT_TYPE_SNORM ), PIPE_FORMAT_R16G16B16A16_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_SNORM ), - PIPE_FORMAT_R16_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 2, 0, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), - PIPE_FORMAT_R16G16_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 2, 2, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), - PIPE_FORMAT_R16G16B16_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 2, 2, 2, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R16_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001, 2, 0, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R16G16_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01, 2, 2, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R16G16B16_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 2, 2, 2, 0, PIPE_FORMAT_TYPE_SSCALED ), PIPE_FORMAT_R16G16B16A16_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 2, 2, 2, 2, PIPE_FORMAT_TYPE_SSCALED ), - PIPE_FORMAT_R8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), - PIPE_FORMAT_R8G8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_UNORM ), - PIPE_FORMAT_R8G8B8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001, 1, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R8G8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01, 1, 1, 0, 0, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R8G8B8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 1, 1, 1, 0, PIPE_FORMAT_TYPE_UNORM ), PIPE_FORMAT_R8G8B8A8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), - PIPE_FORMAT_R8_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_USCALED ), - PIPE_FORMAT_R8G8_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_USCALED ), - PIPE_FORMAT_R8G8B8_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R8G8B8X8_UNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM ), + PIPE_FORMAT_R8_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001, 1, 0, 0, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R8G8_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01, 1, 1, 0, 0, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R8G8B8_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 1, 1, 1, 0, PIPE_FORMAT_TYPE_USCALED ), PIPE_FORMAT_R8G8B8A8_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_USCALED ), - PIPE_FORMAT_R8_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_SNORM ), - PIPE_FORMAT_R8G8_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_SNORM ), - PIPE_FORMAT_R8G8B8_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R8G8B8X8_USCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 1, 1, 1, 1, PIPE_FORMAT_TYPE_USCALED ), + PIPE_FORMAT_R8_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001, 1, 0, 0, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R8G8_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01, 1, 1, 0, 0, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R8G8B8_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 1, 1, 1, 0, PIPE_FORMAT_TYPE_SNORM ), PIPE_FORMAT_R8G8B8A8_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SNORM ), - PIPE_FORMAT_R8_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R000, 1, 0, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), - PIPE_FORMAT_R8G8_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG00, 1, 1, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), - PIPE_FORMAT_R8G8B8_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R8G8B8X8_SNORM = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SNORM ), + PIPE_FORMAT_R8_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001, 1, 0, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R8G8_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01, 1, 1, 0, 0, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R8G8B8_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 1, 1, 1, 0, PIPE_FORMAT_TYPE_SSCALED ), PIPE_FORMAT_R8G8B8A8_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SSCALED ), + PIPE_FORMAT_R8G8B8X8_SSCALED = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SSCALED ), /* sRGB formats */ PIPE_FORMAT_L8_SRGB = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRR1, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SRGB ), PIPE_FORMAT_A8_L8_SRGB = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRRG, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SRGB ), - PIPE_FORMAT_R8G8B8_SRGB = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB0, 1, 1, 1, 0, PIPE_FORMAT_TYPE_SRGB ), + PIPE_FORMAT_R8G8B8_SRGB = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 1, 1, 1, 0, PIPE_FORMAT_TYPE_SRGB ), PIPE_FORMAT_R8G8B8A8_SRGB = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SRGB ), + PIPE_FORMAT_R8G8B8X8_SRGB = _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SRGB ), /* compressed formats */ PIPE_FORMAT_DXT1_RGB = _PIPE_FORMAT_DXT( 1, 8, 8, 8, 0 ), @@ -442,6 +454,8 @@ static INLINE uint pf_get_bits( enum pipe_format format ) switch (pf_layout(format)) { case PIPE_FORMAT_LAYOUT_RGBAZS: return + pf_get_component_bits( format, PIPE_FORMAT_COMP_0 ) + + pf_get_component_bits( format, PIPE_FORMAT_COMP_1 ) + pf_get_component_bits( format, PIPE_FORMAT_COMP_R ) + pf_get_component_bits( format, PIPE_FORMAT_COMP_G ) + pf_get_component_bits( format, PIPE_FORMAT_COMP_B ) + diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index b1a56f3ca6..b73867bb72 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -252,6 +252,8 @@ st_new_renderbuffer_fb(enum pipe_format format) switch (format) { case PIPE_FORMAT_A8R8G8B8_UNORM: case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_X8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: case PIPE_FORMAT_A1R5G5B5_UNORM: case PIPE_FORMAT_A4R4G4B4_UNORM: case PIPE_FORMAT_R5G6B5_UNORM: @@ -268,6 +270,8 @@ st_new_renderbuffer_fb(enum pipe_format format) break; case PIPE_FORMAT_S8Z24_UNORM: case PIPE_FORMAT_Z24S8_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: + case PIPE_FORMAT_Z24X8_UNORM: strb->Base.InternalFormat = GL_DEPTH24_STENCIL8_EXT; strb->Base._BaseFormat = GL_DEPTH_STENCIL_EXT; break; -- cgit v1.2.3 From d7b523b46b833fd08c70850d7a6cc7b6fd714a8e Mon Sep 17 00:00:00 2001 From: Michel Dänzer Date: Fri, 25 Apr 2008 10:34:20 +0100 Subject: gallium: Tell the driver the texture is updated when we finish rendering to it. --- src/mesa/state_tracker/st_cb_fbo.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index b73867bb72..69dde56e55 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -400,6 +400,10 @@ st_finish_render_texture(GLcontext *ctx, ctx->st->pipe->flush(ctx->st->pipe, PIPE_FLUSH_RENDER_CACHE, NULL); + ctx->st->pipe->texture_update(ctx->st->pipe, + st_get_texobj_texture(att->Texture), + att->CubeMapFace, 1 << att->TextureLevel); + /* printf("FINISH RENDER TO TEXTURE surf=%p\n", strb->surface); */ -- cgit v1.2.3 From dd9dc7df80d208b884b4c090e4408c9a12aa6095 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 29 Apr 2008 12:54:52 -0600 Subject: gallium: added some assertions to st_render_texture() to check surface format Make sure we can really render to the texture surface given its format. --- src/mesa/state_tracker/st_cb_fbo.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 69dde56e55..2d741d9390 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -370,6 +370,8 @@ st_render_texture(GLcontext *ctx, att->TextureLevel, att->Zoffset); assert(strb->surface); + assert(screen->is_format_supported(screen, strb->surface->format, PIPE_TEXTURE)); + assert(screen->is_format_supported(screen, strb->surface->format, PIPE_SURFACE)); init_renderbuffer_bits(strb, pt->format); -- cgit v1.2.3 From 99fba5466bfd14c4e052041c0571821be529e762 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 30 Apr 2008 10:43:59 -0600 Subject: gallium: use new buffer wrapper functions in p_inlines.h This allows us to remove most of the direct references to winsys in the state tracker. --- src/mesa/state_tracker/st_atom_constbuf.c | 14 ++++---- src/mesa/state_tracker/st_cb_bitmap.c | 13 +++---- src/mesa/state_tracker/st_cb_bufferobjects.c | 22 +++++------- src/mesa/state_tracker/st_cb_clear.c | 14 ++++---- src/mesa/state_tracker/st_cb_drawpixels.c | 13 +++---- src/mesa/state_tracker/st_cb_fbo.c | 2 +- src/mesa/state_tracker/st_context.c | 4 +-- src/mesa/state_tracker/st_draw.c | 54 ++++++++++++---------------- src/mesa/state_tracker/st_gen_mipmap.c | 14 ++++---- src/mesa/state_tracker/st_texture.c | 1 - 10 files changed, 62 insertions(+), 89 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_atom_constbuf.c b/src/mesa/state_tracker/st_atom_constbuf.c index 03093579e1..2b659aebbc 100644 --- a/src/mesa/state_tracker/st_atom_constbuf.c +++ b/src/mesa/state_tracker/st_atom_constbuf.c @@ -36,7 +36,6 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" -#include "pipe/p_winsys.h" #include "pipe/p_inlines.h" #include "st_context.h" @@ -54,7 +53,7 @@ void st_upload_constants( struct st_context *st, struct gl_program_parameter_list *params, unsigned id) { - struct pipe_winsys *ws = st->pipe->winsys; + struct pipe_context *pipe = st->pipe; struct pipe_constant_buffer *cbuf = &st->state.constants[id]; assert(id == PIPE_SHADER_VERTEX || id == PIPE_SHADER_FRAGMENT); @@ -74,8 +73,8 @@ void st_upload_constants( struct st_context *st, /* We always need to get a new buffer, to keep the drivers simple and * avoid gratuitous rendering synchronization. */ - pipe_buffer_reference( ws, &cbuf->buffer, NULL ); - cbuf->buffer = ws->buffer_create( ws, 1, PIPE_BUFFER_USAGE_CONSTANT, + pipe_reference_buffer(pipe, &cbuf->buffer, NULL ); + cbuf->buffer = pipe_buffer_create(pipe, 1, PIPE_BUFFER_USAGE_CONSTANT, paramBytes ); if (0) @@ -87,9 +86,10 @@ void st_upload_constants( struct st_context *st, /* load Mesa constants into the constant buffer */ if (cbuf->buffer) { - memcpy(ws->buffer_map(ws, cbuf->buffer, PIPE_BUFFER_USAGE_CPU_WRITE), - params->ParameterValues, paramBytes); - ws->buffer_unmap(ws, cbuf->buffer); + void *map = pipe_buffer_map(pipe, cbuf->buffer, + PIPE_BUFFER_USAGE_CPU_WRITE); + memcpy(map, params->ParameterValues, paramBytes); + pipe_buffer_unmap(pipe, cbuf->buffer); } cbuf->size = paramBytes; diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index d73cd4abfa..f0a3b75357 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -50,7 +50,6 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_inlines.h" -#include "pipe/p_winsys.h" #include "util/p_tile.h" #include "util/u_draw_quad.h" #include "util/u_simple_shaders.h" @@ -372,9 +371,8 @@ setup_bitmap_vertex_data(struct st_context *st, void *buf; if (!st->bitmap.vbuf) { - st->bitmap.vbuf = pipe->winsys->buffer_create(pipe->winsys, 32, - PIPE_BUFFER_USAGE_VERTEX, - sizeof(st->bitmap.vertices)); + st->bitmap.vbuf = pipe_buffer_create(pipe, 32, PIPE_BUFFER_USAGE_VERTEX, + sizeof(st->bitmap.vertices)); } /* Positions are in clip coords since we need to do clipping in case @@ -413,10 +411,9 @@ setup_bitmap_vertex_data(struct st_context *st, } /* put vertex data into vbuf */ - buf = pipe->winsys->buffer_map(pipe->winsys, st->bitmap.vbuf, - PIPE_BUFFER_USAGE_CPU_WRITE); + buf = pipe_buffer_map(pipe, st->bitmap.vbuf, PIPE_BUFFER_USAGE_CPU_WRITE); memcpy(buf, st->bitmap.vertices, sizeof(st->bitmap.vertices)); - pipe->winsys->buffer_unmap(pipe->winsys, st->bitmap.vbuf); + pipe_buffer_unmap(pipe, st->bitmap.vbuf); } @@ -761,7 +758,7 @@ st_destroy_bitmap(struct st_context *st) } if (st->bitmap.vbuf) { - pipe->winsys->buffer_destroy(pipe->winsys, st->bitmap.vbuf); + pipe_buffer_destroy(pipe, st->bitmap.vbuf); st->bitmap.vbuf = NULL; } diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c index fa1254ff7c..af79aefa96 100644 --- a/src/mesa/state_tracker/st_cb_bufferobjects.c +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c @@ -35,7 +35,6 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" -#include "pipe/p_winsys.h" #include "pipe/p_inlines.h" @@ -79,7 +78,7 @@ st_bufferobj_free(GLcontext *ctx, struct gl_buffer_object *obj) struct st_buffer_object *st_obj = st_buffer_object(obj); if (st_obj->buffer) - pipe_buffer_reference(pipe->winsys, &st_obj->buffer, NULL); + pipe_reference_buffer(pipe, &st_obj->buffer, NULL); free(st_obj); } @@ -106,10 +105,9 @@ st_bufferobj_subdata(GLcontext *ctx, if (offset >= st_obj->size || size > (st_obj->size - offset)) return; - map = pipe->winsys->buffer_map(pipe->winsys, st_obj->buffer, - PIPE_BUFFER_USAGE_CPU_WRITE); + map = pipe_buffer_map(pipe, st_obj->buffer, PIPE_BUFFER_USAGE_CPU_WRITE); memcpy(map + offset, data, size); - pipe->winsys->buffer_unmap(pipe->winsys, st_obj->buffer); + pipe_buffer_unmap(pipe, st_obj->buffer); } @@ -130,10 +128,9 @@ st_bufferobj_get_subdata(GLcontext *ctx, if (offset >= st_obj->size || size > (st_obj->size - offset)) return; - map = pipe->winsys->buffer_map(pipe->winsys, st_obj->buffer, - PIPE_BUFFER_USAGE_CPU_READ); + map = pipe_buffer_map(pipe, st_obj->buffer, PIPE_BUFFER_USAGE_CPU_READ); memcpy(data, map + offset, size); - pipe->winsys->buffer_unmap(pipe->winsys, st_obj->buffer); + pipe_buffer_unmap(pipe, st_obj->buffer); } @@ -174,10 +171,9 @@ st_bufferobj_data(GLcontext *ctx, buffer_usage = 0; } - pipe_buffer_reference( pipe->winsys, &st_obj->buffer, NULL ); + pipe_reference_buffer( pipe, &st_obj->buffer, NULL ); - st_obj->buffer = pipe->winsys->buffer_create( pipe->winsys, 32, buffer_usage, - size ); + st_obj->buffer = pipe_buffer_create( pipe, 32, buffer_usage, size ); st_obj->size = size; @@ -211,7 +207,7 @@ st_bufferobj_map(GLcontext *ctx, GLenum target, GLenum access, break; } - obj->Pointer = pipe->winsys->buffer_map(pipe->winsys, st_obj->buffer, flags); + obj->Pointer = pipe_buffer_map(pipe, st_obj->buffer, flags); return obj->Pointer; } @@ -225,7 +221,7 @@ st_bufferobj_unmap(GLcontext *ctx, GLenum target, struct gl_buffer_object *obj) struct pipe_context *pipe = st_context(ctx)->pipe; struct st_buffer_object *st_obj = st_buffer_object(obj); - pipe->winsys->buffer_unmap(pipe->winsys, st_obj->buffer); + pipe_buffer_unmap(pipe, st_obj->buffer); obj->Pointer = NULL; return GL_TRUE; } diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 95a5fb8db4..fe979f10bd 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -45,9 +45,9 @@ #include "st_mesa_to_tgsi.h" #include "pipe/p_context.h" +#include "pipe/p_inlines.h" #include "pipe/p_state.h" #include "pipe/p_defines.h" -#include "pipe/p_winsys.h" #include "util/u_pack_color.h" #include "util/u_simple_shaders.h" #include "util/u_draw_quad.h" @@ -106,7 +106,7 @@ st_destroy_clear(struct st_context *st) st->clear.vs = NULL; } if (st->clear.vbuf) { - pipe->winsys->buffer_destroy(pipe->winsys, st->clear.vbuf); + pipe_buffer_destroy(pipe, st->clear.vbuf); st->clear.vbuf = NULL; } } @@ -142,9 +142,8 @@ draw_quad(GLcontext *ctx, void *buf; if (!st->clear.vbuf) { - st->clear.vbuf = pipe->winsys->buffer_create(pipe->winsys, 32, - PIPE_BUFFER_USAGE_VERTEX, - sizeof(st->clear.vertices)); + st->clear.vbuf = pipe_buffer_create(pipe, 32, PIPE_BUFFER_USAGE_VERTEX, + sizeof(st->clear.vertices)); } /* positions */ @@ -171,10 +170,9 @@ draw_quad(GLcontext *ctx, } /* put vertex data into vbuf */ - buf = pipe->winsys->buffer_map(pipe->winsys, st->clear.vbuf, - PIPE_BUFFER_USAGE_CPU_WRITE); + buf = pipe_buffer_map(pipe, st->clear.vbuf, PIPE_BUFFER_USAGE_CPU_WRITE); memcpy(buf, st->clear.vertices, sizeof(st->clear.vertices)); - pipe->winsys->buffer_unmap(pipe->winsys, st->clear.vbuf); + pipe_buffer_unmap(pipe, st->clear.vbuf); /* draw */ util_draw_vertex_buffer(pipe, st->clear.vbuf, diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 7597ea323c..65bfd6cfcc 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -55,7 +55,6 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_inlines.h" -#include "pipe/p_winsys.h" #include "util/p_tile.h" #include "util/u_draw_quad.h" #include "shader/prog_instruction.h" @@ -483,20 +482,18 @@ draw_quad(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z, ubyte *map; /* allocate/load buffer object with vertex data */ - buf = pipe->winsys->buffer_create(pipe->winsys, 32, - PIPE_BUFFER_USAGE_VERTEX, - sizeof(verts)); - map = pipe->winsys->buffer_map(pipe->winsys, buf, - PIPE_BUFFER_USAGE_CPU_WRITE); + buf = pipe_buffer_create(pipe,32, PIPE_BUFFER_USAGE_VERTEX, + sizeof(verts)); + map = pipe_buffer_map(pipe, buf, PIPE_BUFFER_USAGE_CPU_WRITE); memcpy(map, verts, sizeof(verts)); - pipe->winsys->buffer_unmap(pipe->winsys, buf); + pipe_buffer_unmap(pipe, buf); util_draw_vertex_buffer(pipe, buf, PIPE_PRIM_QUADS, 4, /* verts */ 3); /* attribs/vert */ - pipe->winsys->buffer_destroy(pipe->winsys, buf); + pipe_buffer_destroy(pipe, buf); } } diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 2d741d9390..fc8a5ea7f6 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -105,7 +105,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, } else if (strb->surface->buffer) { /* release/discard the old surface buffer */ - pipe_buffer_reference(pipe->winsys, &strb->surface->buffer, NULL); + pipe_reference_buffer(pipe, &strb->surface->buffer, NULL); } /* Determine surface format here */ diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 8a30871fa0..c900064f2b 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -55,7 +55,6 @@ #include "st_gen_mipmap.h" #include "st_program.h" #include "pipe/p_context.h" -#include "pipe/p_winsys.h" #include "pipe/p_inlines.h" #include "draw/draw_context.h" #include "cso_cache/cso_cache.h" @@ -157,7 +156,6 @@ struct st_context *st_create_context(struct pipe_context *pipe, static void st_destroy_context_priv( struct st_context *st ) { - struct pipe_winsys *ws = st->pipe->winsys; uint i; draw_destroy(st->draw); @@ -172,7 +170,7 @@ static void st_destroy_context_priv( struct st_context *st ) for (i = 0; i < Elements(st->state.constants); i++) { if (st->state.constants[i].buffer) { - pipe_buffer_reference(ws, &st->state.constants[i].buffer, NULL); + pipe_reference_buffer(st->pipe, &st->state.constants[i].buffer, NULL); } } diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index 6c20120ac7..0fe4d198bd 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -43,7 +43,6 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" -#include "pipe/p_winsys.h" #include "pipe/p_inlines.h" #include "draw/draw_private.h" @@ -219,8 +218,7 @@ setup_edgeflags(GLcontext *ctx, GLenum primMode, GLint start, GLint count, if (!vec) return NULL; - map = pipe->winsys->buffer_map(pipe->winsys, stobj->buffer, - PIPE_BUFFER_USAGE_CPU_READ); + map = pipe_buffer_map(pipe, stobj->buffer, PIPE_BUFFER_USAGE_CPU_READ); map = ADD_POINTERS(map, array->Ptr); for (i = 0; i < count; i++) { @@ -230,7 +228,7 @@ setup_edgeflags(GLcontext *ctx, GLenum primMode, GLint start, GLint count, map += array->StrideB; } - pipe->winsys->buffer_unmap(pipe->winsys, stobj->buffer); + pipe_buffer_unmap(pipe, stobj->buffer); pipe->set_edgeflags(pipe, vec); @@ -260,7 +258,6 @@ st_draw_vbo(GLcontext *ctx, GLuint max_index) { struct pipe_context *pipe = ctx->st->pipe; - struct pipe_winsys *winsys = pipe->winsys; const struct st_vertex_program *vp; const struct pipe_shader_state *vs; struct pipe_vertex_buffer vbuffer[PIPE_MAX_SHADER_INPUTS]; @@ -292,7 +289,7 @@ st_draw_vbo(GLcontext *ctx, assert(stobj->buffer); vbuffer[attr].buffer = NULL; - pipe_buffer_reference(winsys, &vbuffer[attr].buffer, stobj->buffer); + pipe_reference_buffer(pipe, &vbuffer[attr].buffer, stobj->buffer); vbuffer[attr].buffer_offset = (unsigned) arrays[0]->Ptr;/* in bytes */ velements[attr].src_offset = arrays[mesaAttr]->Ptr - arrays[0]->Ptr; assert(velements[attr].src_offset <= 2048); /* 11-bit field */ @@ -310,9 +307,8 @@ st_draw_vbo(GLcontext *ctx, /* wrap user data */ vbuffer[attr].buffer - = winsys->user_buffer_create(winsys, - (void *) arrays[mesaAttr]->Ptr, - bytes); + = pipe_user_buffer_create(pipe, (void *) arrays[mesaAttr]->Ptr, + bytes); vbuffer[attr].buffer_offset = 0; velements[attr].src_offset = 0; } @@ -358,14 +354,13 @@ st_draw_vbo(GLcontext *ctx, if (bufobj && bufobj->Name) { /* elements/indexes are in a real VBO */ struct st_buffer_object *stobj = st_buffer_object(bufobj); - pipe_buffer_reference(winsys, &indexBuf, stobj->buffer); + pipe_reference_buffer(pipe, &indexBuf, stobj->buffer); indexOffset = (unsigned) ib->ptr / indexSize; } else { /* element/indicies are in user space memory */ - indexBuf = winsys->user_buffer_create(winsys, - (void *) ib->ptr, - ib->count * indexSize); + indexBuf = pipe_user_buffer_create(pipe, (void *) ib->ptr, + ib->count * indexSize); indexOffset = 0; } @@ -380,7 +375,7 @@ st_draw_vbo(GLcontext *ctx, prims[i].start + indexOffset, prims[i].count); } - pipe_buffer_reference(winsys, &indexBuf, NULL); + pipe_reference_buffer(pipe, &indexBuf, NULL); } else { /* non-indexed */ @@ -396,7 +391,7 @@ st_draw_vbo(GLcontext *ctx, /* unreference buffers (frees wrapped user-space buffer objects) */ for (attr = 0; attr < vp->num_inputs; attr++) { - pipe_buffer_reference(winsys, &vbuffer[attr].buffer, NULL); + pipe_reference_buffer(pipe, &vbuffer[attr].buffer, NULL); assert(!vbuffer[attr].buffer); } pipe->set_vertex_buffers(pipe, vp->num_inputs, vbuffer); @@ -458,7 +453,6 @@ st_feedback_draw_vbo(GLcontext *ctx, struct st_context *st = ctx->st; struct pipe_context *pipe = st->pipe; struct draw_context *draw = st->draw; - struct pipe_winsys *winsys = pipe->winsys; const struct st_vertex_program *vp; const struct pipe_shader_state *vs; struct pipe_buffer *index_buffer_handle = 0; @@ -509,7 +503,7 @@ st_feedback_draw_vbo(GLcontext *ctx, assert(stobj->buffer); vbuffers[attr].buffer = NULL; - pipe_buffer_reference(winsys, &vbuffers[attr].buffer, stobj->buffer); + pipe_reference_buffer(pipe, &vbuffers[attr].buffer, stobj->buffer); vbuffers[attr].buffer_offset = (unsigned) arrays[0]->Ptr;/* in bytes */ velements[attr].src_offset = arrays[mesaAttr]->Ptr - arrays[0]->Ptr; } @@ -521,9 +515,8 @@ st_feedback_draw_vbo(GLcontext *ctx, /* wrap user data */ vbuffers[attr].buffer - = winsys->user_buffer_create(winsys, - (void *) arrays[mesaAttr]->Ptr, - bytes); + = pipe_user_buffer_create(pipe, (void *) arrays[mesaAttr]->Ptr, + bytes); vbuffers[attr].buffer_offset = 0; velements[attr].src_offset = 0; } @@ -544,9 +537,8 @@ st_feedback_draw_vbo(GLcontext *ctx, #endif /* map the attrib buffer */ - map = pipe->winsys->buffer_map(pipe->winsys, - vbuffers[attr].buffer, - PIPE_BUFFER_USAGE_CPU_READ); + map = pipe_buffer_map(pipe, vbuffers[attr].buffer, + PIPE_BUFFER_USAGE_CPU_READ); draw_set_mapped_vertex_buffer(draw, attr, map); } @@ -572,9 +564,8 @@ st_feedback_draw_vbo(GLcontext *ctx, return; } - map = pipe->winsys->buffer_map(pipe->winsys, - index_buffer_handle, - PIPE_BUFFER_USAGE_CPU_READ); + map = pipe_buffer_map(pipe, index_buffer_handle, + PIPE_BUFFER_USAGE_CPU_READ); draw_set_mapped_element_buffer(draw, indexSize, map); } else { @@ -584,7 +575,7 @@ st_feedback_draw_vbo(GLcontext *ctx, /* map constant buffers */ - mapped_constants = winsys->buffer_map(winsys, + mapped_constants = pipe_buffer_map(pipe, st->state.constants[PIPE_SHADER_VERTEX].buffer, PIPE_BUFFER_USAGE_CPU_READ); draw_set_mapped_constant_buffer(st->draw, mapped_constants); @@ -597,21 +588,20 @@ st_feedback_draw_vbo(GLcontext *ctx, /* unmap constant buffers */ - winsys->buffer_unmap(winsys, st->state.constants[PIPE_SHADER_VERTEX].buffer); + pipe_buffer_unmap(pipe, st->state.constants[PIPE_SHADER_VERTEX].buffer); /* * unmap vertex/index buffers */ for (i = 0; i < PIPE_MAX_ATTRIBS; i++) { if (draw->pt.vertex_buffer[i].buffer) { - pipe->winsys->buffer_unmap(pipe->winsys, - draw->pt.vertex_buffer[i].buffer); - pipe_buffer_reference(winsys, &draw->pt.vertex_buffer[i].buffer, NULL); + pipe_buffer_unmap(pipe, draw->pt.vertex_buffer[i].buffer); + pipe_reference_buffer(pipe, &draw->pt.vertex_buffer[i].buffer, NULL); draw_set_mapped_vertex_buffer(draw, i, NULL); } } if (ib) { - pipe->winsys->buffer_unmap(pipe->winsys, index_buffer_handle); + pipe_buffer_unmap(pipe, index_buffer_handle); draw_set_mapped_element_buffer(draw, 0, NULL); } } diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c index da9ec12a4d..1a0e19c2f9 100644 --- a/src/mesa/state_tracker/st_gen_mipmap.c +++ b/src/mesa/state_tracker/st_gen_mipmap.c @@ -36,7 +36,6 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_inlines.h" -#include "pipe/p_winsys.h" #include "util/u_gen_mipmap.h" #include "cso_cache/cso_cache.h" @@ -105,7 +104,6 @@ fallback_generate_mipmap(GLcontext *ctx, GLenum target, { struct pipe_context *pipe = ctx->st->pipe; struct pipe_screen *screen = pipe->screen; - struct pipe_winsys *ws = pipe->winsys; struct pipe_texture *pt = st_get_texobj_texture(texObj); const uint baseLevel = texObj->BaseLevel; const uint lastLevel = pt->last_level; @@ -128,11 +126,11 @@ fallback_generate_mipmap(GLcontext *ctx, GLenum target, srcSurf = screen->get_tex_surface(screen, pt, face, srcLevel, zslice); dstSurf = screen->get_tex_surface(screen, pt, face, dstLevel, zslice); - srcData = (ubyte *) ws->buffer_map(ws, srcSurf->buffer, - PIPE_BUFFER_USAGE_CPU_READ) + srcData = (ubyte *) pipe_buffer_map(pipe, srcSurf->buffer, + PIPE_BUFFER_USAGE_CPU_READ) + srcSurf->offset; - dstData = (ubyte *) ws->buffer_map(ws, dstSurf->buffer, - PIPE_BUFFER_USAGE_CPU_WRITE) + dstData = (ubyte *) pipe_buffer_map(pipe, dstSurf->buffer, + PIPE_BUFFER_USAGE_CPU_WRITE) + dstSurf->offset; _mesa_generate_mipmap_level(target, datatype, comps, @@ -144,8 +142,8 @@ fallback_generate_mipmap(GLcontext *ctx, GLenum target, dstSurf->pitch * dstSurf->cpp, /* stride in bytes */ dstData); - ws->buffer_unmap(ws, srcSurf->buffer); - ws->buffer_unmap(ws, dstSurf->buffer); + pipe_buffer_unmap(pipe, srcSurf->buffer); + pipe_buffer_unmap(pipe, dstSurf->buffer); pipe_surface_reference(&srcSurf, NULL); pipe_surface_reference(&dstSurf, NULL); diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c index 66d81e2b95..f68bef1207 100644 --- a/src/mesa/state_tracker/st_texture.c +++ b/src/mesa/state_tracker/st_texture.c @@ -38,7 +38,6 @@ #include "pipe/p_inlines.h" #include "pipe/p_util.h" #include "pipe/p_inlines.h" -#include "pipe/p_winsys.h" #define DBG if(0) printf -- cgit v1.2.3 From c9ed86a96483063f3d6789ed16645a3dca77d726 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Thu, 1 May 2008 11:07:21 +0100 Subject: gallium: tex surface checkpoint --- src/gallium/auxiliary/draw/draw_pipe_aaline.c | 12 ++-- src/gallium/auxiliary/draw/draw_pipe_pstipple.c | 15 +++-- src/gallium/auxiliary/util/p_tile.c | 50 ++++++++++---- src/gallium/auxiliary/util/u_blit.c | 3 +- src/gallium/auxiliary/util/u_gen_mipmap.c | 21 ++++-- src/gallium/drivers/failover/fo_context.c | 2 +- src/gallium/drivers/i915simple/i915_screen.c | 31 +++++++++ src/gallium/drivers/i915simple/i915_surface.c | 23 +++++-- src/gallium/drivers/i915simple/i915_texture.c | 13 ++-- src/gallium/drivers/i965simple/brw_surface.c | 51 ++++++--------- src/gallium/drivers/i965simple/brw_tex_layout.c | 2 +- src/gallium/drivers/softpipe/sp_context.c | 6 +- src/gallium/drivers/softpipe/sp_draw_arrays.c | 6 +- src/gallium/drivers/softpipe/sp_flush.c | 35 +++++----- src/gallium/drivers/softpipe/sp_screen.c | 22 ++++--- src/gallium/drivers/softpipe/sp_surface.c | 23 +++++-- src/gallium/drivers/softpipe/sp_texture.c | 87 ++++++++++++++++++------- src/gallium/drivers/softpipe/sp_texture.h | 1 - src/gallium/drivers/softpipe/sp_tile_cache.c | 36 ++++++---- src/gallium/drivers/softpipe/sp_tile_cache.h | 2 +- src/gallium/include/pipe/p_context.h | 6 -- src/gallium/include/pipe/p_inlines.h | 31 ++++----- src/gallium/include/pipe/p_screen.h | 17 ++++- src/gallium/include/pipe/p_state.h | 4 ++ src/gallium/include/pipe/p_util.h | 3 + src/gallium/include/pipe/p_winsys.h | 2 +- src/gallium/winsys/xlib/xm_winsys.c | 2 + src/mesa/state_tracker/st_atom_pixeltransfer.c | 9 +-- src/mesa/state_tracker/st_cb_accum.c | 12 ++-- src/mesa/state_tracker/st_cb_bitmap.c | 23 +++++-- src/mesa/state_tracker/st_cb_drawpixels.c | 56 +++++++++------- src/mesa/state_tracker/st_cb_fbo.c | 27 +++++--- src/mesa/state_tracker/st_cb_readpixels.c | 5 +- src/mesa/state_tracker/st_cb_texture.c | 48 +++++++------- src/mesa/state_tracker/st_gen_mipmap.c | 6 +- src/mesa/state_tracker/st_texture.c | 34 ++++++---- src/mesa/state_tracker/st_texture.h | 6 +- 37 files changed, 465 insertions(+), 267 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/gallium/auxiliary/draw/draw_pipe_aaline.c b/src/gallium/auxiliary/draw/draw_pipe_aaline.c index f501b2aed4..6dc20f2c90 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_aaline.c +++ b/src/gallium/auxiliary/draw/draw_pipe_aaline.c @@ -415,8 +415,11 @@ aaline_create_texture(struct aaline_stage *aaline) assert(aaline->texture->width[level] == aaline->texture->height[level]); - surface = screen->get_tex_surface(screen, aaline->texture, 0, level, 0); - data = pipe_surface_map(surface); + /* This texture is new, no need to flush. + */ + surface = screen->get_tex_surface(screen, aaline->texture, 0, level, 0, + PIPE_BUFFER_USAGE_CPU_WRITE); + data = screen->surface_map(screen, surface, PIPE_BUFFER_USAGE_CPU_WRITE); if (data == NULL) return FALSE; @@ -440,9 +443,8 @@ aaline_create_texture(struct aaline_stage *aaline) } /* unmap */ - pipe_surface_unmap(surface); - pipe_surface_reference(&surface, NULL); - pipe->texture_update(pipe, aaline->texture, 0, (1 << level)); + screen->surface_unmap(screen, surface); + screen->tex_surface_release(screen, &surface); } return TRUE; } diff --git a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c index c4de9d2698..3aa326acc7 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c +++ b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c @@ -376,8 +376,14 @@ pstip_update_texture(struct pstip_stage *pstip) uint i, j; ubyte *data; - surface = screen->get_tex_surface(screen, pstip->texture, 0, 0, 0); - data = pipe_surface_map(surface); + /* XXX: want to avoid flushing just because we use stipple: + */ + pipe->flush( pipe, PIPE_FLUSH_TEXTURE_CACHE, NULL ); + + surface = screen->get_tex_surface(screen, pstip->texture, 0, 0, 0, + PIPE_BUFFER_USAGE_CPU_WRITE); + data = screen->surface_map(screen, surface, + PIPE_BUFFER_USAGE_CPU_WRITE); /* * Load alpha texture. @@ -399,9 +405,8 @@ pstip_update_texture(struct pstip_stage *pstip) } /* unmap */ - pipe_surface_unmap(surface); - pipe_surface_reference(&surface, NULL); - pipe->texture_update(pipe, pstip->texture, 0, 0x1); + screen->surface_unmap(screen, surface); + screen->tex_surface_release(screen, &surface); } diff --git a/src/gallium/auxiliary/util/p_tile.c b/src/gallium/auxiliary/util/p_tile.c index 63e1cc6013..5728757d2f 100644 --- a/src/gallium/auxiliary/util/p_tile.c +++ b/src/gallium/auxiliary/util/p_tile.c @@ -50,6 +50,7 @@ pipe_get_tile_raw(struct pipe_context *pipe, uint x, uint y, uint w, uint h, void *p, int dst_stride) { + struct pipe_screen *screen = pipe->screen; const uint cpp = ps->cpp; const ubyte *pSrc; const uint src_stride = ps->pitch * cpp; @@ -63,7 +64,11 @@ pipe_get_tile_raw(struct pipe_context *pipe, if (pipe_clip_tile(x, y, &w, &h, ps)) return; - pSrc = (const ubyte *) pipe_surface_map(ps) + (y * ps->pitch + x) * cpp; + pSrc = (const ubyte *) screen->surface_map(screen, ps, + PIPE_BUFFER_USAGE_CPU_READ); + assert(pSrc); /* XXX: proper error handling! */ + + pSrc += (y * ps->pitch + x) * cpp; pDest = (ubyte *) p; for (i = 0; i < h; i++) { @@ -72,7 +77,7 @@ pipe_get_tile_raw(struct pipe_context *pipe, pSrc += src_stride; } - pipe_surface_unmap(ps); + screen->surface_unmap(screen, ps); } @@ -86,6 +91,7 @@ pipe_put_tile_raw(struct pipe_context *pipe, uint x, uint y, uint w, uint h, const void *p, int src_stride) { + struct pipe_screen *screen = pipe->screen; const uint cpp = ps->cpp; const ubyte *pSrc; const uint dst_stride = ps->pitch * cpp; @@ -100,7 +106,11 @@ pipe_put_tile_raw(struct pipe_context *pipe, return; pSrc = (const ubyte *) p; - pDest = (ubyte *) pipe_surface_map(ps) + (y * ps->pitch + x) * cpp; + + pDest = screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_WRITE); + assert(pDest); /* XXX: proper error handling */ + + pDest += (y * ps->pitch + x) * cpp; for (i = 0; i < h; i++) { memcpy(pDest, pSrc, w * cpp); @@ -108,7 +118,7 @@ pipe_put_tile_raw(struct pipe_context *pipe, pSrc += src_stride; } - pipe_surface_unmap(ps); + screen->surface_unmap(screen, ps); } @@ -834,18 +844,26 @@ pipe_get_tile_z(struct pipe_context *pipe, uint x, uint y, uint w, uint h, uint *z) { + struct pipe_screen *screen = pipe->screen; const uint dstStride = w; + void *map; uint *pDest = z; uint i, j; if (pipe_clip_tile(x, y, &w, &h, ps)) return; + map = screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_READ); + if (!map) { + assert(0); + return; + } + switch (ps->format) { case PIPE_FORMAT_Z32_UNORM: { const uint *pSrc - = (const uint *) pipe_surface_map(ps) + (y * ps->pitch + x); + = (const uint *)map + (y * ps->pitch + x); for (i = 0; i < h; i++) { memcpy(pDest, pSrc, 4 * w); pDest += dstStride; @@ -857,7 +875,7 @@ pipe_get_tile_z(struct pipe_context *pipe, case PIPE_FORMAT_X8Z24_UNORM: { const uint *pSrc - = (const uint *) pipe_surface_map(ps) + (y * ps->pitch + x); + = (const uint *)map + (y * ps->pitch + x); for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { /* convert 24-bit Z to 32-bit Z */ @@ -871,7 +889,7 @@ pipe_get_tile_z(struct pipe_context *pipe, case PIPE_FORMAT_Z16_UNORM: { const ushort *pSrc - = (const ushort *) pipe_surface_map(ps) + (y * ps->pitch + x); + = (const ushort *)map + (y * ps->pitch + x); for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { /* convert 16-bit Z to 32-bit Z */ @@ -886,7 +904,7 @@ pipe_get_tile_z(struct pipe_context *pipe, assert(0); } - pipe_surface_unmap(ps); + screen->surface_unmap(screen, ps); } @@ -896,17 +914,25 @@ pipe_put_tile_z(struct pipe_context *pipe, uint x, uint y, uint w, uint h, const uint *zSrc) { + struct pipe_screen *screen = pipe->screen; const uint srcStride = w; const uint *pSrc = zSrc; + void *map; uint i, j; if (pipe_clip_tile(x, y, &w, &h, ps)) return; + map = screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_WRITE); + if (!map) { + assert(0); + return; + } + switch (ps->format) { case PIPE_FORMAT_Z32_UNORM: { - uint *pDest = (uint *) pipe_surface_map(ps) + (y * ps->pitch + x); + uint *pDest = (uint *) map + (y * ps->pitch + x); for (i = 0; i < h; i++) { memcpy(pDest, pSrc, 4 * w); pDest += ps->pitch; @@ -917,7 +943,7 @@ pipe_put_tile_z(struct pipe_context *pipe, case PIPE_FORMAT_S8Z24_UNORM: case PIPE_FORMAT_X8Z24_UNORM: { - uint *pDest = (uint *) pipe_surface_map(ps) + (y * ps->pitch + x); + uint *pDest = (uint *) map + (y * ps->pitch + x); for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { /* convert 32-bit Z to 24-bit Z (0 stencil) */ @@ -930,7 +956,7 @@ pipe_put_tile_z(struct pipe_context *pipe, break; case PIPE_FORMAT_Z16_UNORM: { - ushort *pDest = (ushort *) pipe_surface_map(ps) + (y * ps->pitch + x); + ushort *pDest = (ushort *) map + (y * ps->pitch + x); for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { /* convert 32-bit Z to 16-bit Z */ @@ -945,7 +971,7 @@ pipe_put_tile_z(struct pipe_context *pipe, assert(0); } - pipe_surface_unmap(ps); + screen->surface_unmap(screen, ps); } diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c index 9e9912c6e4..257473ab26 100644 --- a/src/gallium/auxiliary/util/u_blit.c +++ b/src/gallium/auxiliary/util/u_blit.c @@ -287,7 +287,8 @@ util_blit_pixels(struct blit_state *ctx, if (!tex) return; - texSurf = screen->get_tex_surface(screen, tex, 0, 0, 0); + texSurf = screen->get_tex_surface(screen, tex, 0, 0, 0, + PIPE_BUFFER_USAGE_GPU_WRITE); /* load temp texture */ pipe->surface_copy(pipe, FALSE, diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c index 0348629ab8..6ed5503c9a 100644 --- a/src/gallium/auxiliary/util/u_gen_mipmap.c +++ b/src/gallium/auxiliary/util/u_gen_mipmap.c @@ -586,8 +586,11 @@ make_1d_mipmap(struct gen_mipmap_state *ctx, struct pipe_surface *srcSurf, *dstSurf; void *srcMap, *dstMap; - srcSurf = screen->get_tex_surface(screen, pt, face, srcLevel, zslice); - dstSurf = screen->get_tex_surface(screen, pt, face, dstLevel, zslice); + srcSurf = screen->get_tex_surface(screen, pt, face, srcLevel, zslice, + PIPE_BUFFER_USAGE_CPU_READ); + + dstSurf = screen->get_tex_surface(screen, pt, face, dstLevel, zslice, + PIPE_BUFFER_USAGE_CPU_WRITE); srcMap = ((ubyte *) winsys->buffer_map(winsys, srcSurf->buffer, PIPE_BUFFER_USAGE_CPU_READ) @@ -626,8 +629,10 @@ make_2d_mipmap(struct gen_mipmap_state *ctx, struct pipe_surface *srcSurf, *dstSurf; ubyte *srcMap, *dstMap; - srcSurf = screen->get_tex_surface(screen, pt, face, srcLevel, zslice); - dstSurf = screen->get_tex_surface(screen, pt, face, dstLevel, zslice); + srcSurf = screen->get_tex_surface(screen, pt, face, srcLevel, zslice, + PIPE_BUFFER_USAGE_CPU_READ); + dstSurf = screen->get_tex_surface(screen, pt, face, dstLevel, zslice, + PIPE_BUFFER_USAGE_CPU_WRITE); srcMap = ((ubyte *) winsys->buffer_map(winsys, srcSurf->buffer, PIPE_BUFFER_USAGE_CPU_READ) @@ -888,10 +893,14 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, for (dstLevel = baseLevel + 1; dstLevel <= lastLevel; dstLevel++) { const uint srcLevel = dstLevel - 1; + struct pipe_surface *surf = + screen->get_tex_surface(screen, pt, face, dstLevel, zslice, + PIPE_BUFFER_USAGE_GPU_WRITE); + /* * Setup framebuffer / dest surface */ - fb.cbufs[0] = screen->get_tex_surface(screen, pt, face, dstLevel, zslice); + fb.cbufs[0] = surf; fb.width = pt->width[dstLevel]; fb.height = pt->height[dstLevel]; cso_set_framebuffer(ctx->cso, &fb); @@ -922,7 +931,7 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); /* need to signal that the texture has changed _after_ rendering to it */ - pipe->texture_update(pipe, pt, face, (1 << dstLevel)); + pipe_surface_reference( &surf, NULL ); } /* restore state we changed */ diff --git a/src/gallium/drivers/failover/fo_context.c b/src/gallium/drivers/failover/fo_context.c index cb95ba516f..014a3e31d5 100644 --- a/src/gallium/drivers/failover/fo_context.c +++ b/src/gallium/drivers/failover/fo_context.c @@ -147,8 +147,8 @@ struct pipe_context *failover_create( struct pipe_context *hw, failover->pipe.texture_create = hw->texture_create; failover->pipe.texture_release = hw->texture_release; failover->pipe.get_tex_surface = hw->get_tex_surface; -#endif failover->pipe.texture_update = hw->texture_update; +#endif failover->pipe.flush = hw->flush; diff --git a/src/gallium/drivers/i915simple/i915_screen.c b/src/gallium/drivers/i915simple/i915_screen.c index 631642e1b6..dcd349e478 100644 --- a/src/gallium/drivers/i915simple/i915_screen.c +++ b/src/gallium/drivers/i915simple/i915_screen.c @@ -200,6 +200,35 @@ i915_destroy_screen( struct pipe_screen *screen ) } +static void * +i915_surface_map( struct pipe_screen *screen, + struct pipe_surface *surface, + unsigned flags ) +{ + char *map = screen->winsys->buffer_map( screen->winsys, surface->buffer, flags ); + if (map == NULL) + return NULL; + + if (surface->texture && + (flags & PIPE_BUFFER_USAGE_CPU_WRITE)) + { + /* Do something to notify contexts of a texture change. + */ + /* i915_screen(screen)->timestamp++; */ + } + + return map + surface->offset; +} + +static void +i915_surface_unmap(struct pipe_screen *screen, + struct pipe_surface *surface) +{ + screen->winsys->buffer_unmap( screen->winsys, surface->buffer ); +} + + + /** * Create a new i915_screen object */ @@ -243,6 +272,8 @@ i915_create_screen(struct pipe_winsys *winsys, uint pci_id) i915screen->screen.get_param = i915_get_param; i915screen->screen.get_paramf = i915_get_paramf; i915screen->screen.is_format_supported = i915_is_format_supported; + i915screen->screen.surface_map = i915_surface_map; + i915screen->screen.surface_unmap = i915_surface_unmap; i915_init_screen_texture_functions(&i915screen->screen); diff --git a/src/gallium/drivers/i915simple/i915_surface.c b/src/gallium/drivers/i915simple/i915_surface.c index f4fbedbe9b..98367ac073 100644 --- a/src/gallium/drivers/i915simple/i915_surface.c +++ b/src/gallium/drivers/i915simple/i915_surface.c @@ -51,17 +51,25 @@ i915_surface_copy(struct pipe_context *pipe, assert( dst->cpp == src->cpp ); if (0) { - pipe_copy_rect(pipe_surface_map(dst), + void *dst_map = pipe->screen->surface_map( pipe->screen, + dst, + PIPE_BUFFER_USAGE_CPU_WRITE ); + + const void *src_map = pipe->screen->surface_map( pipe->screen, + src, + PIPE_BUFFER_USAGE_CPU_READ ); + + pipe_copy_rect(dst_map, dst->cpp, dst->pitch, dstx, dsty, width, height, - pipe_surface_map(src), + src_map, do_flip ? -(int) src->pitch : src->pitch, srcx, do_flip ? 1 - srcy - height : srcy); - pipe_surface_unmap(src); - pipe_surface_unmap(dst); + pipe->screen->surface_unmap(pipe->screen, src); + pipe->screen->surface_unmap(pipe->screen, dst); } else { i915_copy_blit( i915_context(pipe), @@ -92,7 +100,10 @@ i915_surface_fill(struct pipe_context *pipe, { if (0) { unsigned i, j; - void *dst_map = pipe_surface_map(dst); + void *dst_map = pipe->screen->surface_map( pipe->screen, + dst, + PIPE_BUFFER_USAGE_CPU_WRITE ); + switch (dst->cpp) { case 1: { @@ -126,7 +137,7 @@ i915_surface_fill(struct pipe_context *pipe, break; } - pipe_surface_unmap( dst ); + pipe->screen->surface_unmap(pipe->screen, dst); } else { i915_fill_blit( i915_context(pipe), diff --git a/src/gallium/drivers/i915simple/i915_texture.c b/src/gallium/drivers/i915simple/i915_texture.c index c39e747705..7b9359a0fe 100644 --- a/src/gallium/drivers/i915simple/i915_texture.c +++ b/src/gallium/drivers/i915simple/i915_texture.c @@ -541,13 +541,6 @@ i915_texture_release_screen(struct pipe_screen *screen, } -static void -i915_texture_update(struct pipe_context *pipe, struct pipe_texture *texture, - uint face, uint levelsMask) -{ - /* no-op? */ -} - /* * XXX note: same as code in sp_surface.c @@ -555,7 +548,8 @@ i915_texture_update(struct pipe_context *pipe, struct pipe_texture *texture, static struct pipe_surface * i915_get_tex_surface_screen(struct pipe_screen *screen, struct pipe_texture *pt, - unsigned face, unsigned level, unsigned zslice) + unsigned face, unsigned level, unsigned zslice, + unsigned flags) { struct i915_texture *tex = (struct i915_texture *)pt; struct pipe_winsys *ws = screen->winsys; @@ -586,6 +580,7 @@ i915_get_tex_surface_screen(struct pipe_screen *screen, ps->height = pt->height[level]; ps->pitch = tex->pitch; ps->offset = offset; + ps->usage = flags; } return ps; } @@ -594,7 +589,7 @@ i915_get_tex_surface_screen(struct pipe_screen *screen, void i915_init_texture_functions(struct i915_context *i915) { - i915->pipe.texture_update = i915_texture_update; +// i915->pipe.texture_update = i915_texture_update; } diff --git a/src/gallium/drivers/i965simple/brw_surface.c b/src/gallium/drivers/i965simple/brw_surface.c index c99a91dcf7..3e3736b280 100644 --- a/src/gallium/drivers/i965simple/brw_surface.c +++ b/src/gallium/drivers/i965simple/brw_surface.c @@ -35,27 +35,6 @@ #include "util/p_tile.h" -/* Upload data to a rectangular sub-region. Lots of choices how to do this: - * - * - memcpy by span to current destination - * - upload data as new buffer and blit - * - * Currently always memcpy. - */ -static void -brw_surface_data(struct pipe_context *pipe, - struct pipe_surface *dst, - unsigned dstx, unsigned dsty, - const void *src, unsigned src_pitch, - unsigned srcx, unsigned srcy, unsigned width, unsigned height) -{ - pipe_copy_rect(pipe_surface_map(dst) + dst->offset, - dst->cpp, dst->pitch, - dstx, dsty, width, height, src, src_pitch, srcx, srcy); - - pipe_surface_unmap(dst); -} - /* Assumes all values are within bounds -- no checking at this level - * do it higher up if required. @@ -72,17 +51,25 @@ brw_surface_copy(struct pipe_context *pipe, assert(dst->cpp == src->cpp); if (0) { - pipe_copy_rect(pipe_surface_map(dst) + dst->offset, + void *dst_map = pipe->screen->surface_map( pipe->screen, + dst, + PIPE_BUFFER_USAGE_CPU_WRITE ); + + const void *src_map = pipe->screen->surface_map( pipe->screen, + src, + PIPE_BUFFER_USAGE_CPU_READ ); + + pipe_copy_rect(dst_map, dst->cpp, dst->pitch, - dstx, dsty, - width, height, - pipe_surface_map(src) + src->offset, - do_flip ? -src->pitch : src->pitch, + dstx, dsty, + width, height, + src_map, + do_flip ? -(int) src->pitch : src->pitch, srcx, do_flip ? 1 - srcy - height : srcy); - pipe_surface_unmap(src); - pipe_surface_unmap(dst); + pipe->screen->surface_unmap(pipe->screen, src); + pipe->screen->surface_unmap(pipe->screen, dst); } else { brw_copy_blit(brw_context(pipe), @@ -113,7 +100,10 @@ brw_surface_fill(struct pipe_context *pipe, { if (0) { unsigned i, j; - void *dst_map = pipe_surface_map(dst); + void *dst_map = pipe->screen->surface_map( pipe->screen, + dst, + PIPE_BUFFER_USAGE_CPU_WRITE ); + switch (dst->cpp) { case 1: { @@ -147,7 +137,7 @@ brw_surface_fill(struct pipe_context *pipe, break; } - pipe_surface_unmap( dst ); + pipe->screen->surface_unmap(pipe->screen, dst); } else { brw_fill_blit(brw_context(pipe), @@ -164,7 +154,6 @@ brw_surface_fill(struct pipe_context *pipe, void brw_init_surface_functions(struct brw_context *brw) { - (void) brw_surface_data; /* silence warning */ brw->pipe.surface_copy = brw_surface_copy; brw->pipe.surface_fill = brw_surface_fill; } diff --git a/src/gallium/drivers/i965simple/brw_tex_layout.c b/src/gallium/drivers/i965simple/brw_tex_layout.c index b580f98204..ba4c4a7bcf 100644 --- a/src/gallium/drivers/i965simple/brw_tex_layout.c +++ b/src/gallium/drivers/i965simple/brw_tex_layout.c @@ -407,7 +407,7 @@ brw_get_tex_surface_screen(struct pipe_screen *screen, void brw_init_texture_functions(struct brw_context *brw) { - brw->pipe.texture_update = brw_texture_update; +// brw->pipe.texture_update = brw_texture_update; } diff --git a/src/gallium/drivers/softpipe/sp_context.c b/src/gallium/drivers/softpipe/sp_context.c index edf91ecafa..ee74826763 100644 --- a/src/gallium/drivers/softpipe/sp_context.c +++ b/src/gallium/drivers/softpipe/sp_context.c @@ -192,11 +192,11 @@ softpipe_create( struct pipe_screen *screen, * Must be before quad stage setup! */ for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) - softpipe->cbuf_cache[i] = sp_create_tile_cache(); - softpipe->zsbuf_cache = sp_create_tile_cache(); + softpipe->cbuf_cache[i] = sp_create_tile_cache( screen ); + softpipe->zsbuf_cache = sp_create_tile_cache( screen ); for (i = 0; i < PIPE_MAX_SAMPLERS; i++) - softpipe->tex_cache[i] = sp_create_tile_cache(); + softpipe->tex_cache[i] = sp_create_tile_cache( screen ); /* setup quad rendering stages */ diff --git a/src/gallium/drivers/softpipe/sp_draw_arrays.c b/src/gallium/drivers/softpipe/sp_draw_arrays.c index 6c58f9909d..355c120d18 100644 --- a/src/gallium/drivers/softpipe/sp_draw_arrays.c +++ b/src/gallium/drivers/softpipe/sp_draw_arrays.c @@ -50,7 +50,7 @@ softpipe_map_constant_buffers(struct softpipe_context *sp) for (i = 0; i < 2; i++) { if (sp->constants[i].size) sp->mapped_constants[i] = ws->buffer_map(ws, sp->constants[i].buffer, - PIPE_BUFFER_USAGE_CPU_READ); + PIPE_BUFFER_USAGE_GPU_READ); } draw_set_mapped_constant_buffer(sp->draw, @@ -133,14 +133,14 @@ softpipe_draw_elements(struct pipe_context *pipe, void *buf = pipe->winsys->buffer_map(pipe->winsys, sp->vertex_buffer[i].buffer, - PIPE_BUFFER_USAGE_CPU_READ); + PIPE_BUFFER_USAGE_GPU_READ); draw_set_mapped_vertex_buffer(draw, i, buf); } /* Map index buffer, if present */ if (indexBuffer) { void *mapped_indexes = pipe->winsys->buffer_map(pipe->winsys, indexBuffer, - PIPE_BUFFER_USAGE_CPU_READ); + PIPE_BUFFER_USAGE_GPU_READ); draw_set_mapped_element_buffer(draw, indexSize, mapped_indexes); } else { diff --git a/src/gallium/drivers/softpipe/sp_flush.c b/src/gallium/drivers/softpipe/sp_flush.c index 0625b69099..e03994b63b 100644 --- a/src/gallium/drivers/softpipe/sp_flush.c +++ b/src/gallium/drivers/softpipe/sp_flush.c @@ -50,25 +50,28 @@ softpipe_flush( struct pipe_context *pipe, draw_flush(softpipe->draw); - /* - flush the quad pipeline - * - flush the texture cache - * - flush the render cache - */ + if (flags & PIPE_FLUSH_TEXTURE_CACHE) { + for (i = 0; i < softpipe->num_textures; i++) { + sp_flush_tile_cache(softpipe, softpipe->tex_cache[i]); + } + } - for (i = 0; i < softpipe->framebuffer.num_cbufs; i++) - if (softpipe->cbuf_cache[i]) - sp_flush_tile_cache(softpipe, softpipe->cbuf_cache[i]); + if (flags & PIPE_FLUSH_RENDER_CACHE) { + for (i = 0; i < softpipe->framebuffer.num_cbufs; i++) + if (softpipe->cbuf_cache[i]) + sp_flush_tile_cache(softpipe, softpipe->cbuf_cache[i]); - if (softpipe->zsbuf_cache) - sp_flush_tile_cache(softpipe, softpipe->zsbuf_cache); + if (softpipe->zsbuf_cache) + sp_flush_tile_cache(softpipe, softpipe->zsbuf_cache); - /* Need this call for hardware buffers before swapbuffers. - * - * there should probably be another/different flush-type function - * that's called before swapbuffers because we don't always want - * to unmap surfaces when flushing. - */ - softpipe_unmap_surfaces(softpipe); + /* Need this call for hardware buffers before swapbuffers. + * + * there should probably be another/different flush-type function + * that's called before swapbuffers because we don't always want + * to unmap surfaces when flushing. + */ + softpipe_unmap_surfaces(softpipe); + } if (fence) *fence = NULL; diff --git a/src/gallium/drivers/softpipe/sp_screen.c b/src/gallium/drivers/softpipe/sp_screen.c index 7dacb1c461..e9926bf41f 100644 --- a/src/gallium/drivers/softpipe/sp_screen.c +++ b/src/gallium/drivers/softpipe/sp_screen.c @@ -33,6 +33,7 @@ #include "sp_texture.h" #include "sp_winsys.h" +#include "sp_screen.h" static const char * @@ -137,6 +138,7 @@ softpipe_destroy_screen( struct pipe_screen *screen ) } + /** * Create a new pipe_screen object * Note: we're not presently subclassing pipe_screen (no softpipe_screen). @@ -144,22 +146,22 @@ softpipe_destroy_screen( struct pipe_screen *screen ) struct pipe_screen * softpipe_create_screen(struct pipe_winsys *winsys) { - struct pipe_screen *screen = CALLOC_STRUCT(pipe_screen); + struct softpipe_screen *screen = CALLOC_STRUCT(softpipe_screen); if (!screen) return NULL; - screen->winsys = winsys; + screen->base.winsys = winsys; - screen->destroy = softpipe_destroy_screen; + screen->base.destroy = softpipe_destroy_screen; - screen->get_name = softpipe_get_name; - screen->get_vendor = softpipe_get_vendor; - screen->get_param = softpipe_get_param; - screen->get_paramf = softpipe_get_paramf; - screen->is_format_supported = softpipe_is_format_supported; + screen->base.get_name = softpipe_get_name; + screen->base.get_vendor = softpipe_get_vendor; + screen->base.get_param = softpipe_get_param; + screen->base.get_paramf = softpipe_get_paramf; + screen->base.is_format_supported = softpipe_is_format_supported; - softpipe_init_screen_texture_funcs(screen); + softpipe_init_screen_texture_funcs(&screen->base); - return screen; + return &screen->base; } diff --git a/src/gallium/drivers/softpipe/sp_surface.c b/src/gallium/drivers/softpipe/sp_surface.c index 653449c4f1..b5cc053548 100644 --- a/src/gallium/drivers/softpipe/sp_surface.c +++ b/src/gallium/drivers/softpipe/sp_surface.c @@ -47,18 +47,27 @@ sp_surface_copy(struct pipe_context *pipe, unsigned srcx, unsigned srcy, unsigned width, unsigned height) { assert( dst->cpp == src->cpp ); + void *dst_map = pipe->screen->surface_map( pipe->screen, + dst, + PIPE_BUFFER_USAGE_GPU_WRITE ); - pipe_copy_rect(pipe_surface_map(dst), + const void *src_map = pipe->screen->surface_map( pipe->screen, + src, + PIPE_BUFFER_USAGE_GPU_READ ); + + assert(src_map && dst_map); + + pipe_copy_rect(dst_map, dst->cpp, dst->pitch, dstx, dsty, width, height, - pipe_surface_map(src), + src_map, do_flip ? -(int) src->pitch : src->pitch, srcx, do_flip ? 1 - srcy - height : srcy); - pipe_surface_unmap(src); - pipe_surface_unmap(dst); + pipe->screen->surface_unmap(pipe->screen, src); + pipe->screen->surface_unmap(pipe->screen, dst); } @@ -83,7 +92,9 @@ sp_surface_fill(struct pipe_context *pipe, unsigned width, unsigned height, unsigned value) { unsigned i, j; - void *dst_map = pipe_surface_map(dst); + void *dst_map = pipe->screen->surface_map( pipe->screen, + dst, + PIPE_BUFFER_USAGE_GPU_WRITE ); assert(dst->pitch > 0); assert(width <= dst->pitch); @@ -147,7 +158,7 @@ sp_surface_fill(struct pipe_context *pipe, break; } - pipe_surface_unmap( dst ); + pipe->screen->surface_unmap(pipe->screen, dst); } diff --git a/src/gallium/drivers/softpipe/sp_texture.c b/src/gallium/drivers/softpipe/sp_texture.c index 256586ec88..ee3fa994f9 100644 --- a/src/gallium/drivers/softpipe/sp_texture.c +++ b/src/gallium/drivers/softpipe/sp_texture.c @@ -40,6 +40,7 @@ #include "sp_state.h" #include "sp_texture.h" #include "sp_tile_cache.h" +#include "sp_screen.h" /* Simple, maximally packed layout. @@ -116,19 +117,10 @@ softpipe_texture_release(struct pipe_screen *screen, if (!*pt) return; - /* - DBG("%s %p refcount will be %d\n", - __FUNCTION__, (void *) *pt, (*pt)->refcount - 1); - */ if (--(*pt)->refcount <= 0) { struct softpipe_texture *spt = softpipe_texture(*pt); - /* - DBG("%s deleting %p\n", __FUNCTION__, (void *) spt); - */ - pipe_buffer_reference(screen->winsys, &spt->buffer, NULL); - FREE(spt); } *pt = NULL; @@ -138,7 +130,8 @@ softpipe_texture_release(struct pipe_screen *screen, static struct pipe_surface * softpipe_get_tex_surface(struct pipe_screen *screen, struct pipe_texture *pt, - unsigned face, unsigned level, unsigned zslice) + unsigned face, unsigned level, unsigned zslice, + unsigned usage) { struct pipe_winsys *ws = screen->winsys; struct softpipe_texture *spt = softpipe_texture(pt); @@ -157,6 +150,7 @@ softpipe_get_tex_surface(struct pipe_screen *screen, ps->height = pt->height[level]; ps->pitch = ps->width; ps->offset = spt->level_offset[level]; + ps->usage = usage; if (pt->target == PIPE_TEXTURE_CUBE || pt->target == PIPE_TEXTURE_3D) { ps->offset += ((pt->target == PIPE_TEXTURE_CUBE) ? face : zslice) * @@ -167,30 +161,74 @@ softpipe_get_tex_surface(struct pipe_screen *screen, assert(face == 0); assert(zslice == 0); } + + if (usage & (PIPE_BUFFER_USAGE_CPU_WRITE | + PIPE_BUFFER_USAGE_GPU_WRITE)) { + /* XXX if writing to the texture, invalidate the texcache entries!!! */ + assert(0); + } } return ps; } -static void -softpipe_texture_update(struct pipe_context *pipe, - struct pipe_texture *texture, - uint face, uint levelsMask) +static void +softpipe_tex_surface_release(struct pipe_screen *screen, + struct pipe_surface **s) { - struct softpipe_context *softpipe = softpipe_context(pipe); - uint unit; - for (unit = 0; unit < softpipe->num_textures; unit++) { - if (softpipe->texture[unit] == texture) { - sp_flush_tile_cache(softpipe, softpipe->tex_cache[unit]); - } + /* Effectively do the texture_update work here - if texture images + * needed post-processing to put them into hardware layout, this is + * where it would happen. For softpipe, nothing to do. + */ + assert ((*s)->texture); + + screen->winsys->surface_release(screen->winsys, s); +} + + +static void * +softpipe_surface_map( struct pipe_screen *screen, + struct pipe_surface *surface, + unsigned flags ) +{ + ubyte *map; + + if (flags & ~surface->usage) { + assert(0); + return NULL; + } + + map = screen->winsys->buffer_map( screen->winsys, surface->buffer, flags ); + if (map == NULL) + return NULL; + + /* May want to different things here depending on read/write nature + * of the map: + */ + if (surface->texture && + (flags & PIPE_BUFFER_USAGE_GPU_WRITE)) + { + /* Do something to notify sharing contexts of a texture change. + * In softpipe, that would mean flushing the texture cache. + */ + softpipe_screen(screen)->timestamp++; } + + return map + surface->offset; +} + + +static void +softpipe_surface_unmap(struct pipe_screen *screen, + struct pipe_surface *surface) +{ + screen->winsys->buffer_unmap( screen->winsys, surface->buffer ); } void -softpipe_init_texture_funcs( struct softpipe_context *softpipe ) +softpipe_init_texture_funcs(struct softpipe_context *sp) { - softpipe->pipe.texture_update = softpipe_texture_update; } @@ -199,5 +237,10 @@ softpipe_init_screen_texture_funcs(struct pipe_screen *screen) { screen->texture_create = softpipe_texture_create; screen->texture_release = softpipe_texture_release; + screen->get_tex_surface = softpipe_get_tex_surface; + screen->tex_surface_release = softpipe_tex_surface_release; + + screen->surface_map = softpipe_surface_map; + screen->surface_unmap = softpipe_surface_unmap; } diff --git a/src/gallium/drivers/softpipe/sp_texture.h b/src/gallium/drivers/softpipe/sp_texture.h index a7322144e6..2ba093320d 100644 --- a/src/gallium/drivers/softpipe/sp_texture.h +++ b/src/gallium/drivers/softpipe/sp_texture.h @@ -61,7 +61,6 @@ softpipe_texture(struct pipe_texture *pt) extern void softpipe_init_texture_funcs( struct softpipe_context *softpipe ); - extern void softpipe_init_screen_texture_funcs(struct pipe_screen *screen); diff --git a/src/gallium/drivers/softpipe/sp_tile_cache.c b/src/gallium/drivers/softpipe/sp_tile_cache.c index a88aad5d09..a3fd375a2d 100644 --- a/src/gallium/drivers/softpipe/sp_tile_cache.c +++ b/src/gallium/drivers/softpipe/sp_tile_cache.c @@ -49,6 +49,7 @@ struct softpipe_tile_cache { + struct pipe_screen *screen; struct pipe_surface *surface; /**< the surface we're caching */ void *surface_map; struct pipe_texture *texture; /**< if caching a texture */ @@ -109,13 +110,14 @@ clear_clear_flag(uint *bitvec, int x, int y) struct softpipe_tile_cache * -sp_create_tile_cache(void) +sp_create_tile_cache( struct pipe_screen *screen ) { struct softpipe_tile_cache *tc; uint pos; tc = CALLOC_STRUCT( softpipe_tile_cache ); if (tc) { + tc->screen = screen; for (pos = 0; pos < NUM_ENTRIES; pos++) { tc->entries[pos].x = tc->entries[pos].y = -1; @@ -154,16 +156,17 @@ sp_tile_cache_set_surface(struct softpipe_tile_cache *tc, assert(!tc->texture); if (tc->surface_map) { - /*assert(tc->surface != ps);*/ - pipe_surface_unmap(tc->surface); + tc->screen->surface_unmap(tc->screen, tc->surface); tc->surface_map = NULL; } pipe_surface_reference(&tc->surface, ps); - if (ps) { - if (tc->surface_map) - tc->surface_map = pipe_surface_map(ps); + if (tc->surface) { + if (tc->surface_map) /* XXX: this is always NULL!? */ + tc->surface_map = tc->screen->surface_map(tc->screen, tc->surface, + PIPE_BUFFER_USAGE_GPU_READ | + PIPE_BUFFER_USAGE_GPU_WRITE); tc->depth_stencil = (ps->format == PIPE_FORMAT_S8Z24_UNORM || ps->format == PIPE_FORMAT_Z16_UNORM || @@ -187,10 +190,13 @@ void sp_tile_cache_map_surfaces(struct softpipe_tile_cache *tc) { if (tc->surface && !tc->surface_map) - tc->surface_map = pipe_surface_map(tc->surface); + tc->surface_map = tc->screen->surface_map(tc->screen, tc->surface, + PIPE_BUFFER_USAGE_GPU_WRITE | + PIPE_BUFFER_USAGE_GPU_READ); if (tc->tex_surf && !tc->tex_surf_map) - tc->tex_surf_map = pipe_surface_map(tc->tex_surf); + tc->tex_surf_map = tc->screen->surface_map(tc->screen, tc->tex_surf, + PIPE_BUFFER_USAGE_GPU_READ); } @@ -198,12 +204,12 @@ void sp_tile_cache_unmap_surfaces(struct softpipe_tile_cache *tc) { if (tc->surface_map) { - pipe_surface_unmap(tc->surface); + tc->screen->surface_unmap(tc->screen, tc->surface); tc->surface_map = NULL; } if (tc->tex_surf_map) { - pipe_surface_unmap(tc->tex_surf); + tc->screen->surface_unmap(tc->screen, tc->tex_surf); tc->tex_surf_map = NULL; } } @@ -224,7 +230,7 @@ sp_tile_cache_set_texture(struct pipe_context *pipe, pipe_texture_reference(&tc->texture, texture); if (tc->tex_surf_map) { - pipe_surface_unmap(tc->tex_surf); + tc->screen->surface_unmap(tc->screen, tc->tex_surf); tc->tex_surf_map = NULL; } pipe_surface_reference(&tc->tex_surf, NULL); @@ -514,10 +520,12 @@ sp_get_cached_tile_tex(struct pipe_context *pipe, /* get new surface (view into texture) */ if (tc->tex_surf_map) - pipe_surface_unmap(tc->tex_surf); + tc->screen->surface_unmap(tc->screen, tc->tex_surf); - tc->tex_surf = screen->get_tex_surface(screen, tc->texture, face, level, z); - tc->tex_surf_map = pipe_surface_map(tc->tex_surf); + tc->tex_surf = screen->get_tex_surface(screen, tc->texture, face, level, z, + PIPE_BUFFER_USAGE_GPU_READ); + tc->tex_surf_map = screen->surface_map(screen, tc->tex_surf, + PIPE_BUFFER_USAGE_GPU_READ); tc->tex_face = face; tc->tex_level = level; diff --git a/src/gallium/drivers/softpipe/sp_tile_cache.h b/src/gallium/drivers/softpipe/sp_tile_cache.h index 2631e29a3a..bc96c941f6 100644 --- a/src/gallium/drivers/softpipe/sp_tile_cache.h +++ b/src/gallium/drivers/softpipe/sp_tile_cache.h @@ -61,7 +61,7 @@ struct softpipe_cached_tile extern struct softpipe_tile_cache * -sp_create_tile_cache(void); +sp_create_tile_cache( struct pipe_screen *screen ); extern void sp_destroy_tile_cache(struct softpipe_tile_cache *tc); diff --git a/src/gallium/include/pipe/p_context.h b/src/gallium/include/pipe/p_context.h index f3a9c2cd8b..0f68f592f7 100644 --- a/src/gallium/include/pipe/p_context.h +++ b/src/gallium/include/pipe/p_context.h @@ -198,12 +198,6 @@ struct pipe_context { /*@}*/ - /** Called when texture data is changed */ - void (*texture_update)(struct pipe_context *pipe, - struct pipe_texture *texture, - uint face, uint dirtyLevelsMask); - - /** Flush rendering (flags = bitmask of PIPE_FLUSH_x tokens) */ void (*flush)( struct pipe_context *pipe, unsigned flags, diff --git a/src/gallium/include/pipe/p_inlines.h b/src/gallium/include/pipe/p_inlines.h index 8eb604e73f..592c3c87c2 100644 --- a/src/gallium/include/pipe/p_inlines.h +++ b/src/gallium/include/pipe/p_inlines.h @@ -39,20 +39,6 @@ extern "C" { #endif -static INLINE void * -pipe_surface_map(struct pipe_surface *surface) -{ - return (char *)surface->winsys->buffer_map( surface->winsys, surface->buffer, - PIPE_BUFFER_USAGE_CPU_WRITE | - PIPE_BUFFER_USAGE_CPU_READ ) - + surface->offset; -} - -static INLINE void -pipe_surface_unmap(struct pipe_surface *surface) -{ - surface->winsys->buffer_unmap( surface->winsys, surface->buffer ); -} /** * Set 'ptr' to point to 'surf' and update reference counting. @@ -66,9 +52,20 @@ pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf) if (surf) surf->refcount++; - if (*ptr /* && --(*ptr)->refcount == 0 */) { - struct pipe_winsys *winsys = (*ptr)->winsys; - winsys->surface_release(winsys, ptr); + if (*ptr) { + + /* There are currently two sorts of surfaces... This needs to be + * fixed so that all surfaces are views into a texture. + */ + if ((*ptr)->texture) { + struct pipe_screen *screen = (*ptr)->texture->screen; + screen->tex_surface_release( screen, ptr ); + } + else { + struct pipe_winsys *winsys = (*ptr)->winsys; + winsys->surface_release(winsys, ptr); + } + assert(!*ptr); } diff --git a/src/gallium/include/pipe/p_screen.h b/src/gallium/include/pipe/p_screen.h index 26ac99d287..c080579c26 100644 --- a/src/gallium/include/pipe/p_screen.h +++ b/src/gallium/include/pipe/p_screen.h @@ -96,7 +96,22 @@ struct pipe_screen { struct pipe_surface *(*get_tex_surface)(struct pipe_screen *, struct pipe_texture *texture, unsigned face, unsigned level, - unsigned zslice); + unsigned zslice, + unsigned usage ); + + /* Surfaces allocated by the above must be released here: + */ + void (*tex_surface_release)( struct pipe_screen *, + struct pipe_surface ** ); + + + void *(*surface_map)( struct pipe_screen *, + struct pipe_surface *surface, + unsigned flags ); + + void (*surface_unmap)( struct pipe_screen *, + struct pipe_surface *surface ); + }; diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h index 912d84e7b9..62b05a403b 100644 --- a/src/gallium/include/pipe/p_state.h +++ b/src/gallium/include/pipe/p_state.h @@ -273,7 +273,11 @@ struct pipe_surface unsigned pitch; /**< in pixels */ unsigned offset; /**< offset from start of buffer, in bytes */ unsigned refcount; + unsigned usage; /**< PIPE_BUFFER_USAGE_* */ + struct pipe_winsys *winsys; /**< winsys which owns/created the surface */ + + struct pipe_texture *texture; /**< optional texture into which this is a view */ }; diff --git a/src/gallium/include/pipe/p_util.h b/src/gallium/include/pipe/p_util.h index 0e7e246666..0d8ed167b2 100644 --- a/src/gallium/include/pipe/p_util.h +++ b/src/gallium/include/pipe/p_util.h @@ -204,7 +204,10 @@ mem_dup(const void *src, uint size) #define MIN2( A, B ) ( (A)<(B) ? (A) : (B) ) #define MAX2( A, B ) ( (A)>(B) ? (A) : (B) ) +#ifndef Elements #define Elements(x) (sizeof(x)/sizeof((x)[0])) +#endif + #define Offset(TYPE, MEMBER) ((unsigned)&(((TYPE *)NULL)->MEMBER)) /** diff --git a/src/gallium/include/pipe/p_winsys.h b/src/gallium/include/pipe/p_winsys.h index 3005ec2d94..87a66b66d7 100644 --- a/src/gallium/include/pipe/p_winsys.h +++ b/src/gallium/include/pipe/p_winsys.h @@ -90,7 +90,7 @@ struct pipe_winsys void (*surface_release)(struct pipe_winsys *ws, struct pipe_surface **s); - + /** * Buffer management. Buffer attributes are mostly fixed over its lifetime. * diff --git a/src/gallium/winsys/xlib/xm_winsys.c b/src/gallium/winsys/xlib/xm_winsys.c index 8a89278cde..fd2f56eff2 100644 --- a/src/gallium/winsys/xlib/xm_winsys.c +++ b/src/gallium/winsys/xlib/xm_winsys.c @@ -508,6 +508,7 @@ xm_surface_alloc_storage(struct pipe_winsys *winsys, surf->format = format; surf->cpp = pf_get_size(format); surf->pitch = round_up(width, alignment / surf->cpp); + surf->usage = flags; #ifdef GALLIUM_CELL /* XXX a bit of a hack */ height = round_up(height, TILE_SIZE); @@ -562,6 +563,7 @@ static void xm_surface_release(struct pipe_winsys *winsys, struct pipe_surface **s) { struct pipe_surface *surf = *s; + assert(!surf->texture); surf->refcount--; if (surf->refcount == 0) { if (surf->buffer) diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c b/src/mesa/state_tracker/st_atom_pixeltransfer.c index 76356bbad7..e7186a85da 100644 --- a/src/mesa/state_tracker/st_atom_pixeltransfer.c +++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c @@ -148,8 +148,10 @@ load_color_map_texture(GLcontext *ctx, struct pipe_texture *pt) uint *dest; uint i, j; - surface = screen->get_tex_surface(screen, pt, 0, 0, 0); - dest = (uint *) pipe_surface_map(surface); + surface = screen->get_tex_surface(screen, pt, 0, 0, 0, + PIPE_BUFFER_USAGE_CPU_WRITE); + dest = (uint *) screen->surface_map(screen, surface, + PIPE_BUFFER_USAGE_CPU_WRITE); /* Pack four 1D maps into a 2D texture: * R map is placed horizontally, indexed by S, in channel 0 @@ -168,9 +170,8 @@ load_color_map_texture(GLcontext *ctx, struct pipe_texture *pt) } } - pipe_surface_unmap(surface); + screen->surface_unmap(screen, surface); pipe_surface_reference(&surface, NULL); - pipe->texture_update(pipe, pt, 0, 0x1); } diff --git a/src/mesa/state_tracker/st_cb_accum.c b/src/mesa/state_tracker/st_cb_accum.c index 1636bed91a..e4ef3e16b7 100644 --- a/src/mesa/state_tracker/st_cb_accum.c +++ b/src/mesa/state_tracker/st_cb_accum.c @@ -106,13 +106,15 @@ st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { struct st_renderbuffer *acc_strb = st_renderbuffer(rb); struct pipe_surface *acc_ps = acc_strb->surface; + struct pipe_screen *screen = ctx->st->pipe->screen; const GLint xpos = ctx->DrawBuffer->_Xmin; const GLint ypos = ctx->DrawBuffer->_Ymin; const GLint width = ctx->DrawBuffer->_Xmax - xpos; const GLint height = ctx->DrawBuffer->_Ymax - ypos; GLvoid *map; - map = pipe_surface_map(acc_ps); + map = screen->surface_map(screen, acc_ps, + PIPE_BUFFER_USAGE_CPU_WRITE); /* note acc_strb->format might not equal acc_ps->format */ switch (acc_strb->format) { @@ -140,7 +142,7 @@ st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) _mesa_problem(ctx, "unexpected format in st_clear_accum_buffer()"); } - pipe_surface_unmap(acc_ps); + screen->surface_unmap(screen, acc_ps); } @@ -150,10 +152,12 @@ accum_mad(GLcontext *ctx, GLfloat scale, GLfloat bias, GLint xpos, GLint ypos, GLint width, GLint height, struct st_renderbuffer *acc_strb) { + struct pipe_screen *screen = ctx->st->pipe->screen; struct pipe_surface *acc_ps = acc_strb->surface; GLvoid *map; - map = pipe_surface_map(acc_ps); + map = screen->surface_map(screen, acc_ps, + PIPE_BUFFER_USAGE_CPU_WRITE); /* note acc_strb->format might not equal acc_ps->format */ switch (acc_strb->format) { @@ -174,7 +178,7 @@ accum_mad(GLcontext *ctx, GLfloat scale, GLfloat bias, _mesa_problem(NULL, "unexpected format in st_clear_accum_buffer()"); } - pipe_surface_unmap(acc_ps); + screen->surface_unmap(screen, acc_ps); } diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index ce8fefe703..873b765c2c 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -327,10 +327,11 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, return NULL; } - surface = screen->get_tex_surface(screen, pt, 0, 0, 0); + surface = screen->get_tex_surface(screen, pt, 0, 0, 0, + PIPE_BUFFER_USAGE_CPU_WRITE); /* map texture surface */ - dest = pipe_surface_map(surface); + dest = screen->surface_map(screen, surface, PIPE_BUFFER_USAGE_CPU_WRITE); /* Put image into texture surface */ memset(dest, 0xff, height * surface->pitch); @@ -340,9 +341,8 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, _mesa_unmap_bitmap_pbo(ctx, unpack); /* Release surface */ - pipe_surface_unmap(surface); + screen->surface_unmap(screen, surface); pipe_surface_reference(&surface, NULL); - pipe->texture_update(pipe, pt, 0, 0x1); return pt; } @@ -544,8 +544,10 @@ reset_cache(struct st_context *st) /* Map the texture surface. * Subsequent glBitmap calls will write into the texture image. */ - cache->surf = screen->get_tex_surface(screen, cache->texture, 0, 0, 0); - cache->buffer = pipe_surface_map(cache->surf); + cache->surf = screen->get_tex_surface(screen, cache->texture, 0, 0, 0, + PIPE_BUFFER_USAGE_CPU_WRITE); + cache->buffer = screen->surface_map(screen, cache->surf, + PIPE_BUFFER_USAGE_CPU_WRITE); /* init image to all 0xff */ memset(cache->buffer, 0xff, BITMAP_CACHE_WIDTH * BITMAP_CACHE_HEIGHT); @@ -562,6 +564,7 @@ st_flush_bitmap_cache(struct st_context *st) if (st->ctx->DrawBuffer) { struct bitmap_cache *cache = st->bitmap.cache; struct pipe_context *pipe = st->pipe; + struct pipe_screen *screen = pipe->screen; assert(cache->xmin <= cache->xmax); /* @@ -574,12 +577,18 @@ st_flush_bitmap_cache(struct st_context *st) /* The texture surface has been mapped until now. * So unmap and release the texture surface before drawing. */ +#if 0 pipe_surface_unmap(cache->surf); pipe_surface_reference(&cache->surf, NULL); +#else + screen->surface_unmap(screen, cache->surf); + screen->tex_surface_release(screen, &cache->surf); +#endif +#if 0 /* XXX is this needed? */ pipe->texture_update(pipe, cache->texture, 0, 0x1); - +#endif draw_bitmap_quad(st->ctx, cache->xpos, cache->ypos, diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 65bfd6cfcc..9ae53c95f8 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -362,10 +362,12 @@ make_texture(struct st_context *st, /* we'll do pixel transfer in a fragment shader */ ctx->_ImageTransferState = 0x0; - surface = screen->get_tex_surface(screen, pt, 0, 0, 0); + surface = screen->get_tex_surface(screen, pt, 0, 0, 0, + PIPE_BUFFER_USAGE_CPU_WRITE); /* map texture surface */ - dest = pipe_surface_map(surface); + dest = screen->surface_map(screen, surface, + PIPE_BUFFER_USAGE_CPU_WRITE); /* Put image into texture surface. * Note that the image is actually going to be upside down in @@ -384,9 +386,8 @@ make_texture(struct st_context *st, unpack); /* unmap */ - pipe_surface_unmap(surface); + screen->surface_unmap(screen, surface); pipe_surface_reference(&surface, NULL); - pipe->texture_update(pipe, pt, 0, 0x1); assert(success); @@ -731,6 +732,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, { struct st_context *st = ctx->st; struct pipe_context *pipe = st->pipe; + struct pipe_screen *screen = pipe->screen; struct pipe_surface *ps = st->state.framebuffer.zsbuf; const GLboolean zoom = ctx->Pixel.ZoomX != 1.0 || ctx->Pixel.ZoomY != 1.0; GLint skipPixels; @@ -739,7 +741,8 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); /* map the stencil buffer */ - stmap = pipe_surface_map(ps); + stmap = screen->surface_map(screen, ps, + PIPE_BUFFER_USAGE_CPU_WRITE); /* if width > MAX_WIDTH, have to process image in chunks */ skipPixels = 0; @@ -796,7 +799,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, } /* unmap the stencil buffer */ - pipe_surface_unmap(ps); + screen->surface_unmap(screen, ps); } @@ -869,6 +872,7 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, GLint dstx, GLint dsty) { struct st_renderbuffer *rbDraw = st_renderbuffer(ctx->DrawBuffer->_StencilBuffer); + struct pipe_screen *screen = ctx->st->pipe->screen; struct pipe_surface *psDraw = rbDraw->surface; ubyte *drawMap; ubyte *buffer; @@ -885,7 +889,7 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, &ctx->DefaultPacking, buffer); /* map the stencil buffer */ - drawMap = pipe_surface_map(psDraw); + drawMap = screen->surface_map(screen, psDraw, PIPE_BUFFER_USAGE_CPU_WRITE); /* draw */ /* XXX PixelZoom not handled yet */ @@ -925,7 +929,7 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, free(buffer); /* unmap the stencil buffer */ - pipe_surface_unmap(psDraw); + screen->surface_unmap(screen, psDraw); } @@ -994,13 +998,14 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, if (!pt) return; - psTex = screen->get_tex_surface(screen, pt, 0, 0, 0); - if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) { srcy = ctx->DrawBuffer->Height - srcy - height; } if (srcFormat == texFormat) { + psTex = screen->get_tex_surface(screen, pt, 0, 0, 0, + PIPE_BUFFER_USAGE_GPU_WRITE ); + /* copy source framebuffer surface into mipmap/texture */ pipe->surface_copy(pipe, FALSE, @@ -1009,21 +1014,26 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, psRead, srcx, srcy, width, height); } - else if (type == GL_COLOR) { - /* alternate path using get/put_tile() */ - GLfloat *buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); + else { + psTex = screen->get_tex_surface(screen, pt, 0, 0, 0, + PIPE_BUFFER_USAGE_CPU_WRITE ); - pipe_get_tile_rgba(pipe, psRead, srcx, srcy, width, height, buf); - pipe_put_tile_rgba(pipe, psTex, 0, 0, width, height, buf); + if (type == GL_COLOR) { + /* alternate path using get/put_tile() */ + GLfloat *buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - free(buf); - } - else { - /* GL_DEPTH */ - GLuint *buf = (GLuint *) malloc(width * height * sizeof(GLuint)); - pipe_get_tile_z(pipe, psRead, srcx, srcy, width, height, buf); - pipe_put_tile_z(pipe, psTex, 0, 0, width, height, buf); - free(buf); + pipe_get_tile_rgba(pipe, psRead, srcx, srcy, width, height, buf); + pipe_put_tile_rgba(pipe, psTex, 0, 0, width, height, buf); + + free(buf); + } + else { + /* GL_DEPTH */ + GLuint *buf = (GLuint *) malloc(width * height * sizeof(GLuint)); + pipe_get_tile_z(pipe, psRead, srcx, srcy, width, height, buf); + pipe_put_tile_z(pipe, psTex, 0, 0, width, height, buf); + free(buf); + } } /* draw textured quad */ diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index fc8a5ea7f6..7fdc0bddd6 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -91,9 +91,14 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, struct pipe_context *pipe = ctx->st->pipe; struct st_renderbuffer *strb = st_renderbuffer(rb); enum pipe_format pipeFormat; - GLbitfield flags = 0x0; /* XXX needed? */ + unsigned flags = (PIPE_BUFFER_USAGE_CPU_WRITE | + PIPE_BUFFER_USAGE_CPU_READ | + PIPE_BUFFER_USAGE_GPU_WRITE | + PIPE_BUFFER_USAGE_GPU_READ); int ret; + pipe_surface_reference( &strb->surface, NULL ); + if (!strb->surface) { /* first time surface creation */ strb->surface = pipe->winsys->surface_alloc(pipe->winsys); @@ -103,11 +108,16 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, if (!strb->surface) return GL_FALSE; } +#if 0 else if (strb->surface->buffer) { /* release/discard the old surface buffer */ pipe_reference_buffer(pipe, &strb->surface->buffer, NULL); } - +#else + else { + assert(0); + } +#endif /* Determine surface format here */ if (strb->format != PIPE_FORMAT_NONE) { assert(strb->format != 0); @@ -368,7 +378,11 @@ st_render_texture(GLcontext *ctx, strb->surface = screen->get_tex_surface(screen, pt, att->CubeMapFace, att->TextureLevel, - att->Zoffset); + att->Zoffset, + PIPE_BUFFER_USAGE_CPU_READ | + PIPE_BUFFER_USAGE_CPU_WRITE | + PIPE_BUFFER_USAGE_GPU_READ | + PIPE_BUFFER_USAGE_GPU_WRITE); assert(strb->surface); assert(screen->is_format_supported(screen, strb->surface->format, PIPE_TEXTURE)); assert(screen->is_format_supported(screen, strb->surface->format, PIPE_SURFACE)); @@ -396,22 +410,19 @@ static void st_finish_render_texture(GLcontext *ctx, struct gl_renderbuffer_attachment *att) { + struct pipe_screen *screen = ctx->st->pipe->screen; struct st_renderbuffer *strb = st_renderbuffer(att->Renderbuffer); assert(strb); ctx->st->pipe->flush(ctx->st->pipe, PIPE_FLUSH_RENDER_CACHE, NULL); - ctx->st->pipe->texture_update(ctx->st->pipe, - st_get_texobj_texture(att->Texture), - att->CubeMapFace, 1 << att->TextureLevel); + screen->tex_surface_release( screen, &strb->surface ); /* printf("FINISH RENDER TO TEXTURE surf=%p\n", strb->surface); */ - pipe_surface_reference(&strb->surface, NULL); - _mesa_reference_renderbuffer(&att->Renderbuffer, NULL); /* restore previous framebuffer state */ diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c index ddbe36106c..e242195e7a 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -61,13 +61,14 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, GLvoid *pixels) { struct gl_framebuffer *fb = ctx->ReadBuffer; + struct pipe_screen *screen = ctx->st->pipe->screen; struct st_renderbuffer *strb = st_renderbuffer(fb->_StencilBuffer); struct pipe_surface *ps = strb->surface; ubyte *stmap; GLint j; /* map the stencil buffer */ - stmap = pipe_surface_map(ps); + stmap = screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_READ); /* width should never be > MAX_WIDTH since we did clipping earlier */ ASSERT(width <= MAX_WIDTH); @@ -124,7 +125,7 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, /* unmap the stencil buffer */ - pipe_surface_unmap(ps); + screen->surface_unmap(screen, ps); } diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 981246221b..05e0339e0e 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -478,7 +478,6 @@ st_TexImage(GLcontext * ctx, struct gl_texture_image *texImage, GLsizei imageSize, int compressed) { - struct pipe_context *pipe = ctx->st->pipe; struct st_texture_object *stObj = st_texture_object(texObj); struct st_texture_image *stImage = st_texture_image(texImage); GLint postConvWidth, postConvHeight; @@ -635,7 +634,8 @@ st_TexImage(GLcontext * ctx, return; if (stImage->pt) { - texImage->Data = st_texture_image_map(ctx->st, stImage, 0); + texImage->Data = st_texture_image_map(ctx->st, stImage, 0, + PIPE_BUFFER_USAGE_CPU_WRITE); dstRowStride = stImage->surface->pitch * stImage->surface->cpp; } else { @@ -684,8 +684,9 @@ st_TexImage(GLcontext * ctx, } if (stImage->pt && i < depth) { - st_texture_image_unmap(stImage); - texImage->Data = st_texture_image_map(ctx->st, stImage, i); + st_texture_image_unmap(ctx->st, stImage); + texImage->Data = st_texture_image_map(ctx->st, stImage, i, + PIPE_BUFFER_USAGE_CPU_WRITE); src += srcImageStride; } } @@ -694,13 +695,10 @@ st_TexImage(GLcontext * ctx, _mesa_unmap_teximage_pbo(ctx, unpack); if (stImage->pt) { - st_texture_image_unmap(stImage); + st_texture_image_unmap(ctx->st, stImage); texImage->Data = NULL; } - if (stObj->pt) - pipe->texture_update(pipe, stObj->pt, stImage->face, (1 << level)); - if (level == texObj->BaseLevel && texObj->GenerateMipmap) { ctx->Driver.GenerateMipmap(ctx, target, texObj); } @@ -793,7 +791,8 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level, /* Image is stored in hardware format in a buffer managed by the * kernel. Need to explicitly map and unmap it. */ - texImage->Data = st_texture_image_map(ctx->st, stImage, 0); + texImage->Data = st_texture_image_map(ctx->st, stImage, 0, + PIPE_BUFFER_USAGE_CPU_READ); texImage->RowStride = stImage->surface->pitch; } else { @@ -823,8 +822,9 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level, } if (stImage->pt && i < depth) { - st_texture_image_unmap(stImage); - texImage->Data = st_texture_image_map(ctx->st, stImage, i); + st_texture_image_unmap(ctx->st, stImage); + texImage->Data = st_texture_image_map(ctx->st, stImage, i, + PIPE_BUFFER_USAGE_CPU_READ); dest += dstImageStride; } } @@ -833,7 +833,7 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level, /* Unmap */ if (stImage->pt) { - st_texture_image_unmap(stImage); + st_texture_image_unmap(ctx->st, stImage); texImage->Data = NULL; } } @@ -874,8 +874,6 @@ st_TexSubimage(GLcontext * ctx, struct gl_texture_object *texObj, struct gl_texture_image *texImage) { - struct pipe_context *pipe = ctx->st->pipe; - struct st_texture_object *stObj = st_texture_object(texObj); struct st_texture_image *stImage = st_texture_image(texImage); GLuint dstRowStride; GLuint srcImageStride = _mesa_image_image_stride(packing, width, height, @@ -897,7 +895,8 @@ st_TexSubimage(GLcontext * ctx, * from uploading the buffer under us. */ if (stImage->pt) { - texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset); + texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset, + PIPE_BUFFER_USAGE_CPU_WRITE); dstRowStride = stImage->surface->pitch * stImage->surface->cpp; } @@ -922,8 +921,9 @@ st_TexSubimage(GLcontext * ctx, if (stImage->pt && i < depth) { /* map next slice of 3D texture */ - st_texture_image_unmap(stImage); - texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset + i); + st_texture_image_unmap(ctx->st, stImage); + texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset + i, + PIPE_BUFFER_USAGE_CPU_WRITE); src += srcImageStride; } } @@ -935,11 +935,9 @@ st_TexSubimage(GLcontext * ctx, _mesa_unmap_teximage_pbo(ctx, packing); if (stImage->pt) { - st_texture_image_unmap(stImage); + st_texture_image_unmap(ctx->st, stImage); texImage->Data = NULL; } - - pipe->texture_update(pipe, stObj->pt, stImage->face, (1 << level)); } @@ -1058,7 +1056,8 @@ fallback_copy_texsubimage(GLcontext *ctx, src_surf = strb->surface; - dest_surf = screen->get_tex_surface(screen, pt, face, level, destZ); + dest_surf = screen->get_tex_surface(screen, pt, face, level, destZ, + PIPE_BUFFER_USAGE_CPU_WRITE); assert(width <= MAX_WIDTH); @@ -1119,7 +1118,6 @@ do_copy_texsubimage(GLcontext *ctx, struct gl_texture_image *texImage = _mesa_select_tex_image(ctx, texObj, target, level); struct st_texture_image *stImage = st_texture_image(texImage); - struct st_texture_object *stObj = st_texture_object(texObj); GLenum baseFormat = texImage->InternalFormat; struct gl_framebuffer *fb = ctx->ReadBuffer; struct st_renderbuffer *strb; @@ -1157,7 +1155,8 @@ do_copy_texsubimage(GLcontext *ctx, dest_format = stImage->pt->format; dest_surface = screen->get_tex_surface(screen, stImage->pt, stImage->face, - stImage->level, destZ); + stImage->level, destZ, + PIPE_BUFFER_USAGE_CPU_WRITE); if (ctx->_ImageTransferState == 0x0 && strb->surface->buffer && @@ -1223,8 +1222,6 @@ do_copy_texsubimage(GLcontext *ctx, pipe_surface_reference(&dest_surface, NULL); - pipe->texture_update(pipe, stObj->pt, stImage->face, (1 << level)); - if (level == texObj->BaseLevel && texObj->GenerateMipmap) { ctx->Driver.GenerateMipmap(ctx, target, texObj); } @@ -1529,7 +1526,6 @@ st_finalize_texture(GLcontext *ctx, if (stImage && stObj->pt != stImage->pt) { copy_image_data_to_texture(ctx->st, stObj, level, stImage); *needFlush = GL_TRUE; - pipe->texture_update(pipe, stObj->pt, face, (1 << level)); } } } diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c index 1a0e19c2f9..cfacfdd04c 100644 --- a/src/mesa/state_tracker/st_gen_mipmap.c +++ b/src/mesa/state_tracker/st_gen_mipmap.c @@ -123,8 +123,10 @@ fallback_generate_mipmap(GLcontext *ctx, GLenum target, const ubyte *srcData; ubyte *dstData; - srcSurf = screen->get_tex_surface(screen, pt, face, srcLevel, zslice); - dstSurf = screen->get_tex_surface(screen, pt, face, dstLevel, zslice); + srcSurf = screen->get_tex_surface(screen, pt, face, srcLevel, zslice, + PIPE_BUFFER_USAGE_CPU_READ); + dstSurf = screen->get_tex_surface(screen, pt, face, dstLevel, zslice, + PIPE_BUFFER_USAGE_CPU_WRITE); srcData = (ubyte *) pipe_buffer_map(pipe, srcSurf->buffer, PIPE_BUFFER_USAGE_CPU_READ) diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c index f68bef1207..482a054f64 100644 --- a/src/mesa/state_tracker/st_texture.c +++ b/src/mesa/state_tracker/st_texture.c @@ -184,25 +184,30 @@ st_texture_image_offset(const struct pipe_texture * pt, */ GLubyte * st_texture_image_map(struct st_context *st, struct st_texture_image *stImage, - GLuint zoffset) + GLuint zoffset, + GLuint flags ) { struct pipe_screen *screen = st->pipe->screen; struct pipe_texture *pt = stImage->pt; DBG("%s \n", __FUNCTION__); stImage->surface = screen->get_tex_surface(screen, pt, stImage->face, - stImage->level, zoffset); + stImage->level, zoffset, + flags); - return pipe_surface_map(stImage->surface); + return screen->surface_map(screen, stImage->surface, flags); } void -st_texture_image_unmap(struct st_texture_image *stImage) +st_texture_image_unmap(struct st_context *st, + struct st_texture_image *stImage) { + struct pipe_screen *screen = st->pipe->screen; + DBG("%s\n", __FUNCTION__); - pipe_surface_unmap(stImage->surface); + screen->surface_unmap(screen, stImage->surface); pipe_surface_reference(&stImage->surface, NULL); } @@ -224,12 +229,15 @@ st_surface_data(struct pipe_context *pipe, const void *src, unsigned src_pitch, unsigned srcx, unsigned srcy, unsigned width, unsigned height) { - pipe_copy_rect(pipe_surface_map(dst), + struct pipe_screen *screen = pipe->screen; + void *map = screen->surface_map(screen, dst, PIPE_BUFFER_USAGE_CPU_WRITE); + + pipe_copy_rect(map, dst->cpp, dst->pitch, dstx, dsty, width, height, src, src_pitch, srcx, srcy); - pipe_surface_unmap(dst); + screen->surface_unmap(screen, dst); } @@ -256,7 +264,8 @@ st_texture_image_data(struct pipe_context *pipe, if(dst->compressed) height /= 4; - dst_surface = screen->get_tex_surface(screen, dst, face, level, i); + dst_surface = screen->get_tex_surface(screen, dst, face, level, i, + PIPE_BUFFER_USAGE_CPU_WRITE); st_surface_data(pipe, dst_surface, 0, 0, /* dstx, dsty */ @@ -265,7 +274,7 @@ st_texture_image_data(struct pipe_context *pipe, 0, 0, /* source x, y */ dst->width[level], height); /* width, height */ - pipe_surface_reference(&dst_surface, NULL); + screen->tex_surface_release(screen, &dst_surface); srcUB += src_image_pitch * dst->cpp; } @@ -304,8 +313,11 @@ st_texture_image_copy(struct pipe_context *pipe, assert(src->width[srcLevel] == width); assert(src->height[srcLevel] == height); - dst_surface = screen->get_tex_surface(screen, dst, face, dstLevel, i); - src_surface = screen->get_tex_surface(screen, src, face, srcLevel, i); + dst_surface = screen->get_tex_surface(screen, dst, face, dstLevel, i, + PIPE_BUFFER_USAGE_GPU_WRITE); + + src_surface = screen->get_tex_surface(screen, src, face, srcLevel, i, + PIPE_BUFFER_USAGE_GPU_READ); pipe->surface_copy(pipe, FALSE, diff --git a/src/mesa/state_tracker/st_texture.h b/src/mesa/state_tracker/st_texture.h index 7abccb3a69..f6d5733e21 100644 --- a/src/mesa/state_tracker/st_texture.h +++ b/src/mesa/state_tracker/st_texture.h @@ -121,10 +121,12 @@ st_texture_match_image(const struct pipe_texture *pt, extern GLubyte * st_texture_image_map(struct st_context *st, struct st_texture_image *stImage, - GLuint zoffset); + GLuint zoffset, + GLuint flags); extern void -st_texture_image_unmap(struct st_texture_image *stImage); +st_texture_image_unmap(struct st_context *st, + struct st_texture_image *stImage); /* Return pointers to each 2d slice within an image. Indexed by depth -- cgit v1.2.3 From 4a159132082429d5492f5298c2ccb0df551c9f65 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Fri, 2 May 2008 14:27:10 +0100 Subject: gallium: remove usage of winsys->surface_alloc_storage from state tracker Allocate a texture containing storage instead. Also clean up ACCUM buffer allocation slightly -- drivers will need some changes to texture allocation logic to accomodate the concept of a texture that will only as image storage by the CPU, but it's cleaner than it was. --- src/gallium/include/pipe/p_state.h | 2 + src/mesa/state_tracker/st_cb_fbo.c | 138 +++++++++++++++++-------------------- 2 files changed, 64 insertions(+), 76 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h index 47e57e2957..277ee4b319 100644 --- a/src/gallium/include/pipe/p_state.h +++ b/src/gallium/include/pipe/p_state.h @@ -299,6 +299,8 @@ struct pipe_texture unsigned cpp:8; unsigned last_level:8; /**< Index of last mipmap level present/defined */ unsigned compressed:1; + + unsigned usage; /* These are also refcounted: */ diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 7fdc0bddd6..b174714171 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -90,90 +90,79 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, { struct pipe_context *pipe = ctx->st->pipe; struct st_renderbuffer *strb = st_renderbuffer(rb); - enum pipe_format pipeFormat; - unsigned flags = (PIPE_BUFFER_USAGE_CPU_WRITE | - PIPE_BUFFER_USAGE_CPU_READ | - PIPE_BUFFER_USAGE_GPU_WRITE | - PIPE_BUFFER_USAGE_GPU_READ); - int ret; + struct pipe_texture template, *texture; + + /* Free the old surface (and texture if we hold the last + * reference): + */ pipe_surface_reference( &strb->surface, NULL ); - if (!strb->surface) { - /* first time surface creation */ - strb->surface = pipe->winsys->surface_alloc(pipe->winsys); - assert(strb->surface); - assert(strb->surface->refcount); - assert(strb->surface->winsys); - if (!strb->surface) - return GL_FALSE; - } -#if 0 - else if (strb->surface->buffer) { - /* release/discard the old surface buffer */ - pipe_reference_buffer(pipe, &strb->surface->buffer, NULL); - } -#else - else { - assert(0); - } -#endif - /* Determine surface format here */ + memset(&template, 0, sizeof(template)); + if (strb->format != PIPE_FORMAT_NONE) { - assert(strb->format != 0); - /* we'll hit this for front/back color bufs */ - pipeFormat = strb->format; + template.format = strb->format; } else { - pipeFormat = st_choose_renderbuffer_format(pipe, internalFormat); + template.format = st_choose_renderbuffer_format(pipe, internalFormat); } - init_renderbuffer_bits(strb, pipeFormat); - - ret = pipe->winsys->surface_alloc_storage(pipe->winsys, - strb->surface, - width, - height, - pipeFormat, - flags); - if (ret || !strb->surface->buffer) { - if (pipeFormat == DEFAULT_ACCUM_PIPE_FORMAT) { - /* Accum buffer. Try a different surface format. Since accum - * buffers are s/w only for now, the surface pixel format doesn't - * really matter, only that the buffer is large enough. - */ - int sz, mult; - enum pipe_format accum_format; - - /* allocate a buffer of (typically) double height to get 64bpp */ - accum_format = st_choose_renderbuffer_format(pipe, GL_RGBA); - sz = pf_get_size(accum_format); - mult = pf_get_size(DEFAULT_ACCUM_PIPE_FORMAT) / sz; - - ret = pipe->winsys->surface_alloc_storage(pipe->winsys, - strb->surface, - width, height * mult, - accum_format, flags); - if (ret) - return GL_FALSE; /* we've _really_ failed */ - - } - else { - return GL_FALSE; /* out of memory, try s/w buffer? */ - } + strb->Base.Width = width; + strb->Base.Height = height; + init_renderbuffer_bits(strb, template.format); + + template.compressed = 0; + template.cpp = pf_get_size(template.format); + template.width[0] = width; + template.height[0] = height; + template.depth[0] = 1; + template.last_level = 0; + template.usage = (PIPE_BUFFER_USAGE_CPU_WRITE | + PIPE_BUFFER_USAGE_CPU_READ | + PIPE_BUFFER_USAGE_GPU_WRITE | + PIPE_BUFFER_USAGE_GPU_READ); + + texture = pipe->screen->texture_create( pipe->screen, + &template ); + + /* Special path for accum buffers. + * + * Try a different surface format. Since accum buffers are s/w + * only for now, the surface pixel format doesn't really matter, + * only that the buffer is large enough. + */ + if (!texture && template.format == DEFAULT_ACCUM_PIPE_FORMAT) + { + /* Actually, just setting this usage value should be sufficient + * to tell the driver to go ahead and allocate the buffer, even + * if HW doesn't support the format. + */ + template.usage = (PIPE_BUFFER_USAGE_CPU_READ | + PIPE_BUFFER_USAGE_CPU_WRITE); + + texture = pipe->screen->texture_create( pipe->screen, + &template ); } - ASSERT(strb->surface->buffer); - ASSERT(strb->surface->format); - ASSERT(strb->surface->cpp); - ASSERT(strb->surface->width == width); - /*ASSERT(strb->surface->height == height);*/ - ASSERT(strb->surface->pitch); + if (!texture) + return FALSE; - strb->Base.Width = width; - strb->Base.Height = height; + strb->surface = pipe->screen->get_tex_surface( pipe->screen, + texture, + 0, 0, 0, + template.usage ); + + pipe_texture_reference( &texture, NULL ); - return GL_TRUE; + assert(strb->surface->buffer); + assert(strb->surface->format); + assert(strb->surface->cpp); + assert(strb->surface->width == width); + assert(strb->surface->height == height); + assert(strb->surface->pitch); + + + return strb->surface != NULL; } @@ -185,10 +174,7 @@ st_renderbuffer_delete(struct gl_renderbuffer *rb) { struct st_renderbuffer *strb = st_renderbuffer(rb); ASSERT(strb); - if (strb->surface) { - struct pipe_winsys *ws = strb->surface->winsys; - ws->surface_release(ws, &strb->surface); - } + pipe_surface_reference(&strb->surface, NULL); free(strb); } -- cgit v1.2.3 From a73ae3d5eb8419feab5aea26573aa41b72f941eb Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Fri, 2 May 2008 16:46:31 +0100 Subject: gallium: Add texture usage flags, special-case allocation of display targets For many envirionments it's necessary to allocate display targets in a window-system friendly manner. Add facilities so that a driver can tell if a texture is likely to be used to generate a display surface and if use special allocation paths if necessary. Hook up softpipe to call into the winsys->surface_alloc_storage() routine in this case, though we probably want to change that interface slightly also. --- src/gallium/drivers/softpipe/sp_texture.c | 101 ++++++++++++++++--------- src/gallium/drivers/softpipe/sp_texture.h | 2 +- src/gallium/include/pipe/p_state.h | 6 +- src/mesa/state_tracker/st_atom_pixeltransfer.c | 3 +- src/mesa/state_tracker/st_cb_bitmap.c | 6 +- src/mesa/state_tracker/st_cb_drawpixels.c | 6 +- src/mesa/state_tracker/st_cb_fbo.c | 23 ++++-- src/mesa/state_tracker/st_cb_texture.c | 10 ++- src/mesa/state_tracker/st_texture.c | 4 +- src/mesa/state_tracker/st_texture.h | 3 +- 10 files changed, 111 insertions(+), 53 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/gallium/drivers/softpipe/sp_texture.c b/src/gallium/drivers/softpipe/sp_texture.c index 2b31cd4f25..599ff2ac45 100644 --- a/src/gallium/drivers/softpipe/sp_texture.c +++ b/src/gallium/drivers/softpipe/sp_texture.c @@ -52,40 +52,87 @@ static unsigned minify( unsigned d ) } -static void -softpipe_texture_layout(struct softpipe_texture * spt) +/* Conventional allocation path for non-display textures: + */ +static boolean +softpipe_texture_layout(struct pipe_screen *screen, + struct softpipe_texture * spt) { + struct pipe_winsys *ws = screen->winsys; struct pipe_texture *pt = &spt->base; unsigned level; unsigned width = pt->width[0]; unsigned height = pt->height[0]; unsigned depth = pt->depth[0]; - spt->buffer_size = 0; + unsigned buffer_size = 0; for (level = 0; level <= pt->last_level; level++) { pt->width[level] = width; pt->height[level] = height; pt->depth[level] = depth; + spt->pitch[level] = width; - spt->level_offset[level] = spt->buffer_size; + spt->level_offset[level] = buffer_size; - spt->buffer_size += ((pt->compressed) ? MAX2(1, height/4) : height) * - ((pt->target == PIPE_TEXTURE_CUBE) ? 6 : depth) * - width * pt->cpp; + buffer_size += (((pt->compressed) ? MAX2(1, height/4) : height) * + ((pt->target == PIPE_TEXTURE_CUBE) ? 6 : depth) * + width * pt->cpp); width = minify(width); height = minify(height); depth = minify(depth); } + + spt->buffer = ws->buffer_create(ws, 32, + PIPE_BUFFER_USAGE_PIXEL, + buffer_size); + + return spt->buffer != NULL; } + +/* Hack it up to use the old winsys->surface_alloc_storage() + * method for now: + */ +static boolean +softpipe_displaytarget_layout(struct pipe_screen *screen, + struct softpipe_texture * spt) +{ + struct pipe_winsys *ws = screen->winsys; + struct pipe_surface surf; + unsigned flags = (PIPE_BUFFER_USAGE_CPU_READ | + PIPE_BUFFER_USAGE_CPU_WRITE | + PIPE_BUFFER_USAGE_GPU_READ | + PIPE_BUFFER_USAGE_GPU_WRITE); + + + memset(&surf, 0, sizeof(surf)); + + ws->surface_alloc_storage( ws, + &surf, + spt->base.width[0], + spt->base.height[0], + spt->base.format, + flags); + + /* Now extract the goodies: + */ + spt->buffer = surf.buffer; + spt->pitch[0] = surf.pitch; + + return spt->buffer != NULL; +} + + + + + static struct pipe_texture * softpipe_texture_create(struct pipe_screen *screen, const struct pipe_texture *templat) { - struct pipe_winsys *ws = screen->winsys; struct softpipe_texture *spt = CALLOC_STRUCT(softpipe_texture); if (!spt) return NULL; @@ -94,19 +141,21 @@ softpipe_texture_create(struct pipe_screen *screen, spt->base.refcount = 1; spt->base.screen = screen; - softpipe_texture_layout(spt); - - spt->buffer = ws->buffer_create(ws, 32, - PIPE_BUFFER_USAGE_PIXEL, - spt->buffer_size); - if (!spt->buffer) { - FREE(spt); - return NULL; + if (spt->base.tex_usage & PIPE_TEXTURE_USAGE_DISPLAY_TARGET) { + if (!softpipe_displaytarget_layout(screen, spt)) + goto fail; } - + else { + if (!softpipe_texture_layout(screen, spt)) + goto fail; + } + assert(spt->base.refcount == 1); - return &spt->base; + + fail: + FREE(spt); + return NULL; } @@ -178,22 +227,6 @@ softpipe_get_tex_surface(struct pipe_screen *screen, assert(face == 0); assert(zslice == 0); } - - if (usage & (PIPE_BUFFER_USAGE_CPU_WRITE | - PIPE_BUFFER_USAGE_GPU_WRITE)) { - /* XXX if writing to the texture, invalidate the texcache entries!!! - * - * Actually, no. Flushing dependent contexts is still done - * explicitly and separately. Hardware drivers won't insert - * FLUSH commands into a command stream at this point, - * neither should softpipe try to flush caches. - * - * Those contexts could be living in separate threads & doing - * all sorts of unrelated stuff... Context<->texture - * dependency tracking needs to happen elsewhere. - */ - /* assert(0); */ - } } return ps; } diff --git a/src/gallium/drivers/softpipe/sp_texture.h b/src/gallium/drivers/softpipe/sp_texture.h index 2ba093320d..779a9d8fc9 100644 --- a/src/gallium/drivers/softpipe/sp_texture.h +++ b/src/gallium/drivers/softpipe/sp_texture.h @@ -42,11 +42,11 @@ struct softpipe_texture struct pipe_texture base; unsigned long level_offset[PIPE_MAX_TEXTURE_LEVELS]; + unsigned long pitch[PIPE_MAX_TEXTURE_LEVELS]; /* The data is held here: */ struct pipe_buffer *buffer; - unsigned long buffer_size; }; diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h index 277ee4b319..d7565dff96 100644 --- a/src/gallium/include/pipe/p_state.h +++ b/src/gallium/include/pipe/p_state.h @@ -284,6 +284,10 @@ struct pipe_surface }; +#define PIPE_TEXTURE_USAGE_RENDER_TARGET 0x1 +#define PIPE_TEXTURE_USAGE_DISPLAY_TARGET 0x2 /* ie a backbuffer */ +#define PIPE_TEXTURE_USAGE_SAMPLER 0x4 + /** * Texture object. */ @@ -300,7 +304,7 @@ struct pipe_texture unsigned last_level:8; /**< Index of last mipmap level present/defined */ unsigned compressed:1; - unsigned usage; + unsigned tex_usage; /* PIPE_TEXTURE_USAGE_* */ /* These are also refcounted: */ diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c b/src/mesa/state_tracker/st_atom_pixeltransfer.c index 0c32d53c4a..e500ac8684 100644 --- a/src/mesa/state_tracker/st_atom_pixeltransfer.c +++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c @@ -126,7 +126,8 @@ create_color_map_texture(GLcontext *ctx) /* create texture for color map/table */ pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, format, 0, - texSize, texSize, 1, 0); + texSize, texSize, 1, 0, + PIPE_TEXTURE_USAGE_SAMPLER); return pt; } diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index 873b765c2c..f816e59104 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -321,7 +321,8 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, * Create texture to hold bitmap pattern. */ pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, ctx->st->bitmap.tex_format, - 0, width, height, 1, 0); + 0, width, height, 1, 0, + PIPE_TEXTURE_USAGE_SAMPLER); if (!pt) { _mesa_unmap_bitmap_pbo(ctx, unpack); return NULL; @@ -539,7 +540,8 @@ reset_cache(struct st_context *st) cache->texture = st_texture_create(st, PIPE_TEXTURE_2D, st->bitmap.tex_format, 0, BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT, - 1, 0); + 1, 0, + PIPE_TEXTURE_USAGE_SAMPLER); /* Map the texture surface. * Subsequent glBitmap calls will write into the texture image. diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 9ae53c95f8..8c775ad886 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -346,7 +346,8 @@ make_texture(struct st_context *st, return NULL; pt = st_texture_create(st, PIPE_TEXTURE_2D, pipeFormat, 0, width, height, - 1, 0); + 1, 0, + PIPE_TEXTURE_USAGE_SAMPLER); if (!pt) { _mesa_unmap_drawpix_pbo(ctx, unpack); return NULL; @@ -994,7 +995,8 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, } pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, texFormat, 0, - width, height, 1, 0); + width, height, 1, 0, + PIPE_TEXTURE_USAGE_SAMPLER); if (!pt) return; diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index b174714171..21d61e2163 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -90,8 +90,8 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, { struct pipe_context *pipe = ctx->st->pipe; struct st_renderbuffer *strb = st_renderbuffer(rb); - struct pipe_texture template, *texture; + unsigned surface_usage; /* Free the old surface (and texture if we hold the last * reference): @@ -117,10 +117,15 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, template.height[0] = height; template.depth[0] = 1; template.last_level = 0; - template.usage = (PIPE_BUFFER_USAGE_CPU_WRITE | - PIPE_BUFFER_USAGE_CPU_READ | - PIPE_BUFFER_USAGE_GPU_WRITE | - PIPE_BUFFER_USAGE_GPU_READ); + template.tex_usage = (PIPE_TEXTURE_USAGE_DISPLAY_TARGET | + PIPE_TEXTURE_USAGE_RENDER_TARGET); + + /* Probably need dedicated flags for surface usage too: + */ + surface_usage = (PIPE_BUFFER_USAGE_GPU_READ | + PIPE_BUFFER_USAGE_GPU_WRITE | + PIPE_BUFFER_USAGE_CPU_READ | + PIPE_BUFFER_USAGE_CPU_WRITE); texture = pipe->screen->texture_create( pipe->screen, &template ); @@ -137,11 +142,13 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, * to tell the driver to go ahead and allocate the buffer, even * if HW doesn't support the format. */ - template.usage = (PIPE_BUFFER_USAGE_CPU_READ | - PIPE_BUFFER_USAGE_CPU_WRITE); + template.tex_usage = 0; + surface_usage = (PIPE_BUFFER_USAGE_CPU_READ | + PIPE_BUFFER_USAGE_CPU_WRITE); texture = pipe->screen->texture_create( pipe->screen, &template ); + } if (!texture) @@ -150,7 +157,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, strb->surface = pipe->screen->get_tex_surface( pipe->screen, texture, 0, 0, 0, - template.usage ); + surface_usage ); pipe_texture_reference( &texture, NULL ); diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 4cca3364c1..06caa06e77 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -333,7 +333,9 @@ guess_and_alloc_texture(struct st_context *st, width, height, depth, - comp_byte); + comp_byte, + ( PIPE_TEXTURE_USAGE_RENDER_TARGET | + PIPE_TEXTURE_USAGE_SAMPLER )); DBG("%s - success\n", __FUNCTION__); } @@ -1501,7 +1503,11 @@ st_finalize_texture(GLcontext *ctx, firstImage->base.Width2, firstImage->base.Height2, firstImage->base.Depth2, - comp_byte); + comp_byte, + + ( PIPE_TEXTURE_USAGE_RENDER_TARGET | + PIPE_TEXTURE_USAGE_SAMPLER )); + if (!stObj->pt) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage"); return GL_FALSE; diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c index d6268fc80c..2b3742d4e5 100644 --- a/src/mesa/state_tracker/st_texture.c +++ b/src/mesa/state_tracker/st_texture.c @@ -75,7 +75,8 @@ st_texture_create(struct st_context *st, GLuint width0, GLuint height0, GLuint depth0, - GLuint compress_byte) + GLuint compress_byte, + GLuint usage ) { struct pipe_texture pt, *newtex; struct pipe_screen *screen = st->pipe->screen; @@ -98,6 +99,7 @@ st_texture_create(struct st_context *st, pt.depth[0] = depth0; pt.compressed = compress_byte ? 1 : 0; pt.cpp = pt.compressed ? compress_byte : st_sizeof_format(format); + pt.tex_usage = usage; newtex = screen->texture_create(screen, &pt); diff --git a/src/mesa/state_tracker/st_texture.h b/src/mesa/state_tracker/st_texture.h index f6d5733e21..6a9f08ec6b 100644 --- a/src/mesa/state_tracker/st_texture.h +++ b/src/mesa/state_tracker/st_texture.h @@ -105,7 +105,8 @@ st_texture_create(struct st_context *st, GLuint width0, GLuint height0, GLuint depth0, - GLuint compress_byte); + GLuint compress_byte, + GLuint tex_usage ); /* Check if an image fits into an existing texture object. -- cgit v1.2.3 From b2021e7c06a9ec13b82eeeb352ad2408fe060518 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Fri, 2 May 2008 17:56:01 +0100 Subject: gallium: identify depth-stencil textures And don't use the display-target path to allocate them. --- src/gallium/include/pipe/p_state.h | 3 ++- src/mesa/state_tracker/st_cb_fbo.c | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h index d7565dff96..4936b7f507 100644 --- a/src/gallium/include/pipe/p_state.h +++ b/src/gallium/include/pipe/p_state.h @@ -286,7 +286,8 @@ struct pipe_surface #define PIPE_TEXTURE_USAGE_RENDER_TARGET 0x1 #define PIPE_TEXTURE_USAGE_DISPLAY_TARGET 0x2 /* ie a backbuffer */ -#define PIPE_TEXTURE_USAGE_SAMPLER 0x4 +#define PIPE_TEXTURE_USAGE_DEPTH_STENCIL 0x4 +#define PIPE_TEXTURE_USAGE_SAMPLER 0x8 /** * Texture object. diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 21d61e2163..cb5736f7c3 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -77,6 +77,11 @@ init_renderbuffer_bits(struct st_renderbuffer *strb, return info.size; } +static INLINE GLboolean pf_is_depth_stencil( enum pipe_format format ) +{ + return (pf_get_component_bits( format, PIPE_FORMAT_COMP_Z ) + + pf_get_component_bits( format, PIPE_FORMAT_COMP_S )) != 0; +} /** * gl_renderbuffer::AllocStorage() @@ -117,8 +122,15 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, template.height[0] = height; template.depth[0] = 1; template.last_level = 0; - template.tex_usage = (PIPE_TEXTURE_USAGE_DISPLAY_TARGET | - PIPE_TEXTURE_USAGE_RENDER_TARGET); + + if (pf_is_depth_stencil(template.format)) { + template.tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL; + } + else { + template.tex_usage = (PIPE_TEXTURE_USAGE_DISPLAY_TARGET | + PIPE_TEXTURE_USAGE_RENDER_TARGET); + } + /* Probably need dedicated flags for surface usage too: */ -- cgit v1.2.3 From 99df379b2c5b8e4e2ee7e5f2af864daf0a9eb1f7 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 2 May 2008 11:12:15 -0600 Subject: gallium: set template.target = PIPE_TEXTURE_2D --- src/mesa/state_tracker/st_cb_fbo.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index cb5736f7c3..1fa82b07e6 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -116,6 +116,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, strb->Base.Height = height; init_renderbuffer_bits(strb, template.format); + template.target = PIPE_TEXTURE_2D; template.compressed = 0; template.cpp = pf_get_size(template.format); template.width[0] = width; -- cgit v1.2.3 From 973d0c014dba87308e358291de0730d38d50a733 Mon Sep 17 00:00:00 2001 From: Michal Danzer Date: Tue, 6 May 2008 12:35:25 -0600 Subject: gallium: create renderbuffer surface w/out CPU_READ/WRITE flags --- src/mesa/state_tracker/st_cb_fbo.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 1fa82b07e6..e0578f0b4d 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -385,8 +385,6 @@ st_render_texture(GLcontext *ctx, att->CubeMapFace, att->TextureLevel, att->Zoffset, - PIPE_BUFFER_USAGE_CPU_READ | - PIPE_BUFFER_USAGE_CPU_WRITE | PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE); assert(strb->surface); -- cgit v1.2.3 From 296378b6c8b205048244746e260739448c4ee590 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 6 May 2008 13:47:41 -0600 Subject: gallium: create drawing surfaces as GPU_READ/WRITE only Create different temporary surfaces for CPU_READ/WRITE when needed (such as for glReadPixels, glAccum, some glCopy/DrawPixels, glCopyTexSubImage, etc). --- src/mesa/state_tracker/st_cb_accum.c | 73 ++++++++++++++++++++++--------- src/mesa/state_tracker/st_cb_drawpixels.c | 33 +++++++++++--- src/mesa/state_tracker/st_cb_fbo.c | 25 ++++++----- src/mesa/state_tracker/st_cb_fbo.h | 3 +- src/mesa/state_tracker/st_cb_readpixels.c | 34 +++++++++----- src/mesa/state_tracker/st_cb_texture.c | 10 ++++- 6 files changed, 129 insertions(+), 49 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_accum.c b/src/mesa/state_tracker/st_cb_accum.c index e4ef3e16b7..8098d75e18 100644 --- a/src/mesa/state_tracker/st_cb_accum.c +++ b/src/mesa/state_tracker/st_cb_accum.c @@ -105,7 +105,7 @@ void st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { struct st_renderbuffer *acc_strb = st_renderbuffer(rb); - struct pipe_surface *acc_ps = acc_strb->surface; + struct pipe_surface *acc_ps; struct pipe_screen *screen = ctx->st->pipe->screen; const GLint xpos = ctx->DrawBuffer->_Xmin; const GLint ypos = ctx->DrawBuffer->_Ymin; @@ -113,6 +113,8 @@ st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) const GLint height = ctx->DrawBuffer->_Ymax - ypos; GLvoid *map; + acc_ps = screen->get_tex_surface(screen, acc_strb->texture, 0, 0, 0, + PIPE_BUFFER_USAGE_CPU_WRITE); map = screen->surface_map(screen, acc_ps, PIPE_BUFFER_USAGE_CPU_WRITE); @@ -143,6 +145,7 @@ st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) } screen->surface_unmap(screen, acc_ps); + pipe_surface_reference(&acc_ps, NULL); } @@ -185,70 +188,100 @@ accum_mad(GLcontext *ctx, GLfloat scale, GLfloat bias, static void accum_accum(struct pipe_context *pipe, GLfloat value, GLint xpos, GLint ypos, GLint width, GLint height, - struct pipe_surface *acc_ps, - struct pipe_surface *color_ps) + struct st_renderbuffer *acc_strb, + struct st_renderbuffer *color_strb) { + struct pipe_screen *screen = pipe->screen; + struct pipe_surface *acc_surf, *color_surf; GLfloat *colorBuf, *accBuf; GLint i; + acc_surf = screen->get_tex_surface(screen, acc_strb->texture, 0, 0, 0, + (PIPE_BUFFER_USAGE_CPU_WRITE | + PIPE_BUFFER_USAGE_CPU_READ)); + + color_surf = screen->get_tex_surface(screen, color_strb->texture, 0, 0, 0, + PIPE_BUFFER_USAGE_CPU_READ); + colorBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); accBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - pipe_get_tile_rgba(pipe, color_ps, xpos, ypos, width, height, colorBuf); - acc_get_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf); + pipe_get_tile_rgba(pipe, color_surf, xpos, ypos, width, height, colorBuf); + acc_get_tile_rgba(pipe, acc_surf, xpos, ypos, width, height, accBuf); for (i = 0; i < 4 * width * height; i++) { accBuf[i] = accBuf[i] + colorBuf[i] * value; } - acc_put_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, accBuf); + acc_put_tile_rgba(pipe, acc_surf, xpos, ypos, width, height, accBuf); free(colorBuf); free(accBuf); + pipe_surface_reference(&acc_surf, NULL); + pipe_surface_reference(&color_surf, NULL); } static void accum_load(struct pipe_context *pipe, GLfloat value, GLint xpos, GLint ypos, GLint width, GLint height, - struct pipe_surface *acc_ps, - struct pipe_surface *color_ps) + struct st_renderbuffer *acc_strb, + struct st_renderbuffer *color_strb) { + struct pipe_screen *screen = pipe->screen; + struct pipe_surface *acc_surf, *color_surf; GLfloat *buf; GLint i; + acc_surf = screen->get_tex_surface(screen, acc_strb->texture, 0, 0, 0, + PIPE_BUFFER_USAGE_CPU_WRITE); + + color_surf = screen->get_tex_surface(screen, color_strb->texture, 0, 0, 0, + PIPE_BUFFER_USAGE_CPU_READ); + buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - pipe_get_tile_rgba(pipe, color_ps, xpos, ypos, width, height, buf); + pipe_get_tile_rgba(pipe, color_surf, xpos, ypos, width, height, buf); for (i = 0; i < 4 * width * height; i++) { buf[i] = buf[i] * value; } - acc_put_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, buf); + acc_put_tile_rgba(pipe, acc_surf, xpos, ypos, width, height, buf); free(buf); + pipe_surface_reference(&acc_surf, NULL); + pipe_surface_reference(&color_surf, NULL); } static void accum_return(GLcontext *ctx, GLfloat value, GLint xpos, GLint ypos, GLint width, GLint height, - struct pipe_surface *acc_ps, - struct pipe_surface *color_ps) + struct st_renderbuffer *acc_strb, + struct st_renderbuffer *color_strb) { struct pipe_context *pipe = ctx->st->pipe; + struct pipe_screen *screen = pipe->screen; const GLubyte *colormask = ctx->Color.ColorMask; + struct pipe_surface *acc_surf, *color_surf; GLfloat *abuf, *cbuf = NULL; GLint i, ch; abuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - acc_get_tile_rgba(pipe, acc_ps, xpos, ypos, width, height, abuf); + acc_surf = screen->get_tex_surface(screen, acc_strb->texture, 0, 0, 0, + PIPE_BUFFER_USAGE_CPU_READ); + + color_surf = screen->get_tex_surface(screen, color_strb->texture, 0, 0, 0, + (PIPE_BUFFER_USAGE_CPU_READ | + PIPE_BUFFER_USAGE_CPU_WRITE)); + + acc_get_tile_rgba(pipe, acc_surf, xpos, ypos, width, height, abuf); if (!colormask[0] || !colormask[1] || !colormask[2] || !colormask[3]) { cbuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - pipe_get_tile_rgba(pipe, color_ps, xpos, ypos, width, height, cbuf); + pipe_get_tile_rgba(pipe, color_surf, xpos, ypos, width, height, cbuf); } for (i = 0; i < width * height; i++) { @@ -263,11 +296,13 @@ accum_return(GLcontext *ctx, GLfloat value, } } - pipe_put_tile_rgba(pipe, color_ps, xpos, ypos, width, height, abuf); + pipe_put_tile_rgba(pipe, color_surf, xpos, ypos, width, height, abuf); free(abuf); if (cbuf) free(cbuf); + pipe_surface_reference(&acc_surf, NULL); + pipe_surface_reference(&color_surf, NULL); } @@ -280,8 +315,6 @@ st_Accum(GLcontext *ctx, GLenum op, GLfloat value) = st_renderbuffer(ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer); struct st_renderbuffer *color_strb = st_renderbuffer(ctx->ReadBuffer->_ColorReadBuffer); - struct pipe_surface *acc_ps = acc_strb->surface; - struct pipe_surface *color_ps = color_strb->surface; const GLint xpos = ctx->DrawBuffer->_Xmin; const GLint ypos = ctx->DrawBuffer->_Ymin; @@ -304,14 +337,14 @@ st_Accum(GLcontext *ctx, GLenum op, GLfloat value) break; case GL_ACCUM: if (value != 0.0F) { - accum_accum(pipe, value, xpos, ypos, width, height, acc_ps, color_ps); + accum_accum(pipe, value, xpos, ypos, width, height, acc_strb, color_strb); } break; case GL_LOAD: - accum_load(pipe, value, xpos, ypos, width, height, acc_ps, color_ps); + accum_load(pipe, value, xpos, ypos, width, height, acc_strb, color_strb); break; case GL_RETURN: - accum_return(ctx, value, xpos, ypos, width, height, acc_ps, color_ps); + accum_return(ctx, value, xpos, ypos, width, height, acc_strb, color_strb); break; default: assert(0); diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 6ec3c343cd..c967c989de 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -734,13 +734,19 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, struct st_context *st = ctx->st; struct pipe_context *pipe = st->pipe; struct pipe_screen *screen = pipe->screen; - struct pipe_surface *ps = st->state.framebuffer.zsbuf; + struct st_renderbuffer *strb; + struct pipe_surface *ps; const GLboolean zoom = ctx->Pixel.ZoomX != 1.0 || ctx->Pixel.ZoomY != 1.0; GLint skipPixels; ubyte *stmap; pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); + strb = st_renderbuffer(ctx->DrawBuffer-> + Attachment[BUFFER_STENCIL].Renderbuffer); + ps = screen->get_tex_surface(screen, strb->texture, 0, 0, 0, + PIPE_BUFFER_USAGE_CPU_WRITE); + /* map the stencil buffer */ stmap = screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_WRITE); @@ -801,6 +807,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, /* unmap the stencil buffer */ screen->surface_unmap(screen, ps); + pipe_surface_reference(&ps, NULL); } @@ -874,7 +881,7 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, { struct st_renderbuffer *rbDraw = st_renderbuffer(ctx->DrawBuffer->_StencilBuffer); struct pipe_screen *screen = ctx->st->pipe->screen; - struct pipe_surface *psDraw = rbDraw->surface; + struct pipe_surface *psDraw; ubyte *drawMap; ubyte *buffer; int i; @@ -889,6 +896,9 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, st_read_stencil_pixels(ctx, srcx, srcy, width, height, GL_UNSIGNED_BYTE, &ctx->DefaultPacking, buffer); + psDraw = screen->get_tex_surface(screen, rbDraw->texture, 0, 0, 0, + PIPE_BUFFER_USAGE_CPU_WRITE); + /* map the stencil buffer */ drawMap = screen->surface_map(screen, psDraw, PIPE_BUFFER_USAGE_CPU_WRITE); @@ -931,6 +941,7 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, /* unmap the stencil buffer */ screen->surface_unmap(screen, psDraw); + pipe_surface_reference(&psDraw, NULL); } @@ -945,7 +956,6 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, struct st_renderbuffer *rbRead; struct st_vertex_program *stvp; struct st_fragment_program *stfp; - struct pipe_surface *psRead; struct pipe_surface *psTex; struct pipe_texture *pt; GLfloat *color; @@ -976,8 +986,12 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, stvp = st_make_passthrough_vertex_shader(ctx->st, GL_TRUE); } +#if 0 psRead = rbRead->surface; srcFormat = psRead->format; +#else + srcFormat = rbRead->texture->format; +#endif if (screen->is_format_supported(screen, srcFormat, PIPE_TEXTURE)) { texFormat = srcFormat; @@ -1005,18 +1019,26 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, } if (srcFormat == texFormat) { + /* copy source framebuffer surface into mipmap/texture */ + struct pipe_surface *psRead = screen->get_tex_surface(screen, + rbRead->texture, 0, 0, 0, + PIPE_BUFFER_USAGE_GPU_READ); psTex = screen->get_tex_surface(screen, pt, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE ); - - /* copy source framebuffer surface into mipmap/texture */ pipe->surface_copy(pipe, FALSE, psTex, /* dest */ 0, 0, /* destx/y */ psRead, srcx, srcy, width, height); + pipe_surface_reference(&psRead, NULL); } else { + /* CPU-based fallback/conversion */ + struct pipe_surface *psRead = screen->get_tex_surface(screen, + rbRead->texture, 0, 0, 0, + PIPE_BUFFER_USAGE_CPU_READ); + psTex = screen->get_tex_surface(screen, pt, 0, 0, 0, PIPE_BUFFER_USAGE_CPU_WRITE ); @@ -1036,6 +1058,7 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, pipe_put_tile_z(pipe, psTex, 0, 0, width, height, buf); free(buf); } + pipe_surface_reference(&psRead, NULL); } pipe_surface_reference(&psTex, NULL); diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index e0578f0b4d..747d4905e6 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -95,7 +95,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, { struct pipe_context *pipe = ctx->st->pipe; struct st_renderbuffer *strb = st_renderbuffer(rb); - struct pipe_texture template, *texture; + struct pipe_texture template; unsigned surface_usage; /* Free the old surface (and texture if we hold the last @@ -136,12 +136,14 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, /* Probably need dedicated flags for surface usage too: */ surface_usage = (PIPE_BUFFER_USAGE_GPU_READ | - PIPE_BUFFER_USAGE_GPU_WRITE | + PIPE_BUFFER_USAGE_GPU_WRITE); +#if 0 PIPE_BUFFER_USAGE_CPU_READ | PIPE_BUFFER_USAGE_CPU_WRITE); +#endif - texture = pipe->screen->texture_create( pipe->screen, - &template ); + strb->texture = pipe->screen->texture_create( pipe->screen, + &template ); /* Special path for accum buffers. * @@ -149,7 +151,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, * only for now, the surface pixel format doesn't really matter, * only that the buffer is large enough. */ - if (!texture && template.format == DEFAULT_ACCUM_PIPE_FORMAT) + if (!strb->texture && template.format == DEFAULT_ACCUM_PIPE_FORMAT) { /* Actually, just setting this usage value should be sufficient * to tell the driver to go ahead and allocate the buffer, even @@ -159,21 +161,19 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, surface_usage = (PIPE_BUFFER_USAGE_CPU_READ | PIPE_BUFFER_USAGE_CPU_WRITE); - texture = pipe->screen->texture_create( pipe->screen, - &template ); + strb->texture = pipe->screen->texture_create( pipe->screen, + &template ); } - if (!texture) + if (!strb->texture) return FALSE; strb->surface = pipe->screen->get_tex_surface( pipe->screen, - texture, + strb->texture, 0, 0, 0, surface_usage ); - pipe_texture_reference( &texture, NULL ); - assert(strb->surface->buffer); assert(strb->surface->format); assert(strb->surface->cpp); @@ -195,6 +195,7 @@ st_renderbuffer_delete(struct gl_renderbuffer *rb) struct st_renderbuffer *strb = st_renderbuffer(rb); ASSERT(strb); pipe_surface_reference(&strb->surface, NULL); + pipe_texture_reference(&strb->texture, NULL); free(strb); } @@ -380,6 +381,8 @@ st_render_texture(GLcontext *ctx, rb->Width = pt->width[att->TextureLevel]; rb->Height = pt->height[att->TextureLevel]; + pipe_texture_reference( &strb->texture, pt ); + /* the renderbuffer's surface is inside the texture */ strb->surface = screen->get_tex_surface(screen, pt, att->CubeMapFace, diff --git a/src/mesa/state_tracker/st_cb_fbo.h b/src/mesa/state_tracker/st_cb_fbo.h index c1aa14f9b2..f9cec91314 100644 --- a/src/mesa/state_tracker/st_cb_fbo.h +++ b/src/mesa/state_tracker/st_cb_fbo.h @@ -41,7 +41,8 @@ struct st_renderbuffer { struct gl_renderbuffer Base; - struct pipe_surface *surface; + struct pipe_texture *texture; + struct pipe_surface *surface; /* temporary view into texture */ enum pipe_format format; /** preferred format, or PIPE_FORMAT_NONE */ }; diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c index e242195e7a..0b2b9d544d 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -63,10 +63,14 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, struct gl_framebuffer *fb = ctx->ReadBuffer; struct pipe_screen *screen = ctx->st->pipe->screen; struct st_renderbuffer *strb = st_renderbuffer(fb->_StencilBuffer); - struct pipe_surface *ps = strb->surface; + struct pipe_surface *ps; ubyte *stmap; GLint j; + /* Create a CPU-READ surface/view into the renderbuffer's texture */ + ps = screen->get_tex_surface(screen, strb->texture, 0, 0, 0, + PIPE_BUFFER_USAGE_CPU_READ); + /* map the stencil buffer */ stmap = screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_READ); @@ -126,6 +130,7 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, /* unmap the stencil buffer */ screen->surface_unmap(screen, ps); + pipe_surface_reference(&ps, NULL); } @@ -169,12 +174,14 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, GLvoid *dest) { struct pipe_context *pipe = ctx->st->pipe; + struct pipe_screen *screen = pipe->screen; GLfloat temp[MAX_WIDTH][4]; const GLbitfield transferOps = ctx->_ImageTransferState; GLint i, yStep, dfStride; GLfloat *df; struct st_renderbuffer *strb; struct gl_pixelstore_attrib clippedPacking = *pack; + struct pipe_surface *surf; /* XXX convolution not done yet */ assert((transferOps & IMAGE_CONVOLUTION_BIT) == 0); @@ -230,6 +237,10 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, yStep = 1; } + /* Create a CPU-READ surface/view into the renderbuffer's texture */ + surf = screen->get_tex_surface(screen, strb->texture, 0, 0, 0, + PIPE_BUFFER_USAGE_CPU_READ); + /* * Copy pixels from pipe_surface to user memory */ @@ -241,15 +252,14 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, const GLint dstStride = _mesa_image_row_stride(&clippedPacking, width, format, type); - if (strb->surface->format == PIPE_FORMAT_S8Z24_UNORM || - strb->surface->format == PIPE_FORMAT_X8Z24_UNORM) { + if (surf->format == PIPE_FORMAT_S8Z24_UNORM || + surf->format == PIPE_FORMAT_X8Z24_UNORM) { if (format == GL_DEPTH_COMPONENT) { for (i = 0; i < height; i++) { GLuint ztemp[MAX_WIDTH], j; GLfloat zfloat[MAX_WIDTH]; const double scale = 1.0 / ((1 << 24) - 1); - pipe_get_tile_raw(pipe, strb->surface, x, y, - width, 1, ztemp, 0); + pipe_get_tile_raw(pipe, surf, x, y, width, 1, ztemp, 0); y += yStep; for (j = 0; j < width; j++) { zfloat[j] = (float) (scale * (ztemp[j] & 0xffffff)); @@ -263,18 +273,18 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, /* untested, but simple: */ assert(format == GL_DEPTH_STENCIL_EXT); for (i = 0; i < height; i++) { - pipe_get_tile_raw(pipe, strb->surface, x, y, width, 1, dst, 0); + pipe_get_tile_raw(pipe, surf, x, y, width, 1, dst, 0); y += yStep; dst += dstStride; } } } - else if (strb->surface->format == PIPE_FORMAT_Z16_UNORM) { + else if (surf->format == PIPE_FORMAT_Z16_UNORM) { for (i = 0; i < height; i++) { GLushort ztemp[MAX_WIDTH], j; GLfloat zfloat[MAX_WIDTH]; const double scale = 1.0 / 0xffff; - pipe_get_tile_raw(pipe, strb->surface, x, y, width, 1, ztemp, 0); + pipe_get_tile_raw(pipe, surf, x, y, width, 1, ztemp, 0); y += yStep; for (j = 0; j < width; j++) { zfloat[j] = (float) (scale * ztemp[j]); @@ -284,12 +294,12 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, dst += dstStride; } } - else if (strb->surface->format == PIPE_FORMAT_Z32_UNORM) { + else if (surf->format == PIPE_FORMAT_Z32_UNORM) { for (i = 0; i < height; i++) { GLuint ztemp[MAX_WIDTH], j; GLfloat zfloat[MAX_WIDTH]; const double scale = 1.0 / 0xffffffff; - pipe_get_tile_raw(pipe, strb->surface, x, y, width, 1, ztemp, 0); + pipe_get_tile_raw(pipe, surf, x, y, width, 1, ztemp, 0); y += yStep; for (j = 0; j < width; j++) { zfloat[j] = (float) (scale * ztemp[j]); @@ -303,7 +313,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, /* RGBA format */ /* Do a row at a time to flip image data vertically */ for (i = 0; i < height; i++) { - pipe_get_tile_rgba(pipe, strb->surface, x, y, width, 1, df); + pipe_get_tile_rgba(pipe, surf, x, y, width, 1, df); y += yStep; df += dfStride; if (!dfStride) { @@ -315,6 +325,8 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, } } + pipe_surface_reference(&surf, NULL); + _mesa_unmap_readpix_pbo(ctx, &clippedPacking); } diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index f6f833a0db..828b2340f2 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -306,6 +306,11 @@ guess_and_alloc_texture(struct st_context *st, depth <<= 1; } + if (width == 0 || height == 0 || depth == 0) { + /* no texture needed */ + return; + } + /* Guess a reasonable value for lastLevel. This is probably going * to be wrong fairly often and might mean that we have to look at * resizable buffers, or require that buffers implement lazy @@ -1059,6 +1064,8 @@ fallback_copy_texsubimage(GLcontext *ctx, } src_surf = strb->surface; + src_surf = screen->get_tex_surface(screen, strb->texture, face, level, destZ, + PIPE_BUFFER_USAGE_CPU_READ); dest_surf = screen->get_tex_surface(screen, pt, face, level, destZ, PIPE_BUFFER_USAGE_CPU_WRITE); @@ -1097,6 +1104,7 @@ fallback_copy_texsubimage(GLcontext *ctx, } screen->tex_surface_release(screen, &dest_surf); + screen->tex_surface_release(screen, &src_surf); } @@ -1164,7 +1172,7 @@ do_copy_texsubimage(GLcontext *ctx, stImage->level, destZ, PIPE_BUFFER_USAGE_CPU_WRITE); - if (ctx->_ImageTransferState == 0x0 && + if (0&& ctx->_ImageTransferState == 0x0 && strb->surface->buffer && dest_surface->buffer) { /* do blit-style copy */ -- cgit v1.2.3 From 1a82d9648b3db780e58e4966924157542d148c58 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 7 May 2008 16:44:33 -0600 Subject: gallium: fix some render to texture bugs Before, we were sometimes rendering into a stale texture because st_finalize_texture() would discard the old texture and create a new one. Moved st_update_framebuffer atom after texture validation so that we can create a new renderbuffer surface if the texture changes. Also, split texture validation into two parts: finalize_textures and update_textures. Do finalize_textures first to avoid getting into the situtation where we're doing a pipe->surface_copy() mid-way through state validation. Some debug code still in place, but disabled... --- src/mesa/state_tracker/st_atom.c | 3 +- src/mesa/state_tracker/st_atom.h | 1 + src/mesa/state_tracker/st_atom_framebuffer.c | 60 ++++++++++++++++++++- src/mesa/state_tracker/st_atom_shader.c | 26 ++++++++- src/mesa/state_tracker/st_atom_texture.c | 80 +++++++++++++++++----------- src/mesa/state_tracker/st_cb_fbo.c | 34 +++++++++--- src/mesa/state_tracker/st_cb_fbo.h | 3 ++ src/mesa/state_tracker/st_cb_readpixels.c | 2 + src/mesa/state_tracker/st_cb_texture.c | 1 + src/mesa/state_tracker/st_context.h | 3 ++ src/mesa/state_tracker/st_texture.c | 16 ++++++ 11 files changed, 189 insertions(+), 40 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c index 18063adc79..ecfd117918 100644 --- a/src/mesa/state_tracker/st_atom.c +++ b/src/mesa/state_tracker/st_atom.c @@ -45,10 +45,10 @@ */ static const struct st_tracked_state *atoms[] = { - &st_update_framebuffer, &st_update_depth_stencil_alpha, &st_update_clip, + &st_finalize_textures, &st_update_shader, &st_update_rasterizer, @@ -58,6 +58,7 @@ static const struct st_tracked_state *atoms[] = &st_update_blend, &st_update_sampler, &st_update_texture, + &st_update_framebuffer, &st_update_vs_constants, &st_update_fs_constants, &st_update_pixel_transfer diff --git a/src/mesa/state_tracker/st_atom.h b/src/mesa/state_tracker/st_atom.h index c6c6eba812..c7cffd85c8 100644 --- a/src/mesa/state_tracker/st_atom.h +++ b/src/mesa/state_tracker/st_atom.h @@ -55,6 +55,7 @@ extern const struct st_tracked_state st_update_scissor; extern const struct st_tracked_state st_update_blend; extern const struct st_tracked_state st_update_sampler; extern const struct st_tracked_state st_update_texture; +extern const struct st_tracked_state st_finalize_textures; extern const struct st_tracked_state st_update_fs_constants; extern const struct st_tracked_state st_update_vs_constants; extern const struct st_tracked_state st_update_pixel_transfer; diff --git a/src/mesa/state_tracker/st_atom_framebuffer.c b/src/mesa/state_tracker/st_atom_framebuffer.c index 0a6974d8a7..c9a30e44b2 100644 --- a/src/mesa/state_tracker/st_atom_framebuffer.c +++ b/src/mesa/state_tracker/st_atom_framebuffer.c @@ -34,13 +34,60 @@ #include "st_context.h" #include "st_atom.h" #include "st_cb_fbo.h" +#include "st_texture.h" #include "pipe/p_context.h" +#include "pipe/p_inlines.h" #include "cso_cache/cso_context.h" + +/** + * When doing GL render to texture, we have to be sure that finalize_texture() + * didn't yank out the pipe_texture that we earlier created a surface for. + * Check for that here and create a new surface if needed. + */ +static void +update_renderbuffer_surface(struct st_context *st, + struct st_renderbuffer *strb) +{ + struct pipe_screen *screen = st->pipe->screen; + struct pipe_texture *texture = strb->rtt->pt; + int rtt_width = strb->Base.Width; + int rtt_height = strb->Base.Height; + + if (!strb->surface || + strb->surface->texture != texture || + strb->surface->width != rtt_width || + strb->surface->height != rtt_height) { + int level; + /* find matching mipmap level size */ + for (level = 0; level <= texture->last_level; level++) { + if (texture->width[level] == rtt_width && + texture->height[level] == rtt_height) { + + pipe_surface_reference(&strb->surface, NULL); + + strb->surface = screen->get_tex_surface(screen, + texture, + strb->rtt_face, + level, + strb->rtt_slice, + PIPE_BUFFER_USAGE_GPU_READ | + PIPE_BUFFER_USAGE_GPU_WRITE); +#if 0 + printf("-- alloc new surface %d x %d into tex %p\n", + strb->surface->width, strb->surface->height, + texture); +#endif + break; + } + } + } +} + + /** * Update framebuffer state (color, depth, stencil, etc. buffers) - * XXX someday: separate draw/read buffers. */ static void update_framebuffer_state( struct st_context *st ) @@ -55,6 +102,8 @@ update_framebuffer_state( struct st_context *st ) framebuffer->width = fb->Width; framebuffer->height = fb->Height; + /*printf("------ fb size %d x %d\n", fb->Width, fb->Height);*/ + /* Examine Mesa's ctx->DrawBuffer->_ColorDrawBuffers state * to determine which surfaces to draw to */ @@ -62,6 +111,13 @@ update_framebuffer_state( struct st_context *st ) for (j = 0; j < MAX_DRAW_BUFFERS; j++) { for (i = 0; i < fb->_NumColorDrawBuffers[j]; i++) { strb = st_renderbuffer(fb->_ColorDrawBuffers[j][i]); + + /*printf("--------- framebuffer surface rtt %p\n", strb->rtt);*/ + if (strb->rtt) { + /* rendering to a GL texture, may have to update surface */ + update_renderbuffer_surface(st, strb); + } + assert(strb->surface); framebuffer->cbufs[framebuffer->num_cbufs] = strb->surface; framebuffer->num_cbufs++; @@ -99,7 +155,7 @@ const struct st_tracked_state st_update_framebuffer = { "st_update_framebuffer", /* name */ { /* dirty */ _NEW_BUFFERS, /* mesa */ - 0, /* st */ + ST_NEW_FRAMEBUFFER, /* st */ }, update_framebuffer_state /* update */ }; diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c index 7745591afb..8839ab380f 100644 --- a/src/mesa/state_tracker/st_atom_shader.c +++ b/src/mesa/state_tracker/st_atom_shader.c @@ -44,6 +44,8 @@ #include "pipe/p_context.h" #include "pipe/p_shader_tokens.h" +#include "util/u_simple_shaders.h" + #include "cso_cache/cso_context.h" #include "st_context.h" @@ -252,6 +254,20 @@ st_free_translated_vertex_programs(struct st_context *st, } +static void * +get_passthrough_fs(struct st_context *st) +{ + struct pipe_shader_state shader; + + if (!st->passthrough_fs) { + st->passthrough_fs = + util_make_fragment_passthrough_shader(st->pipe, &shader); + free((void *) shader.tokens); + } + + return st->passthrough_fs; +} + static void update_linkage( struct st_context *st ) @@ -277,7 +293,15 @@ update_linkage( struct st_context *st ) st_reference_fragprog(st, &st->fp, stfp); cso_set_vertex_shader_handle(st->cso_context, stvp->driver_shader); - cso_set_fragment_shader_handle(st->cso_context, stfp->driver_shader); + + if (st->missing_textures) { + /* use a pass-through frag shader that uses no textures */ + void *fs = get_passthrough_fs(st); + cso_set_fragment_shader_handle(st->cso_context, fs); + } + else { + cso_set_fragment_shader_handle(st->cso_context, stfp->driver_shader); + } st->vertex_result_to_slot = xvp->output_to_slot; } diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c index 767654f3d0..1ec671ed48 100644 --- a/src/mesa/state_tracker/st_atom_texture.c +++ b/src/mesa/state_tracker/st_atom_texture.c @@ -39,34 +39,13 @@ #include "pipe/p_context.h" #include "pipe/p_inlines.h" #include "cso_cache/cso_context.h" -#include "util/u_simple_shaders.h" -static void * -get_passthrough_fs(struct st_context *st) -{ - struct pipe_shader_state shader; - - if (!st->passthrough_fs) { - st->passthrough_fs = - util_make_fragment_passthrough_shader(st->pipe, &shader); - free((void *) shader.tokens); - } - - return st->passthrough_fs; -} - - -/** - * XXX This needs some work yet.... - * Need to "upload" texture images at appropriate times. - */ static void update_textures(struct st_context *st) { struct gl_fragment_program *fprog = st->ctx->FragmentProgram._Current; GLuint su; - GLboolean missing_textures = GL_FALSE; st->state.num_textures = 0; @@ -85,13 +64,11 @@ update_textures(struct st_context *st) retval = st_finalize_texture(st->ctx, st->pipe, texObj, &flush); if (!retval) { /* out of mem */ - missing_textures = GL_TRUE; + /* missing texture */ continue; } st->state.num_textures = su + 1; - - stObj->teximage_realloc = TRUE; } pt = st_get_stobj_texture(stObj); @@ -103,12 +80,6 @@ update_textures(struct st_context *st) cso_set_sampler_textures(st->cso_context, st->state.num_textures, st->state.sampler_texture); - - if (missing_textures) { - /* use a pass-through frag shader that uses no textures */ - void *fs = get_passthrough_fs(st); - cso_set_fragment_shader_handle(st->cso_context, fs); - } } @@ -120,3 +91,52 @@ const struct st_tracked_state st_update_texture = { }, update_textures /* update */ }; + + + + +static void +finalize_textures(struct st_context *st) +{ + struct gl_fragment_program *fprog = st->ctx->FragmentProgram._Current; + const GLboolean prev_missing_textures = st->missing_textures; + GLuint su; + + st->missing_textures = GL_FALSE; + + for (su = 0; su < st->ctx->Const.MaxTextureCoordUnits; su++) { + if (fprog->Base.SamplersUsed & (1 << su)) { + const GLuint texUnit = fprog->Base.SamplerUnits[su]; + struct gl_texture_object *texObj + = st->ctx->Texture.Unit[texUnit]._Current; + struct st_texture_object *stObj = st_texture_object(texObj); + + if (texObj) { + GLboolean flush, retval; + + retval = st_finalize_texture(st->ctx, st->pipe, texObj, &flush); + if (!retval) { + /* out of mem */ + st->missing_textures = GL_TRUE; + continue; + } + + stObj->teximage_realloc = TRUE; + } + } + } + + if (prev_missing_textures != st->missing_textures) + st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; +} + + + +const struct st_tracked_state st_finalize_textures = { + "st_finalize_textures", /* name */ + { /* dirty */ + _NEW_TEXTURE, /* mesa */ + 0, /* st */ + }, + finalize_textures /* update */ +}; diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 747d4905e6..2368c31f4b 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -358,6 +358,10 @@ st_render_texture(GLcontext *ctx, struct pipe_context *pipe = st->pipe; struct pipe_screen *screen = pipe->screen; struct pipe_texture *pt; + struct st_texture_object *stObj; + const struct gl_texture_image *texImage = + att->Texture->Image[att->CubeMapFace][att->TextureLevel]; + assert(!att->Renderbuffer); @@ -374,27 +378,42 @@ st_render_texture(GLcontext *ctx, strb = st_renderbuffer(rb); /* get the texture for the texture object */ + stObj = st_texture_object(att->Texture); + + /* point renderbuffer at texobject */ + strb->rtt = stObj; + strb->rtt_level = att->TextureLevel; + strb->rtt_face = att->CubeMapFace; + strb->rtt_slice = att->Zoffset; + + rb->Width = texImage->Width2; + rb->Height = texImage->Height2; + /*printf("***** render to texture level %d: %d x %d\n", att->TextureLevel, rb->Width, rb->Height);*/ + pt = st_get_texobj_texture(att->Texture); assert(pt); - assert(pt->width[att->TextureLevel]); - - rb->Width = pt->width[att->TextureLevel]; - rb->Height = pt->height[att->TextureLevel]; + /*printf("***** pipe texture %d x %d\n", pt->width[0], pt->height[0]);*/ pipe_texture_reference( &strb->texture, pt ); + pipe_surface_reference(&strb->surface, NULL); + +#if 0 /* the renderbuffer's surface is inside the texture */ strb->surface = screen->get_tex_surface(screen, pt, att->CubeMapFace, - att->TextureLevel, + att->TextureLevel /*- att->Texture->BaseLevel*/, att->Zoffset, PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE); + printf("***** surface size: %d x %d\n", strb->surface->width, strb->surface->height); + assert(strb->surface); assert(screen->is_format_supported(screen, strb->surface->format, PIPE_TEXTURE)); assert(screen->is_format_supported(screen, strb->surface->format, PIPE_SURFACE)); init_renderbuffer_bits(strb, pt->format); +#endif /* printf("RENDER TO TEXTURE obj=%p pt=%p surf=%p %d x %d\n", @@ -424,7 +443,10 @@ st_finish_render_texture(GLcontext *ctx, ctx->st->pipe->flush(ctx->st->pipe, PIPE_FLUSH_RENDER_CACHE, NULL); - screen->tex_surface_release( screen, &strb->surface ); + if (strb->surface) + screen->tex_surface_release( screen, &strb->surface ); + + strb->rtt = NULL; /* printf("FINISH RENDER TO TEXTURE surf=%p\n", strb->surface); diff --git a/src/mesa/state_tracker/st_cb_fbo.h b/src/mesa/state_tracker/st_cb_fbo.h index f9cec91314..87b0734a0c 100644 --- a/src/mesa/state_tracker/st_cb_fbo.h +++ b/src/mesa/state_tracker/st_cb_fbo.h @@ -44,6 +44,9 @@ struct st_renderbuffer struct pipe_texture *texture; struct pipe_surface *surface; /* temporary view into texture */ enum pipe_format format; /** preferred format, or PIPE_FORMAT_NONE */ + + struct st_texture_object *rtt; /**< GL render to texture's texture */ + int rtt_level, rtt_face, rtt_slice; }; diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c index 0b2b9d544d..3615fafc0a 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -183,6 +183,8 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, struct gl_pixelstore_attrib clippedPacking = *pack; struct pipe_surface *surf; + assert(ctx->ReadBuffer->Width > 0); + /* XXX convolution not done yet */ assert((transferOps & IMAGE_CONVOLUTION_BIT) == 0); diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 3206215b2e..3468b5f2a1 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -1496,6 +1496,7 @@ st_finalize_texture(GLcontext *ctx, stObj->pt->cpp != cpp || stObj->pt->compressed != firstImage->base.IsCompressed) { pipe_texture_release(&stObj->pt); + ctx->st->dirty.st |= ST_NEW_FRAMEBUFFER; } } diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 1ca779d0a9..69be4ebdd0 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -53,6 +53,7 @@ struct bitmap_cache; #define ST_NEW_MESA 0x1 /* Mesa state has changed */ #define ST_NEW_FRAGMENT_PROGRAM 0x2 #define ST_NEW_VERTEX_PROGRAM 0x4 +#define ST_NEW_FRAMEBUFFER 0x8 struct st_state_flags { @@ -121,6 +122,8 @@ struct st_context struct st_state_flags dirty; + GLboolean missing_textures; + GLfloat polygon_offset_scale; /* ?? */ /** Mapping from VERT_RESULT_x to post-transformed vertex slot */ diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c index 2b3742d4e5..d0f56c9717 100644 --- a/src/mesa/state_tracker/st_texture.c +++ b/src/mesa/state_tracker/st_texture.c @@ -315,6 +315,22 @@ st_texture_image_copy(struct pipe_context *pipe, assert(src->width[srcLevel] == width); assert(src->height[srcLevel] == height); +#if 0 + { + src_surface = screen->get_tex_surface(screen, src, face, srcLevel, i, + PIPE_BUFFER_USAGE_CPU_READ); + ubyte *map = screen->surface_map(screen, src_surface, PIPE_BUFFER_USAGE_CPU_READ); + map += src_surface->width * src_surface->height * 4 / 2; + printf("%s center pixel: %d %d %d %d (pt %p[%d] -> %p[%d])\n", + __FUNCTION__, + map[0], map[1], map[2], map[3], + src, srcLevel, dst, dstLevel); + + screen->surface_unmap(screen, src_surface); + pipe_surface_reference(&src_surface, NULL); + } +#endif + dst_surface = screen->get_tex_surface(screen, dst, face, dstLevel, i, PIPE_BUFFER_USAGE_GPU_WRITE); -- cgit v1.2.3 From f9e2f26df3c16eaa0c56db11cd94b5af7a361ee8 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 8 May 2008 17:45:59 -0600 Subject: gallium: re-enable call to init_renderbuffer_bits(), remove dead code --- src/mesa/state_tracker/st_cb_fbo.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 2368c31f4b..3e592730f8 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -398,22 +398,9 @@ st_render_texture(GLcontext *ctx, pipe_surface_reference(&strb->surface, NULL); -#if 0 - /* the renderbuffer's surface is inside the texture */ - strb->surface = screen->get_tex_surface(screen, pt, - att->CubeMapFace, - att->TextureLevel /*- att->Texture->BaseLevel*/, - att->Zoffset, - PIPE_BUFFER_USAGE_GPU_READ | - PIPE_BUFFER_USAGE_GPU_WRITE); - printf("***** surface size: %d x %d\n", strb->surface->width, strb->surface->height); - - assert(strb->surface); - assert(screen->is_format_supported(screen, strb->surface->format, PIPE_TEXTURE)); - assert(screen->is_format_supported(screen, strb->surface->format, PIPE_SURFACE)); + /* the new surface will be created during framebuffer validation */ init_renderbuffer_bits(strb, pt->format); -#endif /* printf("RENDER TO TEXTURE obj=%p pt=%p surf=%p %d x %d\n", -- cgit v1.2.3 From a1f95a8bf64f863289b6759caeec76d7e054400e Mon Sep 17 00:00:00 2001 From: Roland Scheidegger Date: Fri, 9 May 2008 15:04:33 +0200 Subject: gallium: depth textures have usage depth_stencil instead of render_target --- src/mesa/state_tracker/st_cb_fbo.c | 6 ------ src/mesa/state_tracker/st_cb_texture.c | 17 ++++++++++++----- src/mesa/state_tracker/st_texture.h | 5 +++++ 3 files changed, 17 insertions(+), 11 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 3e592730f8..3560a040c8 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -77,12 +77,6 @@ init_renderbuffer_bits(struct st_renderbuffer *strb, return info.size; } -static INLINE GLboolean pf_is_depth_stencil( enum pipe_format format ) -{ - return (pf_get_component_bits( format, PIPE_FORMAT_COMP_Z ) + - pf_get_component_bits( format, PIPE_FORMAT_COMP_S )) != 0; -} - /** * gl_renderbuffer::AllocStorage() * This is called to allocate the original drawing surface, and diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index c0dba4cf2d..fb78c87989 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -272,6 +272,7 @@ guess_and_alloc_texture(struct st_context *st, GLuint height = stImage->base.Height2; GLuint depth = stImage->base.Depth2; GLuint i, comp_byte = 0; + enum pipe_format fmt; DBG("%s\n", __FUNCTION__); @@ -331,15 +332,18 @@ guess_and_alloc_texture(struct st_context *st, if (stImage->base.IsCompressed) comp_byte = compressed_num_bytes(stImage->base.TexFormat->MesaFormat); + fmt = st_mesa_format_to_pipe_format(stImage->base.TexFormat->MesaFormat); stObj->pt = st_texture_create(st, gl_target_to_pipe(stObj->base.Target), - st_mesa_format_to_pipe_format(stImage->base.TexFormat->MesaFormat), + fmt, lastLevel, width, height, depth, comp_byte, - ( PIPE_TEXTURE_USAGE_RENDER_TARGET | + ( (pf_is_depth_stencil(fmt) ? + PIPE_TEXTURE_USAGE_DEPTH_STENCIL : + PIPE_TEXTURE_USAGE_RENDER_TARGET) | PIPE_TEXTURE_USAGE_SAMPLER )); DBG("%s - success\n", __FUNCTION__); @@ -1510,16 +1514,19 @@ st_finalize_texture(GLcontext *ctx, /* May need to create a new gallium texture: */ if (!stObj->pt) { + const enum pipe_format fmt = + st_mesa_format_to_pipe_format(firstImage->base.TexFormat->MesaFormat); stObj->pt = st_texture_create(ctx->st, gl_target_to_pipe(stObj->base.Target), - st_mesa_format_to_pipe_format(firstImage->base.TexFormat->MesaFormat), + fmt, stObj->lastLevel, firstImage->base.Width2, firstImage->base.Height2, firstImage->base.Depth2, comp_byte, - - ( PIPE_TEXTURE_USAGE_RENDER_TARGET | + ( (pf_is_depth_stencil(fmt) ? + PIPE_TEXTURE_USAGE_DEPTH_STENCIL : + PIPE_TEXTURE_USAGE_RENDER_TARGET) | PIPE_TEXTURE_USAGE_SAMPLER )); if (!stObj->pt) { diff --git a/src/mesa/state_tracker/st_texture.h b/src/mesa/state_tracker/st_texture.h index 55d1a367b5..3febe6a7cb 100644 --- a/src/mesa/state_tracker/st_texture.h +++ b/src/mesa/state_tracker/st_texture.h @@ -93,6 +93,11 @@ st_get_stobj_texture(struct st_texture_object *stObj) return stObj ? stObj->pt : NULL; } +static INLINE GLboolean pf_is_depth_stencil( enum pipe_format format ) +{ + return (pf_get_component_bits( format, PIPE_FORMAT_COMP_Z ) + + pf_get_component_bits( format, PIPE_FORMAT_COMP_S )) != 0; +} extern struct pipe_texture * -- cgit v1.2.3 From 635abed109b26ded34954c379b80e306c602384b Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 26 May 2008 13:30:10 -0600 Subject: gallium: free renderbuffer's old texture in st_renderbuffer_alloc_storage() --- src/mesa/state_tracker/st_cb_fbo.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 3560a040c8..76145a4d5c 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -92,10 +92,11 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, struct pipe_texture template; unsigned surface_usage; - /* Free the old surface (and texture if we hold the last - * reference): + /* Free the old surface and texture */ pipe_surface_reference( &strb->surface, NULL ); + pipe_texture_reference( &strb->texture, NULL ); + memset(&template, 0, sizeof(template)); -- cgit v1.2.3 From 158298eea075e87e4e3b4da9f6a606550f975b5d Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 19 Jun 2008 16:15:09 -0600 Subject: gallium: remove unused vars --- src/mesa/state_tracker/st_cb_fbo.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 76145a4d5c..db25ddd615 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -347,11 +347,8 @@ st_render_texture(GLcontext *ctx, struct gl_framebuffer *fb, struct gl_renderbuffer_attachment *att) { - struct st_context *st = ctx->st; struct st_renderbuffer *strb; struct gl_renderbuffer *rb; - struct pipe_context *pipe = st->pipe; - struct pipe_screen *screen = pipe->screen; struct pipe_texture *pt; struct st_texture_object *stObj; const struct gl_texture_image *texImage = -- cgit v1.2.3 From 4ddd65967915ca4846f2831bc676c878a29dae4a Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Fri, 27 Jun 2008 19:37:56 +0900 Subject: gallium: Drop pipe_texture->cpp and pipe_surface->cpp. The chars-per-pixel concept falls apart with compressed and yuv images, where more than one pixel are coded in a single data block. --- src/gallium/auxiliary/draw/draw_pipe_aaline.c | 4 +- src/gallium/auxiliary/draw/draw_pipe_pstipple.c | 6 +- src/gallium/auxiliary/util/p_tile.c | 98 ++++------- src/gallium/auxiliary/util/p_util.c | 100 +++++++++-- src/gallium/auxiliary/util/u_blit.c | 2 +- src/gallium/auxiliary/util/u_gen_mipmap.c | 8 +- src/gallium/drivers/i915simple/i915_blit.c | 2 - src/gallium/drivers/i915simple/i915_context.h | 6 +- src/gallium/drivers/i915simple/i915_state_emit.c | 4 +- .../drivers/i915simple/i915_state_sampler.c | 2 +- src/gallium/drivers/i915simple/i915_surface.c | 68 ++----- src/gallium/drivers/i915simple/i915_texture.c | 196 +++++++++++---------- src/gallium/drivers/i965simple/brw_context.h | 4 +- src/gallium/drivers/i965simple/brw_misc_state.c | 8 +- src/gallium/drivers/i965simple/brw_surface.c | 69 ++------ src/gallium/drivers/i965simple/brw_tex_layout.c | 117 ++++++------ .../drivers/i965simple/brw_wm_surface_state.c | 6 +- src/gallium/drivers/softpipe/sp_surface.c | 45 ++--- src/gallium/drivers/softpipe/sp_texture.c | 20 ++- src/gallium/drivers/softpipe/sp_texture.h | 2 +- src/gallium/include/pipe/p_format.h | 41 +++++ src/gallium/include/pipe/p_state.h | 11 +- src/gallium/include/pipe/p_util.h | 15 +- src/gallium/winsys/xlib/brw_aub.c | 9 +- src/gallium/winsys/xlib/xm_winsys.c | 24 +-- src/gallium/winsys/xlib/xm_winsys_aub.c | 31 ++-- src/mesa/state_tracker/st_cb_accum.c | 24 +-- src/mesa/state_tracker/st_cb_bitmap.c | 4 +- src/mesa/state_tracker/st_cb_drawpixels.c | 11 +- src/mesa/state_tracker/st_cb_fbo.c | 8 +- src/mesa/state_tracker/st_cb_readpixels.c | 6 +- src/mesa/state_tracker/st_cb_texture.c | 17 +- src/mesa/state_tracker/st_gen_mipmap.c | 4 +- src/mesa/state_tracker/st_texture.c | 26 ++- 34 files changed, 513 insertions(+), 485 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/gallium/auxiliary/draw/draw_pipe_aaline.c b/src/gallium/auxiliary/draw/draw_pipe_aaline.c index ecdebca5f1..3dd7ee19fd 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_aaline.c +++ b/src/gallium/auxiliary/draw/draw_pipe_aaline.c @@ -398,7 +398,7 @@ aaline_create_texture(struct aaline_stage *aaline) texTemp.width[0] = 1 << MAX_TEXTURE_LEVEL; texTemp.height[0] = 1 << MAX_TEXTURE_LEVEL; texTemp.depth[0] = 1; - texTemp.cpp = 1; + pf_get_block(texTemp.format, &texTemp.block); aaline->texture = screen->texture_create(screen, &texTemp); if (!aaline->texture) @@ -439,7 +439,7 @@ aaline_create_texture(struct aaline_stage *aaline) else { d = 255; } - data[i * surface->pitch + j] = d; + data[i * surface->stride + j] = d; } } diff --git a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c index 4087cf7a49..1f63f94365 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c +++ b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c @@ -394,11 +394,11 @@ pstip_update_texture(struct pstip_stage *pstip) for (j = 0; j < 32; j++) { if (stipple[i] & (bit31 >> j)) { /* fragment "on" */ - data[i * surface->pitch + j] = 0; + data[i * surface->stride + j] = 0; } else { /* fragment "off" */ - data[i * surface->pitch + j] = 255; + data[i * surface->stride + j] = 255; } } } @@ -426,7 +426,7 @@ pstip_create_texture(struct pstip_stage *pstip) texTemp.width[0] = 32; texTemp.height[0] = 32; texTemp.depth[0] = 1; - texTemp.cpp = 1; + pf_get_block(texTemp.format, &texTemp.block); pstip->texture = screen->texture_create(screen, &texTemp); if (pstip->texture == NULL) diff --git a/src/gallium/auxiliary/util/p_tile.c b/src/gallium/auxiliary/util/p_tile.c index 5728757d2f..ab603ff6e4 100644 --- a/src/gallium/auxiliary/util/p_tile.c +++ b/src/gallium/auxiliary/util/p_tile.c @@ -48,34 +48,23 @@ void pipe_get_tile_raw(struct pipe_context *pipe, struct pipe_surface *ps, uint x, uint y, uint w, uint h, - void *p, int dst_stride) + void *dst, int dst_stride) { struct pipe_screen *screen = pipe->screen; - const uint cpp = ps->cpp; - const ubyte *pSrc; - const uint src_stride = ps->pitch * cpp; - ubyte *pDest; - uint i; - - if (dst_stride == 0) { - dst_stride = w * cpp; - } + const void *src; if (pipe_clip_tile(x, y, &w, &h, ps)) return; - pSrc = (const ubyte *) screen->surface_map(screen, ps, - PIPE_BUFFER_USAGE_CPU_READ); - assert(pSrc); /* XXX: proper error handling! */ + if (dst_stride == 0) + dst_stride = pf_get_nblocksx(&ps->block, w) * ps->block.size; - pSrc += (y * ps->pitch + x) * cpp; - pDest = (ubyte *) p; + src = screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_READ); + assert(src); + if(!src) + return; - for (i = 0; i < h; i++) { - memcpy(pDest, pSrc, w * cpp); - pDest += dst_stride; - pSrc += src_stride; - } + pipe_copy_rect(dst, &ps->block, dst_stride, 0, 0, w, h, src, ps->stride, x, y); screen->surface_unmap(screen, ps); } @@ -89,34 +78,23 @@ void pipe_put_tile_raw(struct pipe_context *pipe, struct pipe_surface *ps, uint x, uint y, uint w, uint h, - const void *p, int src_stride) + const void *src, int src_stride) { struct pipe_screen *screen = pipe->screen; - const uint cpp = ps->cpp; - const ubyte *pSrc; - const uint dst_stride = ps->pitch * cpp; - ubyte *pDest; - uint i; - - if (src_stride == 0) { - src_stride = w * cpp; - } + void *dst; if (pipe_clip_tile(x, y, &w, &h, ps)) return; - pSrc = (const ubyte *) p; + if (src_stride == 0) + src_stride = pf_get_nblocksx(&ps->block, w) * ps->block.size; - pDest = screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_WRITE); - assert(pDest); /* XXX: proper error handling */ - - pDest += (y * ps->pitch + x) * cpp; + dst = screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_WRITE); + assert(dst); + if(!dst) + return; - for (i = 0; i < h; i++) { - memcpy(pDest, pSrc, w * cpp); - pDest += dst_stride; - pSrc += src_stride; - } + pipe_copy_rect(dst, &ps->block, ps->stride, x, y, w, h, src, src_stride, 0, 0); screen->surface_unmap(screen, ps); } @@ -692,12 +670,12 @@ pipe_get_tile_rgba(struct pipe_context *pipe, if (pipe_clip_tile(x, y, &w, &h, ps)) return; - packed = MALLOC(h * w * ps->cpp); + packed = MALLOC(pf_get_nblocks(&ps->block, w, h) * ps->block.size); if (!packed) return; - pipe_get_tile_raw(pipe, ps, x, y, w, h, packed, w * ps->cpp); + pipe_get_tile_raw(pipe, ps, x, y, w, h, packed, 0); switch (ps->format) { case PIPE_FORMAT_A8R8G8B8_UNORM: @@ -774,7 +752,7 @@ pipe_put_tile_rgba(struct pipe_context *pipe, if (pipe_clip_tile(x, y, &w, &h, ps)) return; - packed = MALLOC(h * w * ps->cpp); + packed = MALLOC(pf_get_nblocks(&ps->block, w, h) * ps->block.size); if (!packed) return; @@ -829,7 +807,7 @@ pipe_put_tile_rgba(struct pipe_context *pipe, assert(0); } - pipe_put_tile_raw(pipe, ps, x, y, w, h, packed, w * ps->cpp); + pipe_put_tile_raw(pipe, ps, x, y, w, h, packed, 0); FREE(packed); } @@ -846,14 +824,14 @@ pipe_get_tile_z(struct pipe_context *pipe, { struct pipe_screen *screen = pipe->screen; const uint dstStride = w; - void *map; + ubyte *map; uint *pDest = z; uint i, j; if (pipe_clip_tile(x, y, &w, &h, ps)) return; - map = screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_READ); + map = (ubyte *)screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_READ); if (!map) { assert(0); return; @@ -863,11 +841,11 @@ pipe_get_tile_z(struct pipe_context *pipe, case PIPE_FORMAT_Z32_UNORM: { const uint *pSrc - = (const uint *)map + (y * ps->pitch + x); + = (const uint *)(map + y * ps->stride + x*4); for (i = 0; i < h; i++) { memcpy(pDest, pSrc, 4 * w); pDest += dstStride; - pSrc += ps->pitch; + pSrc += ps->stride/4; } } break; @@ -875,28 +853,28 @@ pipe_get_tile_z(struct pipe_context *pipe, case PIPE_FORMAT_X8Z24_UNORM: { const uint *pSrc - = (const uint *)map + (y * ps->pitch + x); + = (const uint *)(map + y * ps->stride + x*4); for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { /* convert 24-bit Z to 32-bit Z */ pDest[j] = (pSrc[j] << 8) | (pSrc[j] & 0xff); } pDest += dstStride; - pSrc += ps->pitch; + pSrc += ps->stride/4; } } break; case PIPE_FORMAT_Z16_UNORM: { const ushort *pSrc - = (const ushort *)map + (y * ps->pitch + x); + = (const ushort *)(map + y * ps->stride + x*2); for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { /* convert 16-bit Z to 32-bit Z */ pDest[j] = (pSrc[j] << 16) | pSrc[j]; } pDest += dstStride; - pSrc += ps->pitch; + pSrc += ps->stride/2; } } break; @@ -917,13 +895,13 @@ pipe_put_tile_z(struct pipe_context *pipe, struct pipe_screen *screen = pipe->screen; const uint srcStride = w; const uint *pSrc = zSrc; - void *map; + ubyte *map; uint i, j; if (pipe_clip_tile(x, y, &w, &h, ps)) return; - map = screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_WRITE); + map = (ubyte *)screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_WRITE); if (!map) { assert(0); return; @@ -932,10 +910,10 @@ pipe_put_tile_z(struct pipe_context *pipe, switch (ps->format) { case PIPE_FORMAT_Z32_UNORM: { - uint *pDest = (uint *) map + (y * ps->pitch + x); + uint *pDest = (uint *) (map + y * ps->stride + x*4); for (i = 0; i < h; i++) { memcpy(pDest, pSrc, 4 * w); - pDest += ps->pitch; + pDest += ps->stride/4; pSrc += srcStride; } } @@ -943,26 +921,26 @@ pipe_put_tile_z(struct pipe_context *pipe, case PIPE_FORMAT_S8Z24_UNORM: case PIPE_FORMAT_X8Z24_UNORM: { - uint *pDest = (uint *) map + (y * ps->pitch + x); + uint *pDest = (uint *) (map + y * ps->stride + x*4); for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { /* convert 32-bit Z to 24-bit Z (0 stencil) */ pDest[j] = pSrc[j] >> 8; } - pDest += ps->pitch; + pDest += ps->stride/4; pSrc += srcStride; } } break; case PIPE_FORMAT_Z16_UNORM: { - ushort *pDest = (ushort *) map + (y * ps->pitch + x); + ushort *pDest = (ushort *) (map + y * ps->stride + x*2); for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { /* convert 32-bit Z to 16-bit Z */ pDest[j] = pSrc[j] >> 16; } - pDest += ps->pitch; + pDest += ps->stride/2; pSrc += srcStride; } } diff --git a/src/gallium/auxiliary/util/p_util.c b/src/gallium/auxiliary/util/p_util.c index 4e60b1b841..271be4edf1 100644 --- a/src/gallium/auxiliary/util/p_util.c +++ b/src/gallium/auxiliary/util/p_util.c @@ -32,6 +32,7 @@ #include "pipe/p_defines.h" #include "pipe/p_util.h" +#include "pipe/p_format.h" /** @@ -41,42 +42,109 @@ */ void pipe_copy_rect(ubyte * dst, - unsigned cpp, - unsigned dst_pitch, + const struct pipe_format_block *block, + unsigned dst_stride, unsigned dst_x, unsigned dst_y, unsigned width, unsigned height, const ubyte * src, - int src_pitch, + int src_stride, unsigned src_x, int src_y) { unsigned i; - int src_pitch_pos = src_pitch < 0 ? -src_pitch : src_pitch; + int src_stride_pos = src_stride < 0 ? -src_stride : src_stride; - assert(cpp > 0); + assert(block->size > 0); + assert(block->width > 0); + assert(block->height > 0); assert(src_x >= 0); assert(src_y >= 0); assert(dst_x >= 0); assert(dst_y >= 0); - dst_pitch *= cpp; - src_pitch *= cpp; - src_pitch_pos *= cpp; - dst += dst_x * cpp; - src += src_x * cpp; - dst += dst_y * dst_pitch; - src += src_y * src_pitch_pos; - width *= cpp; + dst_x /= block->width; + dst_y /= block->height; + width = (width + block->width - 1)/block->width; + height = (height + block->height - 1)/block->height; + src_x /= block->width; + src_y /= block->height; + + dst += dst_x * block->size; + src += src_x * block->size; + dst += dst_y * dst_stride; + src += src_y * src_stride_pos; + width *= block->size; - if (width == dst_pitch && width == src_pitch) + if (width == dst_stride && width == src_stride) memcpy(dst, src, height * width); else { for (i = 0; i < height; i++) { memcpy(dst, src, width); - dst += dst_pitch; - src += src_pitch; + dst += dst_stride; + src += src_stride; } } } + +void +pipe_fill_rect(ubyte * dst, + const struct pipe_format_block *block, + unsigned dst_stride, + unsigned dst_x, + unsigned dst_y, + unsigned width, + unsigned height, + uint32_t value) +{ + unsigned i, j; + unsigned width_size; + + assert(block->size > 0); + assert(block->width > 0); + assert(block->height > 0); + assert(dst_x >= 0); + assert(dst_y >= 0); + + dst_x /= block->width; + dst_y /= block->height; + width = (width + block->width - 1)/block->width; + height = (height + block->height - 1)/block->height; + + dst += dst_x * block->size; + dst += dst_y * dst_stride; + width_size = width * block->size; + + switch (block->size) { + case 1: + if(dst_stride == width_size) + memset(dst, (ubyte) value, height * width_size); + else { + for (i = 0; i < height; i++) { + memset(dst, (ubyte) value, width_size); + dst += dst_stride; + } + } + break; + case 2: + for (i = 0; i < height; i++) { + uint16_t *row = (uint16_t *)dst; + for (j = 0; j < width; j++) + *row++ = (uint16_t) value; + dst += dst_stride; + } + break; + case 4: + for (i = 0; i < height; i++) { + uint32_t *row = (uint32_t *)dst; + for (j = 0; j < width; j++) + *row++ = value; + dst += dst_stride; + } + break; + default: + assert(0); + break; + } +} diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c index 6555dcd588..ae779335dc 100644 --- a/src/gallium/auxiliary/util/u_blit.c +++ b/src/gallium/auxiliary/util/u_blit.c @@ -324,7 +324,7 @@ util_blit_pixels(struct blit_state *ctx, texTemp.height[0] = srcH; texTemp.depth[0] = 1; texTemp.compressed = 0; - texTemp.cpp = pf_get_size(src->format); + pf_get_block(src->format, &texTemp.block); tex = screen->texture_create(screen, &texTemp); if (!tex) diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c index 7d71aefda9..5313a8008a 100644 --- a/src/gallium/auxiliary/util/u_gen_mipmap.c +++ b/src/gallium/auxiliary/util/u_gen_mipmap.c @@ -625,7 +625,9 @@ make_2d_mipmap(struct gen_mipmap_state *ctx, struct pipe_winsys *winsys = pipe->winsys; const uint zslice = 0; uint dstLevel; - const int bpt = pf_get_size(pt->format); + + assert(pt->block.width == 1); + assert(pt->block.height == 1); for (dstLevel = baseLevel + 1; dstLevel <= lastLevel; dstLevel++) { const uint srcLevel = dstLevel - 1; @@ -646,9 +648,9 @@ make_2d_mipmap(struct gen_mipmap_state *ctx, reduce_2d(pt->format, srcSurf->width, srcSurf->height, - srcSurf->pitch * bpt, srcMap, + srcSurf->stride, srcMap, dstSurf->width, dstSurf->height, - dstSurf->pitch * bpt, dstMap); + dstSurf->stride, dstMap); winsys->buffer_unmap(winsys, srcSurf->buffer); winsys->buffer_unmap(winsys, dstSurf->buffer); diff --git a/src/gallium/drivers/i915simple/i915_blit.c b/src/gallium/drivers/i915simple/i915_blit.c index 22f91fab92..45fae4c999 100644 --- a/src/gallium/drivers/i915simple/i915_blit.c +++ b/src/gallium/drivers/i915simple/i915_blit.c @@ -47,8 +47,6 @@ i915_fill_blit(struct i915_context *i915, { unsigned BR13, CMD; - dst_pitch *= (short) cpp; - switch (cpp) { case 1: case 2: diff --git a/src/gallium/drivers/i915simple/i915_context.h b/src/gallium/drivers/i915simple/i915_context.h index 5d411a6648..c8db4f608c 100644 --- a/src/gallium/drivers/i915simple/i915_context.h +++ b/src/gallium/drivers/i915simple/i915_context.h @@ -188,9 +188,9 @@ struct i915_texture { /* Derived from the above: */ - unsigned pitch; - unsigned depth_pitch; /* per-image on i945? */ - unsigned total_height; + unsigned stride; + unsigned depth_stride; /* per-image on i945? */ + unsigned total_nblocksy; unsigned tiled; diff --git a/src/gallium/drivers/i915simple/i915_state_emit.c b/src/gallium/drivers/i915simple/i915_state_emit.c index 19d968fd8b..9bd6f92323 100644 --- a/src/gallium/drivers/i915simple/i915_state_emit.c +++ b/src/gallium/drivers/i915simple/i915_state_emit.c @@ -211,7 +211,7 @@ i915_emit_hardware_state(struct i915_context *i915 ) struct pipe_surface *depth_surface = i915->framebuffer.zsbuf; if (cbuf_surface) { - unsigned cpitch = (cbuf_surface->pitch * cbuf_surface->cpp); + unsigned cpitch = cbuf_surface->stride; unsigned ctile = BUF_3D_USE_FENCE; if (cbuf_surface->texture && ((struct i915_texture*)(cbuf_surface->texture))->tiled) { @@ -232,7 +232,7 @@ i915_emit_hardware_state(struct i915_context *i915 ) /* What happens if no zbuf?? */ if (depth_surface) { - unsigned zpitch = (depth_surface->pitch * depth_surface->cpp); + unsigned zpitch = depth_surface->stride; unsigned ztile = BUF_3D_USE_FENCE; if (depth_surface->texture && ((struct i915_texture*)(depth_surface->texture))->tiled) { diff --git a/src/gallium/drivers/i915simple/i915_state_sampler.c b/src/gallium/drivers/i915simple/i915_state_sampler.c index 379aff3846..7868f21ca6 100644 --- a/src/gallium/drivers/i915simple/i915_state_sampler.c +++ b/src/gallium/drivers/i915simple/i915_state_sampler.c @@ -242,7 +242,7 @@ i915_update_texture(struct i915_context *i915, assert(depth); format = translate_texture_format(pt->format); - pitch = tex->pitch * pt->cpp; + pitch = tex->stride; assert(format); assert(pitch); diff --git a/src/gallium/drivers/i915simple/i915_surface.c b/src/gallium/drivers/i915simple/i915_surface.c index cc55a0910e..0061b22f26 100644 --- a/src/gallium/drivers/i915simple/i915_surface.c +++ b/src/gallium/drivers/i915simple/i915_surface.c @@ -48,7 +48,9 @@ i915_surface_copy(struct pipe_context *pipe, unsigned srcx, unsigned srcy, unsigned width, unsigned height) { assert( dst != src ); - assert( dst->cpp == src->cpp ); + assert( dst->block.size == src->block.size ); + assert( dst->block.width == src->block.height ); + assert( dst->block.height == src->block.height ); if (0) { void *dst_map = pipe->screen->surface_map( pipe->screen, @@ -60,38 +62,30 @@ i915_surface_copy(struct pipe_context *pipe, PIPE_BUFFER_USAGE_CPU_READ ); pipe_copy_rect(dst_map, - dst->cpp, - dst->pitch, + &dst->block, + dst->stride, dstx, dsty, width, height, src_map, - do_flip ? -(int) src->pitch : src->pitch, + do_flip ? -(int) src->stride : src->stride, srcx, do_flip ? height - 1 - srcy : srcy); pipe->screen->surface_unmap(pipe->screen, src); pipe->screen->surface_unmap(pipe->screen, dst); } else { + assert(dst->block.width == 1); + assert(dst->block.height == 1); i915_copy_blit( i915_context(pipe), do_flip, - dst->cpp, - (short) src->pitch, src->buffer, src->offset, - (short) dst->pitch, dst->buffer, dst->offset, + dst->block.size, + (short) src->stride/src->block.size, src->buffer, src->offset, + (short) dst->stride/dst->block.size, dst->buffer, dst->offset, (short) srcx, (short) srcy, (short) dstx, (short) dsty, (short) width, (short) height ); } } -/* Fill a rectangular sub-region. Need better logic about when to - * push buffers into AGP - will currently do so whenever possible. - */ -static void * -get_pointer(struct pipe_surface *dst, void *dst_map, unsigned x, unsigned y) -{ - return (char *)dst_map + (y * dst->pitch + x) * dst->cpp; -} - - static void i915_surface_fill(struct pipe_context *pipe, struct pipe_surface *dst, @@ -99,50 +93,20 @@ i915_surface_fill(struct pipe_context *pipe, unsigned width, unsigned height, unsigned value) { if (0) { - unsigned i, j; void *dst_map = pipe->screen->surface_map( pipe->screen, dst, PIPE_BUFFER_USAGE_CPU_WRITE ); - - switch (dst->cpp) { - case 1: { - ubyte *row = get_pointer(dst, dst_map, dstx, dsty); - for (i = 0; i < height; i++) { - memset(row, value, width); - row += dst->pitch; - } - } - break; - case 2: { - ushort *row = get_pointer(dst, dst_map, dstx, dsty); - for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) - row[j] = (ushort) value; - row += dst->pitch; - } - } - break; - case 4: { - unsigned *row = get_pointer(dst, dst_map, dstx, dsty); - for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) - row[j] = value; - row += dst->pitch; - } - } - break; - default: - assert(0); - break; - } + pipe_fill_rect(dst_map, &dst->block, dst->stride, dstx, dsty, width, height, value); pipe->screen->surface_unmap(pipe->screen, dst); } else { + assert(dst->block.width == 1); + assert(dst->block.height == 1); i915_fill_blit( i915_context(pipe), - dst->cpp, - (short) dst->pitch, + dst->block.size, + (short) dst->stride/dst->block.size, dst->buffer, dst->offset, (short) dstx, (short) dsty, (short) width, (short) height, diff --git a/src/gallium/drivers/i915simple/i915_texture.c b/src/gallium/drivers/i915simple/i915_texture.c index b2e490c7db..2815e61345 100644 --- a/src/gallium/drivers/i915simple/i915_texture.c +++ b/src/gallium/drivers/i915simple/i915_texture.c @@ -109,6 +109,9 @@ i915_miptree_set_level_info(struct i915_texture *tex, pt->width[level] = w; pt->height[level] = h; pt->depth[level] = d; + + pt->nblocksx[level] = pf_get_nblocksx(&pt->block, w); + pt->nblocksy[level] = pf_get_nblocksy(&pt->block, h); tex->nr_images[level] = nr_images; @@ -140,7 +143,7 @@ i915_miptree_set_image_offset(struct i915_texture *tex, assert(img < tex->nr_images[level]); - tex->image_offset[level][img] = (x + y * tex->pitch); + tex->image_offset[level][img] = y * tex->stride + x * tex->base.block.size; /* printf("%s level %d img %d pos %d,%d image_offset %x\n", @@ -162,7 +165,7 @@ i915_displaytarget_layout(struct i915_texture *tex) { struct pipe_texture *pt = &tex->base; - if (pt->last_level > 0 || pt->cpp != 4) + if (pt->last_level > 0 || pt->block.size != 4) return 0; i915_miptree_set_level_info( tex, 0, 1, @@ -172,18 +175,18 @@ i915_displaytarget_layout(struct i915_texture *tex) i915_miptree_set_image_offset( tex, 0, 0, 0, 0 ); if (tex->base.width[0] >= 128) { - tex->pitch = power_of_two(tex->base.width[0] * pt->cpp) / pt->cpp; - tex->total_height = round_up(tex->base.height[0], 8); + tex->stride = power_of_two(tex->base.nblocksx[0] * pt->block.size); + tex->total_nblocksy = round_up(tex->base.nblocksy[0], 8); tex->tiled = 1; } else { - tex->pitch = round_up(tex->base.width[0], 64 / pt->cpp); - tex->total_height = tex->base.height[0]; + tex->stride = round_up(tex->base.nblocksx[0] * pt->block.size, 64); + tex->total_nblocksy = tex->base.nblocksy[0]; } /* printf("%s size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__, - tex->base.width[0], tex->base.height[0], pt->cpp, - tex->pitch, tex->total_height, tex->pitch * tex->total_height * 4); + tex->base.width[0], tex->base.height[0], pt->block.size, + tex->stride, tex->total_nblocksy, tex->stride * tex->total_nblocksy); */ return 1; @@ -193,12 +196,14 @@ static void i945_miptree_layout_2d( struct i915_texture *tex ) { struct pipe_texture *pt = &tex->base; - int align_h = 2, align_w = 4; + const int align_x = 2, align_y = 4; unsigned level; unsigned x = 0; unsigned y = 0; unsigned width = pt->width[0]; unsigned height = pt->height[0]; + unsigned nblocksx = pt->nblocksx[0]; + unsigned nblocksy = pt->nblocksy[0]; #if 0 /* used for tiled display targets */ if (pt->last_level == 0 && pt->cpp == 4) @@ -206,7 +211,7 @@ i945_miptree_layout_2d( struct i915_texture *tex ) return; #endif - tex->pitch = pt->width[0]; + tex->stride = round_up(pt->nblocksx[0] * pt->block.size, 4); /* May need to adjust pitch to accomodate the placement of * the 2nd mipmap level. This occurs when the alignment @@ -214,47 +219,43 @@ i945_miptree_layout_2d( struct i915_texture *tex ) * 2nd mipmap level out past the width of its parent. */ if (pt->last_level > 0) { - unsigned mip1_width = align_int(minify(pt->width[0]), align_w) - + minify(minify(pt->width[0])); + unsigned mip1_nblocksx + = align_int(pf_get_nblocksx(&pt->block, minify(width)), align_x) + + pf_get_nblocksx(&pt->block, minify(minify(width))); - if (mip1_width > pt->width[0]) - tex->pitch = mip1_width; + if (mip1_nblocksx > nblocksx) + tex->stride = mip1_nblocksx * pt->block.size; } - /* Pitch must be a whole number of dwords, even though we - * express it in texels. + /* Pitch must be a whole number of dwords */ - tex->pitch = align_int(tex->pitch * pt->cpp, 64) / pt->cpp; - tex->total_height = 0; + tex->stride = align_int(tex->stride, 64); + tex->total_nblocksy = 0; for (level = 0; level <= pt->last_level; level++) { - unsigned img_height; - i915_miptree_set_level_info(tex, level, 1, width, height, 1); i915_miptree_set_image_offset(tex, level, 0, x, y); - if (pt->compressed) - img_height = MAX2(1, height/4); - else - img_height = align_int(height, align_h); - + nblocksy = align_int(nblocksy, align_y); /* Because the images are packed better, the final offset * might not be the maximal one: */ - tex->total_height = MAX2(tex->total_height, y + img_height); + tex->total_nblocksy = MAX2(tex->total_nblocksy, y + nblocksy); /* Layout_below: step right after second mipmap level. */ if (level == 1) { - x += align_int(width, align_w); + x += align_int(nblocksx, align_x); } else { - y += img_height; + y += nblocksy; } width = minify(width); height = minify(height); + nblocksx = pf_get_nblocksx(&pt->block, width); + nblocksy = pf_get_nblocksy(&pt->block, height); } } @@ -264,15 +265,16 @@ i945_miptree_layout_cube(struct i915_texture *tex) struct pipe_texture *pt = &tex->base; unsigned level; - const unsigned dim = pt->width[0]; + const unsigned nblocks = pt->nblocksx[0]; unsigned face; - unsigned lvlWidth = pt->width[0], lvlHeight = pt->height[0]; + unsigned width = pt->width[0]; + unsigned height = pt->height[0]; /* printf("%s %i, %i\n", __FUNCTION__, pt->width[0], pt->height[0]); */ - assert(lvlWidth == lvlHeight); /* cubemap images are square */ + assert(width == height); /* cubemap images are square */ /* * XXX Should only be used for compressed formats. But lets @@ -282,35 +284,32 @@ i945_miptree_layout_cube(struct i915_texture *tex) * determined either by the old-style packing of cubemap faces, * or the final row of 4x4, 2x2 and 1x1 faces below this. */ - if (dim > 32) - tex->pitch = ((dim * pt->cpp * 2 + 3) & ~3) / pt->cpp; + if (nblocks > 32) + tex->stride = round_up(nblocks * pt->block.size * 2, 4); else - tex->pitch = 14 * 8; + tex->stride = 14 * 8 * pt->block.size; - /* - * XXX The 4 is only needed for compressed formats. See above. - */ - tex->total_height = dim * 4 + 4; + tex->total_nblocksy = nblocks * 4; /* Set all the levels to effectively occupy the whole rectangular region. */ for (level = 0; level <= pt->last_level; level++) { - i915_miptree_set_level_info(tex, level, 6, lvlWidth, lvlHeight, 1); - lvlWidth /= 2; - lvlHeight /= 2; + i915_miptree_set_level_info(tex, level, 6, width, height, 1); + width /= 2; + height /= 2; } for (face = 0; face < 6; face++) { - unsigned x = initial_offsets[face][0] * dim; - unsigned y = initial_offsets[face][1] * dim; - unsigned d = dim; + unsigned x = initial_offsets[face][0] * nblocks; + unsigned y = initial_offsets[face][1] * nblocks; + unsigned d = nblocks; #if 0 /* Fix and enable this code for compressed formats */ - if (dim == 4 && face >= 4) { + if (nblocks == 4 && face >= 4) { y = tex->total_height - 4; x = (face - 4) * 8; } - else if (dim < 4 && (face > 0)) { + else if (nblocks < 4 && (face > 0)) { y = tex->total_height - 4; x = face * 8; } @@ -369,28 +368,28 @@ i915_miptree_layout(struct i915_texture * tex) switch (pt->target) { case PIPE_TEXTURE_CUBE: { - const unsigned dim = pt->width[0]; + const unsigned nblocks = pt->nblocksx[0]; unsigned face; - unsigned lvlWidth = pt->width[0], lvlHeight = pt->height[0]; + unsigned width = pt->width[0], height = pt->height[0]; - assert(lvlWidth == lvlHeight); /* cubemap images are square */ + assert(width == height); /* cubemap images are square */ /* double pitch for cube layouts */ - tex->pitch = ((dim * pt->cpp * 2 + 3) & ~3) / pt->cpp; - tex->total_height = dim * 4; + tex->stride = round_up(nblocks * pt->block.size * 2, 4); + tex->total_nblocksy = nblocks * 4; for (level = 0; level <= pt->last_level; level++) { i915_miptree_set_level_info(tex, level, 6, - lvlWidth, lvlHeight, + width, height, 1); - lvlWidth /= 2; - lvlHeight /= 2; + width /= 2; + height /= 2; } for (face = 0; face < 6; face++) { - unsigned x = initial_offsets[face][0] * dim; - unsigned y = initial_offsets[face][1] * dim; - unsigned d = dim; + unsigned x = initial_offsets[face][0] * nblocks; + unsigned y = initial_offsets[face][1] * nblocks; + unsigned d = nblocks; for (level = 0; level <= pt->last_level; level++) { i915_miptree_set_image_offset(tex, level, face, x, y); @@ -405,25 +404,29 @@ i915_miptree_layout(struct i915_texture * tex) unsigned width = pt->width[0]; unsigned height = pt->height[0]; unsigned depth = pt->depth[0]; - unsigned stack_height = 0; + unsigned nblocksx = pt->nblocksx[0]; + unsigned nblocksy = pt->nblocksy[0]; + unsigned stack_nblocksy = 0; /* Calculate the size of a single slice. */ - tex->pitch = ((pt->width[0] * pt->cpp + 3) & ~3) / pt->cpp; + tex->stride = round_up(pt->nblocksx[0] * pt->block.size, 4); /* XXX: hardware expects/requires 9 levels at minimum. */ for (level = 0; level <= MAX2(8, pt->last_level); level++) { i915_miptree_set_level_info(tex, level, depth, - width, height, depth); + width, height, depth); - stack_height += MAX2(2, height); + stack_nblocksy += MAX2(2, nblocksy); width = minify(width); height = minify(height); depth = minify(depth); + nblocksx = pf_get_nblocksx(&pt->block, width); + nblocksy = pf_get_nblocksy(&pt->block, height); } /* Fixup depth image_offsets: @@ -433,7 +436,7 @@ i915_miptree_layout(struct i915_texture * tex) unsigned i; for (i = 0; i < depth; i++) i915_miptree_set_image_offset(tex, level, i, - 0, i * stack_height); + 0, i * stack_nblocksy); depth = minify(depth); } @@ -443,33 +446,33 @@ i915_miptree_layout(struct i915_texture * tex) * remarkable how wasteful of memory the i915 texture layouts * are. They are largely fixed in the i945. */ - tex->total_height = stack_height * pt->depth[0]; + tex->total_nblocksy = stack_nblocksy * pt->depth[0]; break; } default:{ unsigned width = pt->width[0]; unsigned height = pt->height[0]; - unsigned img_height; + unsigned nblocksx = pt->nblocksx[0]; + unsigned nblocksy = pt->nblocksy[0]; - tex->pitch = ((pt->width[0] * pt->cpp + 3) & ~3) / pt->cpp; - tex->total_height = 0; + tex->stride = round_up(pt->nblocksx[0] * pt->block.size, 4); + tex->total_nblocksy = 0; for (level = 0; level <= pt->last_level; level++) { i915_miptree_set_level_info(tex, level, 1, - width, height, 1); + width, height, 1); i915_miptree_set_image_offset(tex, level, 0, - 0, tex->total_height); + 0, tex->total_nblocksy); - if (pt->compressed) - img_height = MAX2(1, height / 4); - else - img_height = (MAX2(2, height) + 1) & ~1; + nblocksy = round_up(MAX2(2, nblocksy), 2); - tex->total_height += img_height; + tex->total_nblocksy += nblocksy; width = minify(width); height = minify(height); + nblocksx = pf_get_nblocksx(&pt->block, width); + nblocksy = pf_get_nblocksy(&pt->block, height); } break; } @@ -477,7 +480,7 @@ i915_miptree_layout(struct i915_texture * tex) /* DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__, tex->pitch, - tex->total_height, pt->cpp, tex->pitch * tex->total_height * pt->cpp); + tex->total_nblocksy, pt->block.size, tex->stride * tex->total_nblocksy); */ return TRUE; @@ -498,14 +501,16 @@ i945_miptree_layout(struct i915_texture * tex) unsigned width = pt->width[0]; unsigned height = pt->height[0]; unsigned depth = pt->depth[0]; + unsigned nblocksx = pt->nblocksx[0]; + unsigned nblocksy = pt->nblocksy[0]; unsigned pack_x_pitch, pack_x_nr; unsigned pack_y_pitch; - tex->pitch = ((pt->width[0] * pt->cpp + 3) & ~3) / pt->cpp; - tex->total_height = 0; + tex->stride = round_up(pt->nblocksx[0] * pt->block.size, 4); + tex->total_nblocksy = 0; - pack_y_pitch = MAX2(pt->height[0], 2); - pack_x_pitch = tex->pitch; + pack_y_pitch = MAX2(pt->nblocksy[0], 2); + pack_x_pitch = tex->stride / pt->block.size; pack_x_nr = 1; for (level = 0; level <= pt->last_level; level++) { @@ -515,11 +520,11 @@ i945_miptree_layout(struct i915_texture * tex) unsigned q, j; i915_miptree_set_level_info(tex, level, nr_images, - width, height, depth); + width, height, depth); for (q = 0; q < nr_images;) { for (j = 0; j < pack_x_nr && q < nr_images; j++, q++) { - i915_miptree_set_image_offset(tex, level, q, x, y + tex->total_height); + i915_miptree_set_image_offset(tex, level, q, x, y + tex->total_nblocksy); x += pack_x_pitch; } @@ -528,12 +533,12 @@ i945_miptree_layout(struct i915_texture * tex) } - tex->total_height += y; + tex->total_nblocksy += y; if (pack_x_pitch > 4) { pack_x_pitch >>= 1; pack_x_nr <<= 1; - assert(pack_x_pitch * pack_x_nr <= tex->pitch); + assert(pack_x_pitch * pack_x_nr * pt->block.size <= tex->stride); } if (pack_y_pitch > 2) { @@ -543,6 +548,8 @@ i945_miptree_layout(struct i915_texture * tex) width = minify(width); height = minify(height); depth = minify(depth); + nblocksx = pf_get_nblocksx(&pt->block, width); + nblocksy = pf_get_nblocksy(&pt->block, height); } break; } @@ -560,7 +567,7 @@ i945_miptree_layout(struct i915_texture * tex) /* DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__, tex->pitch, - tex->total_height, pt->cpp, tex->pitch * tex->total_height * pt->cpp); + tex->total_nblocksy, pt->block.size, tex->stride * tex->total_nblocksy); */ return TRUE; @@ -582,6 +589,9 @@ i915_texture_create(struct pipe_screen *screen, tex->base.refcount = 1; tex->base.screen = screen; + tex->base.nblocksx[0] = pf_get_nblocksx(&tex->base.block, tex->base.width[0]); + tex->base.nblocksy[0] = pf_get_nblocksy(&tex->base.block, tex->base.height[0]); + if (i915screen->is_i945) { if (!i945_miptree_layout(tex)) goto fail; @@ -592,8 +602,8 @@ i915_texture_create(struct pipe_screen *screen, tex->buffer = ws->buffer_create(ws, 64, PIPE_BUFFER_USAGE_PIXEL, - tex->pitch * tex->base.cpp * - tex->total_height); + tex->stride * + tex->total_nblocksy); if (!tex->buffer) goto fail; @@ -648,13 +658,13 @@ i915_get_tex_surface(struct pipe_screen *screen, unsigned offset; /* in bytes */ if (pt->target == PIPE_TEXTURE_CUBE) { - offset = tex->image_offset[level][face] * pt->cpp; + offset = tex->image_offset[level][face]; } else if (pt->target == PIPE_TEXTURE_3D) { - offset = tex->image_offset[level][zslice] * pt->cpp; + offset = tex->image_offset[level][zslice]; } else { - offset = tex->image_offset[level][0] * pt->cpp; + offset = tex->image_offset[level][0]; assert(face == 0); assert(zslice == 0); } @@ -666,10 +676,12 @@ i915_get_tex_surface(struct pipe_screen *screen, pipe_texture_reference(&ps->texture, pt); pipe_buffer_reference(ws, &ps->buffer, tex->buffer); ps->format = pt->format; - ps->cpp = pt->cpp; ps->width = pt->width[level]; ps->height = pt->height[level]; - ps->pitch = tex->pitch; + ps->block = pt->block; + ps->nblocksx = pt->nblocksx[level]; + ps->nblocksy = pt->nblocksy[level]; + ps->stride = tex->stride; ps->offset = offset; ps->usage = flags; ps->status = PIPE_SURFACE_STATUS_DEFINED; @@ -680,7 +692,7 @@ i915_get_tex_surface(struct pipe_screen *screen, static struct pipe_texture * i915_texture_blanket(struct pipe_screen * screen, const struct pipe_texture *base, - const unsigned *pitch, + const unsigned *stride, struct pipe_buffer *buffer) { struct i915_texture *tex; @@ -699,7 +711,7 @@ i915_texture_blanket(struct pipe_screen * screen, tex->base = *base; - tex->pitch = pitch[0]; + tex->stride = stride[0]; i915_miptree_set_level_info(tex, 0, 1, base->width[0], base->height[0], 1); i915_miptree_set_image_offset(tex, 0, 0, 0, 0); diff --git a/src/gallium/drivers/i965simple/brw_context.h b/src/gallium/drivers/i965simple/brw_context.h index 8ac6b4e689..2cae7665f7 100644 --- a/src/gallium/drivers/i965simple/brw_context.h +++ b/src/gallium/drivers/i965simple/brw_context.h @@ -231,9 +231,9 @@ struct brw_texture { /* Derived from the above: */ - unsigned pitch; + unsigned stride; unsigned depth_pitch; /* per-image on i945? */ - unsigned total_height; + unsigned total_nblocksy; unsigned nr_images[PIPE_MAX_TEXTURE_LEVELS]; diff --git a/src/gallium/drivers/i965simple/brw_misc_state.c b/src/gallium/drivers/i965simple/brw_misc_state.c index 925049ecc1..be812c5da9 100644 --- a/src/gallium/drivers/i965simple/brw_misc_state.c +++ b/src/gallium/drivers/i965simple/brw_misc_state.c @@ -224,7 +224,9 @@ static void upload_depthbuffer(struct brw_context *brw) } else { unsigned int format; - switch (depth_surface->cpp) { + assert(depth_surface->block.width == 1); + assert(depth_surface->block.height == 1); + switch (depth_surface->block.size) { case 2: format = BRW_DEPTHFORMAT_D16_UNORM; break; @@ -239,7 +241,7 @@ static void upload_depthbuffer(struct brw_context *brw) return; } - OUT_BATCH(((depth_surface->pitch * depth_surface->cpp) - 1) | + OUT_BATCH((depth_surface->stride - 1) | (format << 18) | (BRW_TILEWALK_YMAJOR << 26) | // (depth_surface->region->tiled << 27) | @@ -247,7 +249,7 @@ static void upload_depthbuffer(struct brw_context *brw) OUT_RELOC(depth_surface->buffer, PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE, 0); OUT_BATCH((BRW_SURFACE_MIPMAPLAYOUT_BELOW << 1) | - ((depth_surface->pitch - 1) << 6) | + ((depth_surface->stride/depth_surface->block.size - 1) << 6) | ((depth_surface->height - 1) << 19)); OUT_BATCH(0); } diff --git a/src/gallium/drivers/i965simple/brw_surface.c b/src/gallium/drivers/i965simple/brw_surface.c index 3d98a2bf19..0be3dfc743 100644 --- a/src/gallium/drivers/i965simple/brw_surface.c +++ b/src/gallium/drivers/i965simple/brw_surface.c @@ -47,8 +47,10 @@ brw_surface_copy(struct pipe_context *pipe, struct pipe_surface *src, unsigned srcx, unsigned srcy, unsigned width, unsigned height) { - assert(dst != src); - assert(dst->cpp == src->cpp); + assert( dst != src ); + assert( dst->block.size == src->block.size ); + assert( dst->block.width == src->block.height ); + assert( dst->block.height == src->block.height ); if (0) { void *dst_map = pipe->screen->surface_map( pipe->screen, @@ -60,37 +62,30 @@ brw_surface_copy(struct pipe_context *pipe, PIPE_BUFFER_USAGE_CPU_READ ); pipe_copy_rect(dst_map, - dst->cpp, - dst->pitch, + &dst->block, + dst->stride, dstx, dsty, width, height, src_map, - do_flip ? -(int) src->pitch : src->pitch, + do_flip ? -(int) src->stride : src->stride, srcx, do_flip ? height - 1 - srcy : srcy); pipe->screen->surface_unmap(pipe->screen, src); pipe->screen->surface_unmap(pipe->screen, dst); } else { + assert(dst->block.width == 1); + assert(dst->block.height == 1); brw_copy_blit(brw_context(pipe), do_flip, - dst->cpp, - (short) src->pitch, src->buffer, src->offset, FALSE, - (short) dst->pitch, dst->buffer, dst->offset, FALSE, + dst->block.size, + (short) src->stride/src->block.size, src->buffer, src->offset, FALSE, + (short) dst->stride/dst->block.size, dst->buffer, dst->offset, FALSE, (short) srcx, (short) srcy, (short) dstx, (short) dsty, (short) width, (short) height, PIPE_LOGICOP_COPY); } } -/* Fill a rectangular sub-region. Need better logic about when to - * push buffers into AGP - will currently do so whenever possible. - */ -static void * -get_pointer(struct pipe_surface *dst, void *dst_map, unsigned x, unsigned y) -{ - return (char *)dst_map + (y * dst->pitch + x) * dst->cpp; -} - static void brw_surface_fill(struct pipe_context *pipe, @@ -99,50 +94,20 @@ brw_surface_fill(struct pipe_context *pipe, unsigned width, unsigned height, unsigned value) { if (0) { - unsigned i, j; void *dst_map = pipe->screen->surface_map( pipe->screen, dst, PIPE_BUFFER_USAGE_CPU_WRITE ); - - switch (dst->cpp) { - case 1: { - ubyte *row = get_pointer(dst, dst_map, dstx, dsty); - for (i = 0; i < height; i++) { - memset(row, value, width); - row += dst->pitch; - } - } - break; - case 2: { - ushort *row = get_pointer(dst, dst_map, dstx, dsty); - for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) - row[j] = (ushort) value; - row += dst->pitch; - } - } - break; - case 4: { - unsigned *row = get_pointer(dst, dst_map, dstx, dsty); - for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) - row[j] = value; - row += dst->pitch; - } - } - break; - default: - assert(0); - break; - } + pipe_fill_rect(dst_map, &dst->block, dst->stride, dstx, dsty, width, height, value); pipe->screen->surface_unmap(pipe->screen, dst); } else { + assert(dst->block.width == 1); + assert(dst->block.height == 1); brw_fill_blit(brw_context(pipe), - dst->cpp, - (short) dst->pitch, + dst->block.size, + (short) dst->stride/dst->block.size, dst->buffer, dst->offset, FALSE, (short) dstx, (short) dsty, (short) width, (short) height, diff --git a/src/gallium/drivers/i965simple/brw_tex_layout.c b/src/gallium/drivers/i965simple/brw_tex_layout.c index 78ae0b1223..8c7725605b 100644 --- a/src/gallium/drivers/i965simple/brw_tex_layout.c +++ b/src/gallium/drivers/i965simple/brw_tex_layout.c @@ -81,7 +81,7 @@ static void intel_miptree_set_image_offset(struct brw_texture *tex, assert(x == 0 && y == 0); assert(img < tex->nr_images[level]); - tex->image_offset[level][img] = (x + y * tex->pitch) * pt->cpp; + tex->image_offset[level][img] = y * tex->stride + x * pt->block.size; } static void intel_miptree_set_level_info(struct brw_texture *tex, @@ -97,8 +97,11 @@ static void intel_miptree_set_level_info(struct brw_texture *tex, pt->width[level] = w; pt->height[level] = h; pt->depth[level] = d; + + pt->nblocksx[level] = pf_get_nblocksx(&pt->block, w); + pt->nblocksy[level] = pf_get_nblocksy(&pt->block, h); - tex->level_offset[level] = (x + y * tex->pitch) * pt->cpp; + tex->level_offset[level] = y * tex->stride + x * tex->base.block.size; tex->nr_images[level] = nr_images; /* @@ -123,77 +126,60 @@ static void intel_miptree_set_level_info(struct brw_texture *tex, static void i945_miptree_layout_2d(struct brw_texture *tex) { struct pipe_texture *pt = &tex->base; - unsigned align_h = 2, align_w = 4; + const int align_x = 2, align_y = 4; unsigned level; unsigned x = 0; unsigned y = 0; unsigned width = pt->width[0]; unsigned height = pt->height[0]; + unsigned nblocksx = pt->nblocksx[0]; + unsigned nblocksy = pt->nblocksy[0]; - tex->pitch = pt->width[0]; - -#if 0 - if (pt->compressed) { - align_w = intel_compressed_alignment(pt->internal_format); - tex->pitch = ALIGN(pt->width[0], align_w); - } -#endif + tex->stride = align(pt->nblocksx[0] * pt->block.size, 4); /* May need to adjust pitch to accomodate the placement of - * the 2nd mipmap. This occurs when the alignment + * the 2nd mipmap level. This occurs when the alignment * constraints of mipmap placement push the right edge of the - * 2nd mipmap out past the width of its parent. + * 2nd mipmap level out past the width of its parent. */ if (pt->last_level > 0) { - unsigned mip1_width; - - if (pt->compressed) { - mip1_width = align(minify(pt->width[0]), align_w) - + align(minify(minify(pt->width[0])), align_w); - } else { - mip1_width = align(minify(pt->width[0]), align_w) - + minify(minify(pt->width[0])); - } + unsigned mip1_nblocksx + = align_int(pf_get_nblocksx(&pt->block, minify(width)), align_x) + + pf_get_nblocksx(&pt->block, minify(minify(width))); - if (mip1_width > tex->pitch) { - tex->pitch = mip1_width; - } + if (mip1_nblocksx > nblocksx) + tex->stride = mip1_nblocksx * pt->block.size; } - /* Pitch must be a whole number of dwords, even though we - * express it in texels. + /* Pitch must be a whole number of dwords */ - tex->pitch = align(tex->pitch * pt->cpp, 4) / pt->cpp; - tex->total_height = 0; + tex->stride = align_int(tex->stride, 64); + tex->total_nblocksy = 0; for (level = 0; level <= pt->last_level; level++) { - unsigned img_height; - intel_miptree_set_level_info(tex, level, 1, x, y, width, height, 1); - if (pt->compressed) - img_height = MAX2(1, height/4); - else - img_height = align(height, align_h); - + nblocksy = align_int(nblocksy, align_y); /* Because the images are packed better, the final offset * might not be the maximal one: */ - tex->total_height = MAX2(tex->total_height, y + img_height); + tex->total_nblocksy = MAX2(tex->total_nblocksy, y + nblocksy); - /* Layout_below: step right after second mipmap. + /* Layout_below: step right after second mipmap level. */ if (level == 1) { - x += align(width, align_w); + x += align_int(nblocksx, align_x); } else { - y += img_height; + y += nblocksy; } width = minify(width); height = minify(height); + nblocksx = pf_get_nblocksx(&pt->block, width); + nblocksy = pf_get_nblocksy(&pt->block, height); } } @@ -210,26 +196,20 @@ static boolean brw_miptree_layout(struct brw_texture *tex) unsigned width = pt->width[0]; unsigned height = pt->height[0]; unsigned depth = pt->depth[0]; + unsigned nblocksx = pt->nblocksx[0]; + unsigned nblocksy = pt->nblocksy[0]; unsigned pack_x_pitch, pack_x_nr; unsigned pack_y_pitch; unsigned level; unsigned align_h = 2; unsigned align_w = 4; - tex->total_height = 0; -#if 0 - if (pt->compressed) { - align_w = intel_compressed_alignment(pt->internal_format); - pt->pitch = align(width, align_w); - pack_y_pitch = (height + 3) / 4; - } else -#endif - { - tex->pitch = align(pt->width[0] * pt->cpp, 4) / pt->cpp; - pack_y_pitch = align(pt->height[0], align_h); - } + tex->total_nblocksy = 0; + + tex->stride = align(pt->nblocksx[0], 4); + pack_y_pitch = align(pt->nblocksy[0], align_h); - pack_x_pitch = tex->pitch; + pack_x_pitch = tex->stride / pt->block.size; pack_x_nr = 1; for (level = 0; level <= pt->last_level; level++) { @@ -239,7 +219,7 @@ static boolean brw_miptree_layout(struct brw_texture *tex) uint q, j; intel_miptree_set_level_info(tex, level, nr_images, - 0, tex->total_height, + 0, tex->total_nblocksy, width, height, depth); for (q = 0; q < nr_images;) { @@ -253,10 +233,12 @@ static boolean brw_miptree_layout(struct brw_texture *tex) } - tex->total_height += y; + tex->total_nblocksy += y; width = minify(width); height = minify(height); depth = minify(depth); + nblocksx = pf_get_nblocksx(&pt->block, width); + nblocksy = pf_get_nblocksy(&pt->block, height); if (pt->compressed) { pack_y_pitch = (height + 3) / 4; @@ -269,7 +251,7 @@ static boolean brw_miptree_layout(struct brw_texture *tex) if (pack_x_pitch > 4) { pack_x_pitch >>= 1; pack_x_nr <<= 1; - assert(pack_x_pitch * pack_x_nr <= tex->pitch); + assert(pack_x_pitch * pack_x_nr * pt->block.size <= tex->stride); } if (pack_y_pitch > 2) { @@ -289,9 +271,9 @@ static boolean brw_miptree_layout(struct brw_texture *tex) #if 0 PRINT("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__, pt->pitch, - pt->total_height, - pt->cpp, - pt->pitch * pt->total_height * pt->cpp ); + pt->total_nblocksy, + pt->block.size, + pt->stride * pt->total_nblocksy ); #endif return TRUE; @@ -309,11 +291,14 @@ brw_texture_create_screen(struct pipe_screen *screen, tex->base = *templat; tex->base.refcount = 1; + tex->base.nblocksx[0] = pf_get_nblocksx(&tex->base.block, tex->base.width[0]); + tex->base.nblocksy[0] = pf_get_nblocksy(&tex->base.block, tex->base.height[0]); + if (brw_miptree_layout(tex)) tex->buffer = ws->buffer_create(ws, 64, PIPE_BUFFER_USAGE_PIXEL, - tex->pitch * tex->base.cpp * - tex->total_height); + tex->stride * + tex->total_nblocksy); if (!tex->buffer) { FREE(tex); @@ -370,10 +355,10 @@ brw_get_tex_surface_screen(struct pipe_screen *screen, offset = tex->level_offset[level]; if (pt->target == PIPE_TEXTURE_CUBE) { - offset += tex->image_offset[level][face] * pt->cpp; + offset += tex->image_offset[level][face]; } else if (pt->target == PIPE_TEXTURE_3D) { - offset += tex->image_offset[level][zslice] * pt->cpp; + offset += tex->image_offset[level][zslice]; } else { assert(face == 0); @@ -386,10 +371,12 @@ brw_get_tex_surface_screen(struct pipe_screen *screen, assert(ps->refcount); pipe_buffer_reference(ws, &ps->buffer, tex->buffer); ps->format = pt->format; - ps->cpp = pt->cpp; ps->width = pt->width[level]; ps->height = pt->height[level]; - ps->pitch = tex->pitch; + ps->block = pt->block; + ps->nblocksx = pt->nblocksx[level]; + ps->nblocksy = pt->nblocksy[level]; + ps->stride = tex->stride; ps->offset = offset; } return ps; diff --git a/src/gallium/drivers/i965simple/brw_wm_surface_state.c b/src/gallium/drivers/i965simple/brw_wm_surface_state.c index 69e56dc8bd..1a326f9918 100644 --- a/src/gallium/drivers/i965simple/brw_wm_surface_state.c +++ b/src/gallium/drivers/i965simple/brw_wm_surface_state.c @@ -160,7 +160,7 @@ void brw_update_texture_surface( struct brw_context *brw, surf.ss3.tile_walk = BRW_TILEWALK_XMAJOR; surf.ss3.tiled_surface = 0; /* always zero */ - surf.ss3.pitch = tObj->pitch - 1; + surf.ss3.pitch = tObj->stride - 1; surf.ss3.depth = tObj->base.depth[0] - 1; surf.ss4.min_lod = 0; @@ -197,7 +197,7 @@ static void upload_wm_surfaces(struct brw_context *brw ) memset(&surf, 0, sizeof(surf)); if (pipe_surface != NULL) { - if (pipe_surface->cpp == 4) + if (pipe_surface->block.size == 4) surf.ss0.surface_format = BRW_SURFACEFORMAT_B8G8R8A8_UNORM; else surf.ss0.surface_format = BRW_SURFACEFORMAT_B5G6R5_UNORM; @@ -210,7 +210,7 @@ static void upload_wm_surfaces(struct brw_context *brw ) surf.ss2.height = pipe_surface->height - 1; surf.ss3.tile_walk = BRW_TILEWALK_XMAJOR; surf.ss3.tiled_surface = 0; - surf.ss3.pitch = (pipe_surface->pitch * pipe_surface->cpp) - 1; + surf.ss3.pitch = pipe_surface->stride - 1; } else { surf.ss0.surface_format = BRW_SURFACEFORMAT_B8G8R8A8_UNORM; surf.ss0.surface_type = BRW_SURFACE_NULL; diff --git a/src/gallium/drivers/softpipe/sp_surface.c b/src/gallium/drivers/softpipe/sp_surface.c index 9fd48aeccc..7dc15c38d1 100644 --- a/src/gallium/drivers/softpipe/sp_surface.c +++ b/src/gallium/drivers/softpipe/sp_surface.c @@ -58,18 +58,20 @@ sp_surface_copy(struct pipe_context *pipe, src, PIPE_BUFFER_USAGE_CPU_READ ); - assert(dst->cpp == src->cpp); + assert(dst->block.size == src->block.size); + assert(dst->block.width == src->block.width); + assert(dst->block.height == src->block.height); assert(src_map); assert(dst_map); /* If do_flip, invert src_y position and pass negative src stride */ pipe_copy_rect(dst_map, - dst->cpp, - dst->pitch, + &dst->block, + dst->stride, dstx, dsty, width, height, src_map, - do_flip ? -(int) src->pitch : src->pitch, + do_flip ? -(int) src->stride : src->stride, srcx, do_flip ? src->height - 1 - srcy : srcy); pipe->screen->surface_unmap(pipe->screen, src); @@ -80,7 +82,7 @@ sp_surface_copy(struct pipe_context *pipe, static void * get_pointer(struct pipe_surface *dst, void *dst_map, unsigned x, unsigned y) { - return (char *)dst_map + (y * dst->pitch + x) * dst->cpp; + return (char *)dst_map + y / dst->block.height * dst->stride + x / dst->block.width * dst->block.size; } @@ -102,39 +104,14 @@ sp_surface_fill(struct pipe_context *pipe, dst, PIPE_BUFFER_USAGE_CPU_WRITE ); - assert(dst->pitch > 0); - assert(width <= dst->pitch); + assert(dst->stride > 0); - switch (dst->cpp) { + switch (dst->block.size) { case 1: - { - ubyte *row = get_pointer(dst, dst_map, dstx, dsty); - for (i = 0; i < height; i++) { - memset(row, value, width); - row += dst->pitch; - } - } - break; case 2: - { - ushort *row = get_pointer(dst, dst_map, dstx, dsty); - for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) - row[j] = (ushort) value; - row += dst->pitch; - } - } - break; case 4: - { - unsigned *row = get_pointer(dst, dst_map, dstx, dsty); - for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) - row[j] = value; - row += dst->pitch; - } - } + pipe_fill_rect(dst_map, &dst->block, dst->stride, dstx, dsty, width, height, value); break; case 8: { @@ -155,7 +132,7 @@ sp_surface_fill(struct pipe_context *pipe, row[j*4+2] = val2; row[j*4+3] = val3; } - row += dst->pitch * 4; + row += dst->stride/2; } } break; diff --git a/src/gallium/drivers/softpipe/sp_texture.c b/src/gallium/drivers/softpipe/sp_texture.c index 2ef17a220b..4db045cdc3 100644 --- a/src/gallium/drivers/softpipe/sp_texture.c +++ b/src/gallium/drivers/softpipe/sp_texture.c @@ -71,13 +71,15 @@ softpipe_texture_layout(struct pipe_screen *screen, pt->width[level] = width; pt->height[level] = height; pt->depth[level] = depth; - spt->pitch[level] = width; + pt->nblocksx[level] = pf_get_nblocksx(&pt->block, width); + pt->nblocksy[level] = pf_get_nblocksy(&pt->block, height); + spt->stride[level] = pt->nblocksx[level]*pt->block.size; spt->level_offset[level] = buffer_size; - buffer_size += (((pt->compressed) ? MAX2(1, height/4) : height) * + buffer_size += (pt->nblocksy[level] * ((pt->target == PIPE_TEXTURE_CUBE) ? 6 : depth) * - width * pt->cpp); + spt->stride[level]); width = minify(width); height = minify(height); @@ -121,7 +123,7 @@ softpipe_displaytarget_layout(struct pipe_screen *screen, /* Now extract the goodies: */ spt->buffer = surf.buffer; - spt->pitch[0] = surf.pitch; + spt->stride[0] = surf.stride; return spt->buffer != NULL; } @@ -195,10 +197,12 @@ softpipe_get_tex_surface(struct pipe_screen *screen, assert(ps->winsys); pipe_buffer_reference(ws, &ps->buffer, spt->buffer); ps->format = pt->format; - ps->cpp = pt->cpp; + ps->block = pt->block; ps->width = pt->width[level]; ps->height = pt->height[level]; - ps->pitch = spt->pitch[level]; + ps->nblocksx = pt->nblocksx[level]; + ps->nblocksy = pt->nblocksy[level]; + ps->stride = spt->stride[level]; ps->offset = spt->level_offset[level]; ps->usage = usage; @@ -228,8 +232,8 @@ softpipe_get_tex_surface(struct pipe_screen *screen, if (pt->target == PIPE_TEXTURE_CUBE || pt->target == PIPE_TEXTURE_3D) { ps->offset += ((pt->target == PIPE_TEXTURE_CUBE) ? face : zslice) * - (pt->compressed ? ps->height/4 : ps->height) * - ps->width * ps->cpp; + ps->nblocksy * + ps->stride; } else { assert(face == 0); diff --git a/src/gallium/drivers/softpipe/sp_texture.h b/src/gallium/drivers/softpipe/sp_texture.h index 0e1017632c..bf437a7c61 100644 --- a/src/gallium/drivers/softpipe/sp_texture.h +++ b/src/gallium/drivers/softpipe/sp_texture.h @@ -42,7 +42,7 @@ struct softpipe_texture struct pipe_texture base; unsigned long level_offset[PIPE_MAX_TEXTURE_LEVELS]; - unsigned long pitch[PIPE_MAX_TEXTURE_LEVELS]; + unsigned long stride[PIPE_MAX_TEXTURE_LEVELS]; /* The data is held here: */ diff --git a/src/gallium/include/pipe/p_format.h b/src/gallium/include/pipe/p_format.h index d973fb357b..a2c6155d01 100644 --- a/src/gallium/include/pipe/p_format.h +++ b/src/gallium/include/pipe/p_format.h @@ -501,6 +501,47 @@ pf_get_block(enum pipe_format format, struct pipe_format_block *block) } } +static INLINE unsigned +pf_get_nblocksx(const struct pipe_format_block *block, unsigned x) +{ + return (x + block->width - 1)/block->width; +} + +static INLINE unsigned +pf_get_nblocksy(const struct pipe_format_block *block, unsigned y) +{ + return (y + block->height - 1)/block->height; +} + +static INLINE unsigned +pf_get_nblocks(const struct pipe_format_block *block, unsigned width, unsigned height) +{ + return pf_get_nblocksx(block, width)*pf_get_nblocksy(block, height); +} + +static INLINE void +pipe_rect_to_blocks(const struct pipe_format_block *block, + unsigned *width, unsigned *height, + unsigned *src_x, unsigned *src_y, + unsigned *dst_x, unsigned *dst_y) +{ + assert(block->size > 0); + assert(block->width > 0); + assert(block->height > 0); + if(width) + *width = pf_get_nblocksx(block, *width); + if(height) + *height = pf_get_nblocksy(block, *height); + if(src_x) + *src_x /= block->width; + if(src_y) + *src_y /= block->height; + if(dst_x) + *dst_x /= block->width; + if(dst_y) + *dst_y /= block->height; +} + #ifdef __cplusplus } #endif diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h index e7ee8c97ed..2992e2f3b3 100644 --- a/src/gallium/include/pipe/p_state.h +++ b/src/gallium/include/pipe/p_state.h @@ -267,10 +267,12 @@ struct pipe_surface enum pipe_format format; /**< PIPE_FORMAT_x */ unsigned status; /**< PIPE_SURFACE_STATUS_x */ unsigned clear_value; /**< XXX may be temporary */ - unsigned cpp; /**< bytes per pixel */ unsigned width; unsigned height; - unsigned pitch; /**< in pixels */ + struct pipe_format_block block; + unsigned nblocksx; + unsigned nblocksy; + unsigned stride; /**< in bytes */ unsigned layout; /**< PIPE_SURFACE_LAYOUT_x */ unsigned offset; /**< offset from start of buffer, in bytes */ unsigned refcount; @@ -303,7 +305,10 @@ struct pipe_texture unsigned height[PIPE_MAX_TEXTURE_LEVELS]; unsigned depth[PIPE_MAX_TEXTURE_LEVELS]; - unsigned cpp:8; + struct pipe_format_block block; + unsigned nblocksx[PIPE_MAX_TEXTURE_LEVELS]; + unsigned nblocksy[PIPE_MAX_TEXTURE_LEVELS]; + unsigned last_level:8; /**< Index of last mipmap level present/defined */ unsigned compressed:1; diff --git a/src/gallium/include/pipe/p_util.h b/src/gallium/include/pipe/p_util.h index cf2447822a..7dcdd28287 100644 --- a/src/gallium/include/pipe/p_util.h +++ b/src/gallium/include/pipe/p_util.h @@ -31,6 +31,7 @@ #include "p_config.h" #include "p_compiler.h" #include "p_debug.h" +#include "p_format.h" #include "p_pointer.h" #include #include @@ -401,11 +402,15 @@ static INLINE int align(int value, int alignment) /* util/p_util.c */ -extern void pipe_copy_rect(ubyte * dst, unsigned cpp, unsigned dst_pitch, - unsigned dst_x, unsigned dst_y, unsigned width, - unsigned height, const ubyte * src, - int src_pitch, unsigned src_x, int src_y); - +extern void pipe_copy_rect(ubyte * dst, const struct pipe_format_block *block, + unsigned dst_stride, unsigned dst_x, unsigned dst_y, + unsigned width, unsigned height, const ubyte * src, + int src_stride, unsigned src_x, int src_y); + +extern void +pipe_fill_rect(ubyte * dst, const struct pipe_format_block *block, + unsigned dst_stride, unsigned dst_x, unsigned dst_y, + unsigned width, unsigned height, uint32_t value); #if defined(_MSC_VER) diff --git a/src/gallium/winsys/xlib/brw_aub.c b/src/gallium/winsys/xlib/brw_aub.c index 10eedd8402..6e814ce5d1 100644 --- a/src/gallium/winsys/xlib/brw_aub.c +++ b/src/gallium/winsys/xlib/brw_aub.c @@ -322,7 +322,10 @@ void brw_aub_dump_bmp( struct brw_aubfile *aubfile, struct aub_dump_bmp db; unsigned format; - if (surface->cpp == 4) + assert(surface->block.width == 1); + assert(surface->block.height == 1); + + if (surface->block.size == 4) format = 0x7; else format = 0x3; @@ -331,8 +334,8 @@ void brw_aub_dump_bmp( struct brw_aubfile *aubfile, db.xmin = 0; db.ymin = 0; db.format = format; - db.bpp = surface->cpp * 8; - db.pitch = surface->pitch; + db.bpp = surface->block.size * 8; + db.pitch = surface->stride/surface->block.size; db.xsize = surface->width; db.ysize = surface->height; db.addr = gtt_offset; diff --git a/src/gallium/winsys/xlib/xm_winsys.c b/src/gallium/winsys/xlib/xm_winsys.c index b14758f333..9225ee510d 100644 --- a/src/gallium/winsys/xlib/xm_winsys.c +++ b/src/gallium/winsys/xlib/xm_winsys.c @@ -364,9 +364,10 @@ xmesa_display_surface(XMesaBuffer b, const struct pipe_surface *surf) return; } - if (XSHM_ENABLED(xm_buf) && (xm_buf->tempImage == NULL)) { - alloc_shm_ximage(xm_buf, b, surf->pitch, surf->height); + assert(surf->block.width == 1); + assert(surf->block.height == 1); + alloc_shm_ximage(xm_buf, b, surf->stride/surf->block.size, surf->height); } ximage = (XSHM_ENABLED(xm_buf)) ? xm_buf->tempImage : b->tempImage; @@ -386,7 +387,7 @@ xmesa_display_surface(XMesaBuffer b, const struct pipe_surface *surf) /* update XImage's fields */ ximage->width = surf->width; ximage->height = surf->height; - ximage->bytes_per_line = surf->pitch * surf->cpp; + ximage->bytes_per_line = surf->stride; XPutImage(b->xm_visual->display, b->drawable, b->gc, ximage, 0, 0, 0, 0, surf->width, surf->height); @@ -497,18 +498,21 @@ xm_surface_alloc_storage(struct pipe_winsys *winsys, surf->width = width; surf->height = height; surf->format = format; - surf->cpp = pf_get_size(format); - surf->pitch = round_up(width, alignment / surf->cpp); + pf_get_block(format, &surf->block); + surf->nblocksx = pf_get_nblocksx(&surf->block, width); + surf->nblocksy = pf_get_nblocksy(&surf->block, height); + surf->stride = round_up(surf->nblocksx * surf->block.size, alignment); surf->usage = flags; -#ifdef GALLIUM_CELL /* XXX a bit of a hack */ - height = round_up(height, TILE_SIZE); -#endif - assert(!surf->buffer); surf->buffer = winsys->buffer_create(winsys, alignment, PIPE_BUFFER_USAGE_PIXEL, - surf->pitch * surf->cpp * height); +#ifdef GALLIUM_CELL /* XXX a bit of a hack */ + surf->stride * round_up(surf->nblocksy, TILE_SIZE)); +#else + surf->stride * surf->nblocksy); +#endif + if(!surf->buffer) return -1; diff --git a/src/gallium/winsys/xlib/xm_winsys_aub.c b/src/gallium/winsys/xlib/xm_winsys_aub.c index 77376099f0..7fc9debdd5 100644 --- a/src/gallium/winsys/xlib/xm_winsys_aub.c +++ b/src/gallium/winsys/xlib/xm_winsys_aub.c @@ -279,22 +279,25 @@ aub_i915_surface_alloc_storage(struct pipe_winsys *winsys, unsigned flags, unsigned tex_usage) { - const unsigned alignment = 64; - - surf->width = width; - surf->height = height; - surf->format = format; - surf->cpp = pf_get_size(format); - surf->pitch = round_up(width, alignment / surf->cpp); - - assert(!surf->buffer); - surf->buffer = winsys->buffer_create(winsys, alignment, - PIPE_BUFFER_USAGE_PIXEL, - surf->pitch * surf->cpp * height); + const unsigned alignment = 64; + + surf->width = width; + surf->height = height; + surf->format = format; + pf_get_block(format, &surf->block); + surf->nblocksx = pf_get_nblocksx(&surf->block, width); + surf->nblocksy = pf_get_nblocksy(&surf->block, height); + surf->stride = round_up(surf->nblocksx * surf->block.size, alignment); + surf->usage = flags; + + assert(!surf->buffer); + surf->buffer = winsys->buffer_create(winsys, alignment, + PIPE_BUFFER_USAGE_PIXEL, + surf->stride * surf->nblocksy); if(!surf->buffer) - return -1; + return -1; - return 0; + return 0; } static void diff --git a/src/mesa/state_tracker/st_cb_accum.c b/src/mesa/state_tracker/st_cb_accum.c index 8098d75e18..809a906ba3 100644 --- a/src/mesa/state_tracker/st_cb_accum.c +++ b/src/mesa/state_tracker/st_cb_accum.c @@ -66,15 +66,17 @@ acc_get_tile_rgba(struct pipe_context *pipe, struct pipe_surface *acc_ps, uint x, uint y, uint w, uint h, float *p) { const enum pipe_format f = acc_ps->format; - const int cpp = acc_ps->cpp; + const struct pipe_format_block b = acc_ps->block; acc_ps->format = DEFAULT_ACCUM_PIPE_FORMAT; - acc_ps->cpp = 8; + acc_ps->block.size = 8; + acc_ps->block.width = 1; + acc_ps->block.height = 1; pipe_get_tile_rgba(pipe, acc_ps, x, y, w, h, p); acc_ps->format = f; - acc_ps->cpp = cpp; + acc_ps->block = b; } @@ -88,15 +90,17 @@ acc_put_tile_rgba(struct pipe_context *pipe, struct pipe_surface *acc_ps, uint x, uint y, uint w, uint h, const float *p) { enum pipe_format f = acc_ps->format; - const int cpp = acc_ps->cpp; + const struct pipe_format_block b = acc_ps->block; acc_ps->format = DEFAULT_ACCUM_PIPE_FORMAT; - acc_ps->cpp = 8; + acc_ps->block.size = 8; + acc_ps->block.width = 1; + acc_ps->block.height = 1; pipe_put_tile_rgba(pipe, acc_ps, x, y, w, h, p); acc_ps->format = f; - acc_ps->cpp = cpp; + acc_ps->block = b; } @@ -111,7 +115,7 @@ st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) const GLint ypos = ctx->DrawBuffer->_Ymin; const GLint width = ctx->DrawBuffer->_Xmax - xpos; const GLint height = ctx->DrawBuffer->_Ymax - ypos; - GLvoid *map; + GLubyte *map; acc_ps = screen->get_tex_surface(screen, acc_strb->texture, 0, 0, 0, PIPE_BUFFER_USAGE_CPU_WRITE); @@ -128,8 +132,7 @@ st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) GLshort a = FLOAT_TO_SHORT(ctx->Accum.ClearColor[3]); int i, j; for (i = 0; i < height; i++) { - GLshort *dst = ((GLshort *) map - + ((ypos + i) * acc_ps->pitch + xpos) * 4); + GLshort *dst = (GLshort *) (map + (ypos + i) * acc_ps->stride + xpos * 8); for (j = 0; j < width; j++) { dst[0] = r; dst[1] = g; @@ -168,8 +171,7 @@ accum_mad(GLcontext *ctx, GLfloat scale, GLfloat bias, { int i, j; for (i = 0; i < height; i++) { - GLshort *acc = ((GLshort *) map - + ((ypos + i) * acc_ps->pitch + xpos) * 4); + GLshort *acc = (GLshort *) (map + (ypos + i) * acc_ps->stride + xpos * 8); for (j = 0; j < width * 4; j++) { float val = SHORT_TO_FLOAT(acc[j]) * scale + bias; acc[j] = FLOAT_TO_SHORT(val); diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index 6fa3cbd533..f3bc3b8584 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -341,9 +341,9 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, dest = screen->surface_map(screen, surface, PIPE_BUFFER_USAGE_CPU_WRITE); /* Put image into texture surface */ - memset(dest, 0xff, height * surface->pitch); + memset(dest, 0xff, height * surface->stride); unpack_bitmap(ctx->st, 0, 0, width, height, unpack, bitmap, - dest, surface->pitch); + dest, surface->stride); _mesa_unmap_bitmap_pbo(ctx, unpack); diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index d8f1d2367c..a7781f3ab2 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -382,7 +382,7 @@ make_texture(struct st_context *st, mformat, /* gl_texture_format */ dest, /* dest */ 0, 0, 0, /* dstX/Y/Zoffset */ - surface->pitch * cpp, /* dstRowStride, bytes */ + surface->stride, /* dstRowStride, bytes */ &dstImageOffsets, /* dstImageOffsets */ width, height, 1, /* size */ format, type, /* src format/type */ @@ -786,13 +786,13 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, switch (ps->format) { case PIPE_FORMAT_S8_UNORM: { - ubyte *dest = stmap + spanY * ps->pitch + spanX; + ubyte *dest = stmap + spanY * ps->stride + spanX; memcpy(dest, values, spanWidth); } break; case PIPE_FORMAT_S8Z24_UNORM: { - uint *dest = (uint *) stmap + spanY * ps->pitch + spanX; + uint *dest = (uint *) (stmap + spanY * ps->stride + spanX*4); GLint k; for (k = 0; k < spanWidth; k++) { uint p = dest[k]; @@ -903,6 +903,9 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, psDraw = screen->get_tex_surface(screen, rbDraw->texture, 0, 0, 0, PIPE_BUFFER_USAGE_CPU_WRITE); + assert(psDraw->block.width == 1); + assert(psDraw->block.height == 1); + /* map the stencil buffer */ drawMap = screen->surface_map(screen, psDraw, PIPE_BUFFER_USAGE_CPU_WRITE); @@ -919,7 +922,7 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, y = ctx->DrawBuffer->Height - y - 1; } - dst = drawMap + (y * psDraw->pitch + dstx) * psDraw->cpp; + dst = drawMap + y * psDraw->stride + dstx * psDraw->block.size; src = buffer + i * width; switch (psDraw->format) { diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index db25ddd615..1067caf9b3 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -113,7 +113,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, template.target = PIPE_TEXTURE_2D; template.compressed = 0; - template.cpp = pf_get_size(template.format); + pf_get_block(template.format, &template.block); template.width[0] = width; template.height[0] = height; template.depth[0] = 1; @@ -171,10 +171,12 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, assert(strb->surface->buffer); assert(strb->surface->format); - assert(strb->surface->cpp); + assert(strb->surface->block.size); + assert(strb->surface->block.width); + assert(strb->surface->block.height); assert(strb->surface->width == width); assert(strb->surface->height == height); - assert(strb->surface->pitch); + assert(strb->surface->stride); return strb->surface != NULL; diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c index c5193631a7..09d9c29e44 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -94,13 +94,13 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, switch (ps->format) { case PIPE_FORMAT_S8_UNORM: { - const ubyte *src = stmap + srcY * ps->pitch + x; + const ubyte *src = stmap + srcY * ps->stride + x; memcpy(values, src, width); } break; case PIPE_FORMAT_S8Z24_UNORM: { - const uint *src = (uint *) stmap + srcY * ps->pitch + x; + const uint *src = (uint *) (stmap + srcY * ps->stride + x*4); GLint k; for (k = 0; k < width; k++) { values[k] = src[k] >> 24; @@ -109,7 +109,7 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, break; case PIPE_FORMAT_Z24S8_UNORM: { - const uint *src = (uint *) stmap + srcY * ps->pitch + x; + const uint *src = (uint *) (stmap + srcY * ps->stride + x*4); GLint k; for (k = 0; k < width; k++) { values[k] = src[k] & 0xff; diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 7d52d1da1b..b9aa513d72 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -658,7 +658,7 @@ st_TexImage(GLcontext * ctx, texImage->Data = st_texture_image_map(ctx->st, stImage, 0, PIPE_BUFFER_USAGE_CPU_WRITE); if (stImage->surface) - dstRowStride = stImage->surface->pitch * stImage->surface->cpp; + dstRowStride = stImage->surface->stride; } else { /* Allocate regular memory and store the image there temporarily. */ @@ -820,7 +820,7 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level, */ texImage->Data = st_texture_image_map(ctx->st, stImage, 0, PIPE_BUFFER_USAGE_CPU_READ); - texImage->RowStride = stImage->surface->pitch; + texImage->RowStride = stImage->surface->stride / stImage->pt->block.size; } else { /* Otherwise, the image should actually be stored in @@ -925,7 +925,7 @@ st_TexSubimage(GLcontext * ctx, texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset, PIPE_BUFFER_USAGE_CPU_WRITE); if (stImage->surface) - dstRowStride = stImage->surface->pitch * stImage->surface->cpp; + dstRowStride = stImage->surface->stride; } if (!texImage->Data) { @@ -1425,9 +1425,11 @@ copy_image_data_to_texture(struct st_context *st, stImage->face, dstLevel, stImage->base.Data, - stImage->base.RowStride, + stImage->base.RowStride * + stObj->pt->block.size, stImage->base.RowStride * - stImage->base.Height); + stImage->base.Height * + stObj->pt->block.size); _mesa_align_free(stImage->base.Data); stImage->base.Data = NULL; } @@ -1477,6 +1479,7 @@ st_finalize_texture(GLcontext *ctx, pipe_texture_reference(&stObj->pt, firstImage->pt); } + /* FIXME: determine format block instead of cpp */ if (firstImage->base.IsCompressed) { comp_byte = compressed_num_bytes(firstImage->base.TexFormat->MesaFormat); cpp = comp_byte; @@ -1497,7 +1500,9 @@ st_finalize_texture(GLcontext *ctx, stObj->pt->width[0] != firstImage->base.Width2 || stObj->pt->height[0] != firstImage->base.Height2 || stObj->pt->depth[0] != firstImage->base.Depth2 || - stObj->pt->cpp != cpp || + stObj->pt->block.size != cpp || + stObj->pt->block.width != 1 || + stObj->pt->block.height != 1 || stObj->pt->compressed != firstImage->base.IsCompressed) { pipe_texture_release(&stObj->pt); ctx->st->dirty.st |= ST_NEW_FRAMEBUFFER; diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c index 851f17c3b4..2fc00df429 100644 --- a/src/mesa/state_tracker/st_gen_mipmap.c +++ b/src/mesa/state_tracker/st_gen_mipmap.c @@ -137,10 +137,10 @@ fallback_generate_mipmap(GLcontext *ctx, GLenum target, _mesa_generate_mipmap_level(target, datatype, comps, 0 /*border*/, pt->width[srcLevel], pt->height[srcLevel], pt->depth[srcLevel], - srcSurf->pitch * srcSurf->cpp, /* stride in bytes */ + srcSurf->stride, /* stride in bytes */ srcData, pt->width[dstLevel], pt->height[dstLevel], pt->depth[dstLevel], - dstSurf->pitch * dstSurf->cpp, /* stride in bytes */ + dstSurf->stride, /* stride in bytes */ dstData); pipe_buffer_unmap(pipe, srcSurf->buffer); diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c index 9553b34e31..8222826e7a 100644 --- a/src/mesa/state_tracker/st_texture.c +++ b/src/mesa/state_tracker/st_texture.c @@ -98,7 +98,7 @@ st_texture_create(struct st_context *st, pt.height[0] = height0; pt.depth[0] = depth0; pt.compressed = compress_byte ? 1 : 0; - pt.cpp = pt.compressed ? compress_byte : st_sizeof_format(format); + pf_get_block(format, &pt.block); pt.tex_usage = usage; newtex = screen->texture_create(screen, &pt); @@ -231,16 +231,19 @@ static void st_surface_data(struct pipe_context *pipe, struct pipe_surface *dst, unsigned dstx, unsigned dsty, - const void *src, unsigned src_pitch, + const void *src, unsigned src_stride, unsigned srcx, unsigned srcy, unsigned width, unsigned height) { struct pipe_screen *screen = pipe->screen; void *map = screen->surface_map(screen, dst, PIPE_BUFFER_USAGE_CPU_WRITE); pipe_copy_rect(map, - dst->cpp, - dst->pitch, - dstx, dsty, width, height, src, src_pitch, srcx, srcy); + &dst->block, + dst->stride, + dstx, dsty, + width, height, + src, src_stride, + srcx, srcy); screen->surface_unmap(screen, dst); } @@ -254,34 +257,29 @@ st_texture_image_data(struct pipe_context *pipe, GLuint face, GLuint level, void *src, - GLuint src_row_pitch, GLuint src_image_pitch) + GLuint src_row_stride, GLuint src_image_stride) { struct pipe_screen *screen = pipe->screen; GLuint depth = dst->depth[level]; GLuint i; - GLuint height = 0; const GLubyte *srcUB = src; struct pipe_surface *dst_surface; DBG("%s\n", __FUNCTION__); for (i = 0; i < depth; i++) { - height = dst->height[level]; - if(dst->compressed) - height /= 4; - dst_surface = screen->get_tex_surface(screen, dst, face, level, i, PIPE_BUFFER_USAGE_CPU_WRITE); st_surface_data(pipe, dst_surface, 0, 0, /* dstx, dsty */ srcUB, - src_row_pitch, + src_row_stride, 0, 0, /* source x, y */ - dst->width[level], height); /* width, height */ + dst->width[level], dst->height[level]); /* width, height */ screen->tex_surface_release(screen, &dst_surface); - srcUB += src_image_pitch * dst->cpp; + srcUB += src_image_stride; } } -- cgit v1.2.3 From 429a08384c2ea66d446e46beb28e33ee3b764d52 Mon Sep 17 00:00:00 2001 From: Roland Scheidegger Date: Fri, 27 Jun 2008 16:02:43 +0200 Subject: gallium: handle msaa --- src/gallium/include/pipe/p_state.h | 6 +- src/gallium/winsys/dri/intel/intel_screen.c | 6 +- src/mesa/drivers/dri/common/utils.c | 97 ++++++++++++++++------------- src/mesa/drivers/dri/common/utils.h | 3 +- src/mesa/main/mtypes.h | 1 + src/mesa/state_tracker/st_cb_fbo.c | 4 +- src/mesa/state_tracker/st_cb_fbo.h | 2 +- src/mesa/state_tracker/st_framebuffer.c | 18 +++--- 8 files changed, 77 insertions(+), 60 deletions(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h index 2992e2f3b3..5546796936 100644 --- a/src/gallium/include/pipe/p_state.h +++ b/src/gallium/include/pipe/p_state.h @@ -276,7 +276,7 @@ struct pipe_surface unsigned layout; /**< PIPE_SURFACE_LAYOUT_x */ unsigned offset; /**< offset from start of buffer, in bytes */ unsigned refcount; - unsigned usage; /**< PIPE_BUFFER_USAGE_* */ + unsigned usage; /**< PIPE_BUFFER_USAGE_* */ struct pipe_winsys *winsys; /**< winsys which owns/created the surface */ @@ -311,7 +311,9 @@ struct pipe_texture unsigned last_level:8; /**< Index of last mipmap level present/defined */ unsigned compressed:1; - + + unsigned nr_samples:8; /**< for multisampled surfaces, nr of samples */ + unsigned tex_usage; /* PIPE_TEXTURE_USAGE_* */ /* These are also refcounted: diff --git a/src/gallium/winsys/dri/intel/intel_screen.c b/src/gallium/winsys/dri/intel/intel_screen.c index 89de188ada..cfecebdb8c 100644 --- a/src/gallium/winsys/dri/intel/intel_screen.c +++ b/src/gallium/winsys/dri/intel/intel_screen.c @@ -483,11 +483,13 @@ intelFillInModes(unsigned pixel_bits, unsigned depth_bits, uint8_t depth_bits_array[3]; uint8_t stencil_bits_array[3]; + uint8_t msaa_samples_array[1]; depth_bits_array[0] = 0; depth_bits_array[1] = depth_bits; depth_bits_array[2] = depth_bits; + msaa_samples_array[0] = 0; /* Just like with the accumulation buffer, always provide some modes * with a stencil buffer. It will be a sw fallback, but some apps won't @@ -521,7 +523,7 @@ intelFillInModes(unsigned pixel_bits, unsigned depth_bits, if (!driFillInModes(&m, fb_format, fb_type, depth_bits_array, stencil_bits_array, depth_buffer_factor, back_buffer_modes, - back_buffer_factor, GLX_TRUE_COLOR)) { + back_buffer_factor, msaa_samples_array, 1, GLX_TRUE_COLOR)) { fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__, __LINE__); return NULL; @@ -529,7 +531,7 @@ intelFillInModes(unsigned pixel_bits, unsigned depth_bits, if (!driFillInModes(&m, fb_format, fb_type, depth_bits_array, stencil_bits_array, depth_buffer_factor, back_buffer_modes, - back_buffer_factor, GLX_DIRECT_COLOR)) { + back_buffer_factor, msaa_samples_array, 1, GLX_DIRECT_COLOR)) { fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__, __LINE__); return NULL; diff --git a/src/mesa/drivers/dri/common/utils.c b/src/mesa/drivers/dri/common/utils.c index 94db319928..3cf2146dce 100644 --- a/src/mesa/drivers/dri/common/utils.c +++ b/src/mesa/drivers/dri/common/utils.c @@ -521,6 +521,9 @@ GLboolean driClipRectToFramebuffer( const GLframebuffer *buffer, * \c GLX_SWAP_UNDEFINED_OML. See the * GLX_OML_swap_method extension spec for more details. * \param num_db_modes Number of entries in \c db_modes. + * \param msaa_samples Array of msaa sample count. 0 represents a visual + * without a multisample buffer. + * \param num_msaa_modes Number of entries in \c msaa_samples. * \param visType GLX visual type. Usually either \c GLX_TRUE_COLOR or * \c GLX_DIRECT_COLOR. * @@ -542,6 +545,7 @@ driFillInModes( __GLcontextModes ** ptr_to_modes, const uint8_t * depth_bits, const uint8_t * stencil_bits, unsigned num_depth_stencil_bits, const GLenum * db_modes, unsigned num_db_modes, + const u_int8_t * msaa_samples, unsigned num_msaa_modes, int visType ) { static const uint8_t bits_table[3][4] = { @@ -607,9 +611,7 @@ driFillInModes( __GLcontextModes ** ptr_to_modes, const uint32_t * masks; const int index = fb_type & 0x07; __GLcontextModes * modes = *ptr_to_modes; - unsigned i; - unsigned j; - unsigned k; + unsigned i, j, k, h; if ( bytes_per_pixel[ index ] == 0 ) { @@ -659,49 +661,54 @@ driFillInModes( __GLcontextModes ** ptr_to_modes, for ( k = 0 ; k < num_depth_stencil_bits ; k++ ) { for ( i = 0 ; i < num_db_modes ; i++ ) { - for ( j = 0 ; j < 2 ; j++ ) { - - modes->redBits = bits[0]; - modes->greenBits = bits[1]; - modes->blueBits = bits[2]; - modes->alphaBits = bits[3]; - modes->redMask = masks[0]; - modes->greenMask = masks[1]; - modes->blueMask = masks[2]; - modes->alphaMask = masks[3]; - modes->rgbBits = modes->redBits + modes->greenBits - + modes->blueBits + modes->alphaBits; - - modes->accumRedBits = 16 * j; - modes->accumGreenBits = 16 * j; - modes->accumBlueBits = 16 * j; - modes->accumAlphaBits = (masks[3] != 0) ? 16 * j : 0; - modes->visualRating = (j == 0) ? GLX_NONE : GLX_SLOW_CONFIG; - - modes->stencilBits = stencil_bits[k]; - modes->depthBits = depth_bits[k]; - - modes->visualType = visType; - modes->renderType = GLX_RGBA_BIT; - modes->drawableType = GLX_WINDOW_BIT; - modes->rgbMode = GL_TRUE; - - if ( db_modes[i] == GLX_NONE ) { - modes->doubleBufferMode = GL_FALSE; + for ( h = 0 ; h < num_msaa_modes; h++ ) { + for ( j = 0 ; j < 2 ; j++ ) { + + modes->redBits = bits[0]; + modes->greenBits = bits[1]; + modes->blueBits = bits[2]; + modes->alphaBits = bits[3]; + modes->redMask = masks[0]; + modes->greenMask = masks[1]; + modes->blueMask = masks[2]; + modes->alphaMask = masks[3]; + modes->rgbBits = modes->redBits + modes->greenBits + + modes->blueBits + modes->alphaBits; + + modes->accumRedBits = 16 * j; + modes->accumGreenBits = 16 * j; + modes->accumBlueBits = 16 * j; + modes->accumAlphaBits = (masks[3] != 0) ? 16 * j : 0; + modes->visualRating = (j == 0) ? GLX_NONE : GLX_SLOW_CONFIG; + + modes->stencilBits = stencil_bits[k]; + modes->depthBits = depth_bits[k]; + + modes->visualType = visType; + modes->renderType = GLX_RGBA_BIT; + modes->drawableType = GLX_WINDOW_BIT; + modes->rgbMode = GL_TRUE; + + if ( db_modes[i] == GLX_NONE ) { + modes->doubleBufferMode = GL_FALSE; + } + else { + modes->doubleBufferMode = GL_TRUE; + modes->swapMethod = db_modes[i]; + } + + modes->samples = msaa_samples[h]; + modes->sampleBuffers = modes->samples ? 1 : 0; + + modes->haveAccumBuffer = ((modes->accumRedBits + + modes->accumGreenBits + + modes->accumBlueBits + + modes->accumAlphaBits) > 0); + modes->haveDepthBuffer = (modes->depthBits > 0); + modes->haveStencilBuffer = (modes->stencilBits > 0); + + modes = modes->next; } - else { - modes->doubleBufferMode = GL_TRUE; - modes->swapMethod = db_modes[i]; - } - - modes->haveAccumBuffer = ((modes->accumRedBits + - modes->accumGreenBits + - modes->accumBlueBits + - modes->accumAlphaBits) > 0); - modes->haveDepthBuffer = (modes->depthBits > 0); - modes->haveStencilBuffer = (modes->stencilBits > 0); - - modes = modes->next; } } } diff --git a/src/mesa/drivers/dri/common/utils.h b/src/mesa/drivers/dri/common/utils.h index 1067d0a8bf..20940c21b4 100644 --- a/src/mesa/drivers/dri/common/utils.h +++ b/src/mesa/drivers/dri/common/utils.h @@ -115,6 +115,7 @@ extern GLboolean driFillInModes( __GLcontextModes ** modes, GLenum fb_format, GLenum fb_type, const uint8_t * depth_bits, const uint8_t * stencil_bits, unsigned num_depth_stencil_bits, - const GLenum * db_modes, unsigned num_db_modes, int visType ); + const GLenum * db_modes, unsigned num_db_modes, + const u_int8_t * msaa_samples, unsigned num_msaa_modes, int visType ); #endif /* DRI_DEBUG_H */ diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index dceb7611f2..0a065541e1 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -2269,6 +2269,7 @@ struct gl_renderbuffer GLubyte IndexBits; GLubyte DepthBits; GLubyte StencilBits; + GLubyte Samples; /**< Number of samples - 0 if not multisampled */ GLvoid *Data; /**< This may not be used by some kinds of RBs */ /* Used to wrap one renderbuffer around another: */ diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 1067caf9b3..7245798d0d 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -118,6 +118,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, template.height[0] = height; template.depth[0] = 1; template.last_level = 0; + template.nr_samples = rb->Samples; if (pf_is_depth_stencil(template.format)) { template.tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL; @@ -249,7 +250,7 @@ st_new_renderbuffer(GLcontext *ctx, GLuint name) * renderbuffer). The window system code determines the format. */ struct gl_renderbuffer * -st_new_renderbuffer_fb(enum pipe_format format) +st_new_renderbuffer_fb(enum pipe_format format, int samples) { struct st_renderbuffer *strb; @@ -261,6 +262,7 @@ st_new_renderbuffer_fb(enum pipe_format format) _mesa_init_renderbuffer(&strb->Base, 0); strb->Base.ClassID = 0x4242; /* just a unique value */ + strb->Base.Samples = samples; strb->format = format; switch (format) { diff --git a/src/mesa/state_tracker/st_cb_fbo.h b/src/mesa/state_tracker/st_cb_fbo.h index 87b0734a0c..ff56001a4e 100644 --- a/src/mesa/state_tracker/st_cb_fbo.h +++ b/src/mesa/state_tracker/st_cb_fbo.h @@ -58,7 +58,7 @@ st_renderbuffer(struct gl_renderbuffer *rb) extern struct gl_renderbuffer * -st_new_renderbuffer_fb(enum pipe_format format); +st_new_renderbuffer_fb(enum pipe_format format, int samples); extern void st_init_fbo_functions(struct dd_function_table *functions); diff --git a/src/mesa/state_tracker/st_framebuffer.c b/src/mesa/state_tracker/st_framebuffer.c index 1b6e68c2a1..1994a1c826 100644 --- a/src/mesa/state_tracker/st_framebuffer.c +++ b/src/mesa/state_tracker/st_framebuffer.c @@ -51,27 +51,29 @@ st_create_framebuffer( const __GLcontextModes *visual, { struct st_framebuffer *stfb = CALLOC_STRUCT(st_framebuffer); if (stfb) { + int samples = 0; _mesa_initialize_framebuffer(&stfb->Base, visual); + if (visual->sampleBuffers) samples = visual->samples; { /* fake frontbuffer */ /* XXX allocation should only happen in the unusual case it's actually needed */ struct gl_renderbuffer *rb - = st_new_renderbuffer_fb(colorFormat); + = st_new_renderbuffer_fb(colorFormat, samples); _mesa_add_renderbuffer(&stfb->Base, BUFFER_FRONT_LEFT, rb); } if (visual->doubleBufferMode) { struct gl_renderbuffer *rb - = st_new_renderbuffer_fb(colorFormat); + = st_new_renderbuffer_fb(colorFormat, samples); _mesa_add_renderbuffer(&stfb->Base, BUFFER_BACK_LEFT, rb); } if (visual->depthBits == 24 && visual->stencilBits == 8) { /* combined depth/stencil buffer */ struct gl_renderbuffer *depthStencilRb - = st_new_renderbuffer_fb(depthFormat); + = st_new_renderbuffer_fb(depthFormat, samples); /* note: bind RB to two attachment points */ _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthStencilRb); _mesa_add_renderbuffer(&stfb->Base, BUFFER_STENCIL, depthStencilRb); @@ -82,26 +84,26 @@ st_create_framebuffer( const __GLcontextModes *visual, if (visual->depthBits == 32) { /* 32-bit depth buffer */ struct gl_renderbuffer *depthRb - = st_new_renderbuffer_fb(depthFormat); + = st_new_renderbuffer_fb(depthFormat, samples); _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb); } else if (visual->depthBits == 24) { /* 24-bit depth buffer, ignore stencil bits */ struct gl_renderbuffer *depthRb - = st_new_renderbuffer_fb(depthFormat); + = st_new_renderbuffer_fb(depthFormat, samples); _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb); } else if (visual->depthBits > 0) { /* 16-bit depth buffer */ struct gl_renderbuffer *depthRb - = st_new_renderbuffer_fb(depthFormat); + = st_new_renderbuffer_fb(depthFormat, samples); _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb); } if (visual->stencilBits > 0) { /* 8-bit stencil */ struct gl_renderbuffer *stencilRb - = st_new_renderbuffer_fb(stencilFormat); + = st_new_renderbuffer_fb(stencilFormat, samples); _mesa_add_renderbuffer(&stfb->Base, BUFFER_STENCIL, stencilRb); } } @@ -109,7 +111,7 @@ st_create_framebuffer( const __GLcontextModes *visual, if (visual->accumRedBits > 0) { /* 16-bit/channel accum */ struct gl_renderbuffer *accumRb - = st_new_renderbuffer_fb(DEFAULT_ACCUM_PIPE_FORMAT); + = st_new_renderbuffer_fb(DEFAULT_ACCUM_PIPE_FORMAT, 0); /* XXX accum isn't multisampled right? */ _mesa_add_renderbuffer(&stfb->Base, BUFFER_ACCUM, accumRb); } -- cgit v1.2.3 From 9ca1c62a963ca7024c4bccf83af3f90955cd5068 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 4 Jul 2008 10:02:16 -0600 Subject: gallium: replace assertion with conditional --- src/mesa/state_tracker/st_cb_fbo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/mesa/state_tracker/st_cb_fbo.c') diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 7245798d0d..8406bf247f 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -422,7 +422,8 @@ st_finish_render_texture(GLcontext *ctx, struct pipe_screen *screen = ctx->st->pipe->screen; struct st_renderbuffer *strb = st_renderbuffer(att->Renderbuffer); - assert(strb); + if (!strb) + return; ctx->st->pipe->flush(ctx->st->pipe, PIPE_FLUSH_RENDER_CACHE, NULL); -- cgit v1.2.3