diff options
Diffstat (limited to 'src/mesa/state_tracker')
44 files changed, 2626 insertions, 2089 deletions
diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c index 7806df4a531..cf391f1f91f 100644 --- a/src/mesa/state_tracker/st_atom.c +++ b/src/mesa/state_tracker/st_atom.c @@ -34,8 +34,7 @@ #include "st_atom.h" #include "st_cb_bitmap.h" #include "st_program.h" - -#include "pipe/p_context.h" +#include "st_manager.h" /** @@ -136,9 +135,7 @@ void st_validate_state( struct st_context *st ) check_program_state( st ); - if (st->pipe->screen->update_buffer) - st->pipe->screen->update_buffer(st->pipe->screen, - st->pipe->priv); + st_manager_validate_framebuffers(st); if (state->st == 0) return; diff --git a/src/mesa/state_tracker/st_atom_constbuf.c b/src/mesa/state_tracker/st_atom_constbuf.c index d975cd66f7d..a8f2b879d53 100644 --- a/src/mesa/state_tracker/st_atom_constbuf.c +++ b/src/mesa/state_tracker/st_atom_constbuf.c @@ -57,7 +57,7 @@ void st_upload_constants( struct st_context *st, unsigned shader_type) { struct pipe_context *pipe = st->pipe; - struct pipe_buffer **cbuf = &st->state.constants[shader_type]; + struct pipe_resource **cbuf = &st->state.constants[shader_type]; assert(shader_type == PIPE_SHADER_VERTEX || shader_type == PIPE_SHADER_FRAGMENT); @@ -71,10 +71,10 @@ 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(cbuf, NULL ); - *cbuf = pipe_buffer_create(pipe->screen, 16, - PIPE_BUFFER_USAGE_CONSTANT, - paramBytes ); + pipe_resource_reference(cbuf, NULL ); + *cbuf = pipe_buffer_create(pipe->screen, + PIPE_BIND_CONSTANT_BUFFER, + paramBytes ); if (ST_DEBUG & DEBUG_CONSTANTS) { debug_printf("%s(shader=%d, numParams=%d, stateFlags=0x%x)\n", @@ -84,10 +84,9 @@ void st_upload_constants( struct st_context *st, } /* load Mesa constants into the constant buffer */ - if (cbuf) - st_no_flush_pipe_buffer_write(st, *cbuf, - 0, paramBytes, - params->ParameterValues); + st_no_flush_pipe_buffer_write(st, *cbuf, + 0, paramBytes, + params->ParameterValues); st->pipe->set_constant_buffer(st->pipe, shader_type, 0, *cbuf); } diff --git a/src/mesa/state_tracker/st_atom_framebuffer.c b/src/mesa/state_tracker/st_atom_framebuffer.c index fba7bfe2cea..52c507da3b3 100644 --- a/src/mesa/state_tracker/st_atom_framebuffer.c +++ b/src/mesa/state_tracker/st_atom_framebuffer.c @@ -34,11 +34,9 @@ #include "st_context.h" #include "st_atom.h" #include "st_cb_fbo.h" -#include "st_public.h" #include "st_texture.h" #include "pipe/p_context.h" #include "cso_cache/cso_context.h" -#include "util/u_rect.h" #include "util/u_math.h" #include "util/u_inlines.h" @@ -46,7 +44,7 @@ /** * 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. + * didn't yank out the pipe_resource that we earlier created a surface for. * Check for that here and create a new surface if needed. */ static void @@ -54,29 +52,30 @@ 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; + struct pipe_resource *resource = strb->rtt->pt; int rtt_width = strb->Base.Width; int rtt_height = strb->Base.Height; if (!strb->surface || - strb->surface->texture != texture || + strb->surface->texture != resource || strb->surface->width != rtt_width || strb->surface->height != rtt_height) { GLuint level; /* find matching mipmap level size */ - for (level = 0; level <= texture->last_level; level++) { - if (u_minify(texture->width0, level) == rtt_width && - u_minify(texture->height0, level) == rtt_height) { + for (level = 0; level <= resource->last_level; level++) { + if (u_minify(resource->width0, level) == rtt_width && + u_minify(resource->height0, 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); + resource, + strb->rtt_face, + level, + strb->rtt_slice, + PIPE_BIND_RENDER_TARGET | + PIPE_BIND_BLIT_SOURCE | + PIPE_BIND_BLIT_DESTINATION ); #if 0 printf("-- alloc new surface %d x %d into tex %p\n", strb->surface->width, strb->surface->height, @@ -154,31 +153,17 @@ update_framebuffer_state( struct st_context *st ) pipe_surface_reference(&framebuffer->zsbuf, NULL); } - cso_set_framebuffer(st->cso_context, framebuffer); - - if (fb->_ColorDrawBufferIndexes[0] == BUFFER_FRONT_LEFT) { - if (st->frontbuffer_status == FRONT_STATUS_COPY_OF_BACK) { - /* copy back color buffer to front color buffer */ - struct st_framebuffer *stfb = (struct st_framebuffer *) fb; - struct pipe_surface *surf_front, *surf_back; - (void) st_get_framebuffer_surface(stfb, ST_SURFACE_FRONT_LEFT, &surf_front); - (void) st_get_framebuffer_surface(stfb, ST_SURFACE_BACK_LEFT, &surf_back); - - if (st->pipe->surface_copy) { - st->pipe->surface_copy(st->pipe, - surf_front, 0, 0, /* dest */ - surf_back, 0, 0, /* src */ - fb->Width, fb->Height); - } else { - util_surface_copy(st->pipe, FALSE, - surf_front, 0, 0, - surf_back, 0, 0, - fb->Width, fb->Height); - } - } - /* we're assuming we'll really draw to the front buffer */ - st->frontbuffer_status = FRONT_STATUS_DIRTY; +#ifdef DEBUG + /* Make sure the resource binding flags were set properly */ + for (i = 0; i < framebuffer->nr_cbufs; i++) { + assert(framebuffer->cbufs[i]->texture->bind & PIPE_BIND_RENDER_TARGET); } + if (framebuffer->zsbuf) { + assert(framebuffer->zsbuf->texture->bind & PIPE_BIND_DEPTH_STENCIL); + } +#endif + + cso_set_framebuffer(st->cso_context, framebuffer); } diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c b/src/mesa/state_tracker/st_atom_pixeltransfer.c index 0b2e3f53812..29c4d092bf0 100644 --- a/src/mesa/state_tracker/st_atom_pixeltransfer.c +++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c @@ -112,21 +112,22 @@ make_state_key(GLcontext *ctx, struct state_key *key) } -static struct pipe_texture * +static struct pipe_resource * create_color_map_texture(GLcontext *ctx) { - struct pipe_context *pipe = ctx->st->pipe; - struct pipe_texture *pt; + struct st_context *st = st_context(ctx); + struct pipe_context *pipe = st->pipe; + struct pipe_resource *pt; enum pipe_format format; const uint texSize = 256; /* simple, and usually perfect */ /* find an RGBA texture format */ format = st_choose_format(pipe->screen, GL_RGBA, - PIPE_TEXTURE_2D, PIPE_TEXTURE_USAGE_SAMPLER); + PIPE_TEXTURE_2D, PIPE_BIND_SAMPLER_VIEW); /* create texture for color map/table */ - pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, format, 0, - texSize, texSize, 1, PIPE_TEXTURE_USAGE_SAMPLER); + pt = st_texture_create(st, PIPE_TEXTURE_2D, format, 0, + texSize, texSize, 1, PIPE_BIND_SAMPLER_VIEW); return pt; } @@ -135,10 +136,10 @@ create_color_map_texture(GLcontext *ctx) * Update the pixelmap texture with the contents of the R/G/B/A pixel maps. */ static void -load_color_map_texture(GLcontext *ctx, struct pipe_texture *pt) +load_color_map_texture(GLcontext *ctx, struct pipe_resource *pt) { - struct pipe_context *pipe = ctx->st->pipe; - struct pipe_screen *screen = pipe->screen; + struct st_context *st = st_context(ctx); + struct pipe_context *pipe = st->pipe; struct pipe_transfer *transfer; const GLuint rSize = ctx->PixelMaps.RtoR.Size; const GLuint gSize = ctx->PixelMaps.GtoG.Size; @@ -151,7 +152,7 @@ load_color_map_texture(GLcontext *ctx, struct pipe_texture *pt) transfer = st_cond_flush_get_tex_transfer(st_context(ctx), pt, 0, 0, 0, PIPE_TRANSFER_WRITE, 0, 0, texSize, texSize); - dest = (uint *) screen->transfer_map(screen, transfer); + dest = (uint *) pipe_transfer_map(pipe, transfer); /* Pack four 1D maps into a 2D texture: * R map is placed horizontally, indexed by S, in channel 0 @@ -172,8 +173,8 @@ load_color_map_texture(GLcontext *ctx, struct pipe_texture *pt) } } - screen->transfer_unmap(screen, transfer); - screen->tex_transfer_destroy(transfer); + pipe_transfer_unmap(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); } @@ -186,7 +187,7 @@ load_color_map_texture(GLcontext *ctx, struct pipe_texture *pt) static struct gl_fragment_program * get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) { - struct st_context *st = ctx->st; + struct st_context *st = st_context(ctx); struct prog_instruction inst[MAX_INST]; struct gl_program_parameter_list *params; struct gl_fragment_program *fp; @@ -257,6 +258,9 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) /* create the colormap/texture now if not already done */ if (!st->pixel_xfer.pixelmap_texture) { st->pixel_xfer.pixelmap_texture = create_color_map_texture(ctx); + st->pixel_xfer.pixelmap_sampler_view = + st_create_texture_sampler_view(st->pipe, + st->pixel_xfer.pixelmap_texture); } /* with a little effort, we can do four pixel map look-ups with diff --git a/src/mesa/state_tracker/st_atom_rasterizer.c b/src/mesa/state_tracker/st_atom_rasterizer.c index 9c9a99bcfc6..5669b1f82af 100644 --- a/src/mesa/state_tracker/st_atom_rasterizer.c +++ b/src/mesa/state_tracker/st_atom_rasterizer.c @@ -209,7 +209,7 @@ static void update_raster_state( struct st_context *st ) */ if (vertProg) { if (vertProg->Base.Id == 0) { - if (vertProg->Base.OutputsWritten & (1 << VERT_RESULT_PSIZ)) { + if (vertProg->Base.OutputsWritten & BITFIELD64_BIT(VERT_RESULT_PSIZ)) { /* generated program which emits point size */ raster->point_size_per_vertex = TRUE; } diff --git a/src/mesa/state_tracker/st_atom_scissor.c b/src/mesa/state_tracker/st_atom_scissor.c index 5e0c51cff0a..56b1383ae39 100644 --- a/src/mesa/state_tracker/st_atom_scissor.c +++ b/src/mesa/state_tracker/st_atom_scissor.c @@ -72,12 +72,15 @@ update_scissor( struct st_context *st ) scissor.minx = scissor.miny = scissor.maxx = scissor.maxy = 0; } - /* Now invert Y. Pipe drivers use the convention Y=0=top for surfaces + /* Now invert Y if needed. + * Gallium drivers use the convention Y=0=top for surfaces. */ - miny = fb->Height - scissor.maxy; - maxy = fb->Height - scissor.miny; - scissor.miny = miny; - scissor.maxy = maxy; + if (st_fb_orientation(fb) == Y_0_TOP) { + miny = fb->Height - scissor.maxy; + maxy = fb->Height - scissor.miny; + scissor.miny = miny; + scissor.maxy = maxy; + } if (memcmp(&scissor, &st->state.scissor, sizeof(scissor)) != 0) { /* state has changed */ diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c index 57b71c1e7b0..f4294ac1e6f 100644 --- a/src/mesa/state_tracker/st_atom_texture.c +++ b/src/mesa/state_tracker/st_atom_texture.c @@ -46,6 +46,7 @@ static void update_textures(struct st_context *st) { + struct pipe_context *pipe = st->pipe; struct gl_vertex_program *vprog = st->ctx->VertexProgram._Current; struct gl_fragment_program *fprog = st->ctx->FragmentProgram._Current; const GLbitfield samplersUsed = (vprog->Base.SamplersUsed | @@ -56,7 +57,7 @@ update_textures(struct st_context *st) /* loop over sampler units (aka tex image units) */ for (su = 0; su < st->ctx->Const.MaxTextureImageUnits; su++) { - struct pipe_texture *pt = NULL; + struct pipe_sampler_view *sampler_view = NULL; if (samplersUsed & (1 << su)) { struct gl_texture_object *texObj; @@ -84,7 +85,7 @@ update_textures(struct st_context *st) st->state.num_textures = su + 1; - pt = st_get_stobj_texture(stObj); + sampler_view = st_get_texture_sampler_view(stObj, pipe); } /* @@ -96,17 +97,17 @@ update_textures(struct st_context *st) } */ - pipe_texture_reference(&st->state.sampler_texture[su], pt); + pipe_sampler_view_reference(&st->state.sampler_views[su], sampler_view); } - cso_set_sampler_textures(st->cso_context, - st->state.num_textures, - st->state.sampler_texture); + cso_set_fragment_sampler_views(st->cso_context, + st->state.num_textures, + st->state.sampler_views); if (st->ctx->Const.MaxVertexTextureImageUnits > 0) { - cso_set_vertex_sampler_textures(st->cso_context, - MIN2(st->state.num_textures, - st->ctx->Const.MaxVertexTextureImageUnits), - st->state.sampler_texture); + cso_set_vertex_sampler_views(st->cso_context, + MIN2(st->state.num_textures, + st->ctx->Const.MaxVertexTextureImageUnits), + st->state.sampler_views); } } diff --git a/src/mesa/state_tracker/st_cb_accum.c b/src/mesa/state_tracker/st_cb_accum.c index 33e43ddcc4c..0101837f999 100644 --- a/src/mesa/state_tracker/st_cb_accum.c +++ b/src/mesa/state_tracker/st_cb_accum.c @@ -38,7 +38,6 @@ #include "st_context.h" #include "st_cb_accum.h" #include "st_cb_fbo.h" -#include "st_public.h" #include "st_texture.h" #include "st_inlines.h" #include "pipe/p_context.h" @@ -129,7 +128,6 @@ accum_accum(struct st_context *st, GLfloat value, struct st_renderbuffer *color_strb) { struct pipe_context *pipe = st->pipe; - struct pipe_screen *screen = pipe->screen; struct pipe_transfer *color_trans; size_t stride = acc_strb->stride; GLubyte *data = acc_strb->data; @@ -138,14 +136,15 @@ accum_accum(struct st_context *st, GLfloat value, if (ST_DEBUG & DEBUG_FALLBACK) debug_printf("%s: fallback processing\n", __FUNCTION__); - color_trans = st_cond_flush_get_tex_transfer(st, color_strb->texture, + color_trans = st_cond_flush_get_tex_transfer(st, + color_strb->texture, 0, 0, 0, PIPE_TRANSFER_READ, xpos, ypos, width, height); buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - pipe_get_tile_rgba(color_trans, 0, 0, width, height, buf); + pipe_get_tile_rgba(pipe, color_trans, 0, 0, width, height, buf); switch (acc_strb->format) { case PIPE_FORMAT_R16G16B16A16_SNORM: @@ -166,7 +165,7 @@ accum_accum(struct st_context *st, GLfloat value, } free(buf); - screen->tex_transfer_destroy(color_trans); + pipe->transfer_destroy(pipe, color_trans); } @@ -177,7 +176,6 @@ accum_load(struct st_context *st, GLfloat value, struct st_renderbuffer *color_strb) { struct pipe_context *pipe = st->pipe; - struct pipe_screen *screen = pipe->screen; struct pipe_transfer *color_trans; size_t stride = acc_strb->stride; GLubyte *data = acc_strb->data; @@ -194,7 +192,7 @@ accum_load(struct st_context *st, GLfloat value, buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - pipe_get_tile_rgba(color_trans, 0, 0, width, height, buf); + pipe_get_tile_rgba(pipe, color_trans, 0, 0, width, height, buf); switch (acc_strb->format) { case PIPE_FORMAT_R16G16B16A16_SNORM: @@ -215,7 +213,7 @@ accum_load(struct st_context *st, GLfloat value, } free(buf); - screen->tex_transfer_destroy(color_trans); + pipe->transfer_destroy(pipe, color_trans); } @@ -225,8 +223,7 @@ accum_return(GLcontext *ctx, GLfloat value, struct st_renderbuffer *acc_strb, struct st_renderbuffer *color_strb) { - struct pipe_context *pipe = ctx->st->pipe; - struct pipe_screen *screen = pipe->screen; + struct pipe_context *pipe = st_context(ctx)->pipe; const GLubyte *colormask = ctx->Color.ColorMask[0]; enum pipe_transfer_usage usage; struct pipe_transfer *color_trans; @@ -251,7 +248,7 @@ accum_return(GLcontext *ctx, GLfloat value, width, height); if (usage & PIPE_TRANSFER_READ) - pipe_get_tile_rgba(color_trans, 0, 0, width, height, buf); + pipe_get_tile_rgba(pipe, color_trans, 0, 0, width, height, buf); switch (acc_strb->format) { case PIPE_FORMAT_R16G16B16A16_SNORM: @@ -280,17 +277,17 @@ accum_return(GLcontext *ctx, GLfloat value, _mesa_problem(NULL, "unexpected format in st_clear_accum_buffer()"); } - pipe_put_tile_rgba(color_trans, 0, 0, width, height, buf); + pipe_put_tile_rgba(pipe, color_trans, 0, 0, width, height, buf); free(buf); - screen->tex_transfer_destroy(color_trans); + pipe->transfer_destroy(pipe, color_trans); } static void st_Accum(GLcontext *ctx, GLenum op, GLfloat value) { - struct st_context *st = ctx->st; + struct st_context *st = st_context(ctx); struct st_renderbuffer *acc_strb = st_renderbuffer(ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer); struct st_renderbuffer *color_strb diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index 0332d4dbdfe..797c0ba7f55 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -92,7 +92,7 @@ struct bitmap_cache /** Bitmap's Z position */ GLfloat zpos; - struct pipe_texture *texture; + struct pipe_resource *texture; struct pipe_transfer *trans; GLboolean empty; @@ -114,6 +114,7 @@ struct bitmap_cache static struct st_fragment_program * make_bitmap_fragment_program(GLcontext *ctx, GLuint samplerIndex) { + struct st_context *st = st_context(ctx); struct st_fragment_program *stfp; struct gl_program *p; GLuint ic = 0; @@ -145,7 +146,7 @@ make_bitmap_fragment_program(GLcontext *ctx, GLuint samplerIndex) p->Instructions[ic].Opcode = OPCODE_KIL; p->Instructions[ic].SrcReg[0].File = PROGRAM_TEMPORARY; - if (ctx->st->bitmap.tex_format == PIPE_FORMAT_L8_UNORM) + if (st->bitmap.tex_format == PIPE_FORMAT_L8_UNORM) p->Instructions[ic].SrcReg[0].Swizzle = SWIZZLE_XXXX; p->Instructions[ic].SrcReg[0].Index = 0; @@ -187,7 +188,7 @@ find_free_bit(uint bitfield) static struct st_fragment_program * combined_bitmap_fragment_program(GLcontext *ctx) { - struct st_context *st = ctx->st; + struct st_context *st = st_context(ctx); struct st_fragment_program *stfp = st->fp; if (!stfp->bitmap_program) { @@ -253,16 +254,16 @@ unpack_bitmap(struct st_context *st, /** * Create a texture which represents a bitmap image. */ -static struct pipe_texture * +static struct pipe_resource * 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; - struct pipe_screen *screen = pipe->screen; + struct st_context *st = st_context(ctx); + struct pipe_context *pipe = st->pipe; struct pipe_transfer *transfer; ubyte *dest; - struct pipe_texture *pt; + struct pipe_resource *pt; /* PBO source... */ bitmap = _mesa_map_pbo_source(ctx, unpack, bitmap); @@ -273,30 +274,30 @@ 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, + pt = st_texture_create(st, PIPE_TEXTURE_2D, st->bitmap.tex_format, 0, width, height, 1, - PIPE_TEXTURE_USAGE_SAMPLER); + PIPE_BIND_SAMPLER_VIEW); if (!pt) { _mesa_unmap_pbo_source(ctx, unpack); return NULL; } - transfer = st_no_flush_get_tex_transfer(st_context(ctx), pt, 0, 0, 0, + transfer = st_no_flush_get_tex_transfer(st, pt, 0, 0, 0, PIPE_TRANSFER_WRITE, 0, 0, width, height); - dest = screen->transfer_map(screen, transfer); + dest = pipe_transfer_map(pipe, transfer); /* Put image into texture transfer */ memset(dest, 0xff, height * transfer->stride); - unpack_bitmap(ctx->st, 0, 0, width, height, unpack, bitmap, + unpack_bitmap(st, 0, 0, width, height, unpack, bitmap, dest, transfer->stride); _mesa_unmap_pbo_source(ctx, unpack); /* Release transfer */ - screen->transfer_unmap(screen, transfer); - screen->tex_transfer_destroy(transfer); + pipe_transfer_unmap(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); return pt; } @@ -335,13 +336,13 @@ setup_bitmap_vertex_data(struct st_context *st, GLuint i; if (st->bitmap.vbuf_slot >= max_slots) { - pipe_buffer_reference(&st->bitmap.vbuf, NULL); + pipe_resource_reference(&st->bitmap.vbuf, NULL); st->bitmap.vbuf_slot = 0; } if (!st->bitmap.vbuf) { - st->bitmap.vbuf = pipe_buffer_create(pipe->screen, 32, - PIPE_BUFFER_USAGE_VERTEX, + st->bitmap.vbuf = pipe_buffer_create(pipe->screen, + PIPE_BIND_VERTEX_BUFFER, max_slots * sizeof(st->bitmap.vertices)); } @@ -398,12 +399,12 @@ setup_bitmap_vertex_data(struct st_context *st, static void draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, GLsizei width, GLsizei height, - struct pipe_texture *pt, + struct pipe_sampler_view *sv, const GLfloat *color) { - struct st_context *st = ctx->st; - struct pipe_context *pipe = ctx->st->pipe; - struct cso_context *cso = ctx->st->cso_context; + struct st_context *st = st_context(ctx); + struct pipe_context *pipe = st->pipe; + struct cso_context *cso = st->cso_context; struct st_fragment_program *stfp; GLuint maxSize; GLuint offset; @@ -436,10 +437,11 @@ draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, cso_save_rasterizer(cso); cso_save_samplers(cso); - cso_save_sampler_textures(cso); + cso_save_fragment_sampler_views(cso); cso_save_viewport(cso); cso_save_fragment_shader(cso); cso_save_vertex_shader(cso); + cso_save_vertex_elements(cso); /* rasterizer state: just scissor */ st->bitmap.rasterizer.scissor = ctx->Scissor.Enabled; @@ -465,11 +467,11 @@ draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, /* user textures, plus the bitmap texture */ { - struct pipe_texture *textures[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS]; uint num = MAX2(stfp->bitmap_sampler + 1, st->state.num_textures); - memcpy(textures, st->state.sampler_texture, sizeof(textures)); - textures[stfp->bitmap_sampler] = pt; - cso_set_sampler_textures(cso, num, textures); + memcpy(sampler_views, st->state.sampler_views, sizeof(sampler_views)); + sampler_views[stfp->bitmap_sampler] = sv; + cso_set_fragment_sampler_views(cso, num, sampler_views); } /* viewport state: viewport matching window dims */ @@ -490,6 +492,8 @@ draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, cso_set_viewport(cso, &vp); } + cso_set_vertex_elements(cso, 3, st->velems_util_draw); + /* convert Z from [0,1] to [-1,-1] to match viewport Z scale/bias */ z = z * 2.0 - 1.0; @@ -505,10 +509,11 @@ draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, /* restore state */ cso_restore_rasterizer(cso); cso_restore_samplers(cso); - cso_restore_sampler_textures(cso); + cso_restore_fragment_sampler_views(cso); cso_restore_viewport(cso); cso_restore_fragment_shader(cso); cso_restore_vertex_shader(cso); + cso_restore_vertex_elements(cso); } @@ -516,7 +521,6 @@ static void reset_cache(struct st_context *st) { struct pipe_context *pipe = st->pipe; - struct pipe_screen *screen = pipe->screen; struct bitmap_cache *cache = st->bitmap.cache; /*memset(cache->buffer, 0xff, sizeof(cache->buffer));*/ @@ -528,7 +532,7 @@ reset_cache(struct st_context *st) cache->ymax = -1000000; if (cache->trans) { - screen->tex_transfer_destroy(cache->trans); + pipe->transfer_destroy(pipe, cache->trans); cache->trans = NULL; } @@ -538,7 +542,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, PIPE_TEXTURE_USAGE_SAMPLER); + 1, + PIPE_BIND_SAMPLER_VIEW); } @@ -566,7 +571,6 @@ static void create_cache_trans(struct st_context *st) { struct pipe_context *pipe = st->pipe; - struct pipe_screen *screen = pipe->screen; struct bitmap_cache *cache = st->bitmap.cache; if (cache->trans) @@ -579,7 +583,7 @@ create_cache_trans(struct st_context *st) PIPE_TRANSFER_WRITE, 0, 0, BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT); - cache->buffer = screen->transfer_map(screen, cache->trans); + cache->buffer = pipe_transfer_map(pipe, cache->trans); /* init image to all 0xff */ memset(cache->buffer, 0xff, cache->trans->stride * BITMAP_CACHE_HEIGHT); @@ -597,7 +601,7 @@ st_flush_bitmap_cache(struct st_context *st) if (st->ctx->DrawBuffer) { struct pipe_context *pipe = st->pipe; - struct pipe_screen *screen = pipe->screen; + struct pipe_sampler_view *sv; assert(cache->xmin <= cache->xmax); @@ -613,24 +617,29 @@ st_flush_bitmap_cache(struct st_context *st) if (cache->trans) { if (0) print_cache(cache); - screen->transfer_unmap(screen, cache->trans); + pipe_transfer_unmap(pipe, cache->trans); cache->buffer = NULL; - screen->tex_transfer_destroy(cache->trans); + pipe->transfer_destroy(pipe, cache->trans); cache->trans = NULL; } - draw_bitmap_quad(st->ctx, - cache->xpos, - cache->ypos, - cache->zpos, - BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT, - cache->texture, - cache->color); + sv = st_create_texture_sampler_view(st->pipe, cache->texture); + if (sv) { + draw_bitmap_quad(st->ctx, + cache->xpos, + cache->ypos, + cache->zpos, + BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT, + sv, + cache->color); + + pipe_sampler_view_reference(&sv, NULL); + } } /* release/free the texture */ - pipe_texture_reference(&cache->texture, NULL); + pipe_resource_reference(&cache->texture, NULL); reset_cache(st); } @@ -646,7 +655,7 @@ st_flush_bitmap( struct st_context *st ) /* Release vertex buffer to avoid synchronous rendering if we were * to map it in the next frame. */ - pipe_buffer_reference(&st->bitmap.vbuf, NULL); + pipe_resource_reference(&st->bitmap.vbuf, NULL); st->bitmap.vbuf_slot = 0; } @@ -725,8 +734,8 @@ static void st_Bitmap(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, const struct gl_pixelstore_attrib *unpack, const GLubyte *bitmap ) { - struct st_context *st = ctx->st; - struct pipe_texture *pt; + struct st_context *st = st_context(ctx); + struct pipe_resource *pt; if (width == 0 || height == 0) return; @@ -749,12 +758,20 @@ st_Bitmap(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, pt = make_bitmap_texture(ctx, width, height, unpack, bitmap); if (pt) { + struct pipe_sampler_view *sv = st_create_texture_sampler_view(st->pipe, pt); + assert(pt->target == PIPE_TEXTURE_2D); - draw_bitmap_quad(ctx, x, y, ctx->Current.RasterPos[2], - width, height, pt, - st->ctx->Current.RasterColor); + + if (sv) { + draw_bitmap_quad(ctx, x, y, ctx->Current.RasterPos[2], + width, height, sv, + st->ctx->Current.RasterColor); + + pipe_sampler_view_reference(&sv, NULL); + } + /* release/free the texture */ - pipe_texture_reference(&pt, NULL); + pipe_resource_reference(&pt, NULL); } } @@ -791,15 +808,15 @@ st_init_bitmap(struct st_context *st) /* find a usable texture format */ if (screen->is_format_supported(screen, PIPE_FORMAT_I8_UNORM, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_SAMPLER, 0)) { + PIPE_BIND_SAMPLER_VIEW, 0)) { st->bitmap.tex_format = PIPE_FORMAT_I8_UNORM; } else if (screen->is_format_supported(screen, PIPE_FORMAT_A8_UNORM, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_SAMPLER, 0)) { + PIPE_BIND_SAMPLER_VIEW, 0)) { st->bitmap.tex_format = PIPE_FORMAT_A8_UNORM; } else if (screen->is_format_supported(screen, PIPE_FORMAT_L8_UNORM, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_SAMPLER, 0)) { + PIPE_BIND_SAMPLER_VIEW, 0)) { st->bitmap.tex_format = PIPE_FORMAT_L8_UNORM; } else { @@ -819,7 +836,6 @@ void st_destroy_bitmap(struct st_context *st) { struct pipe_context *pipe = st->pipe; - struct pipe_screen *screen = pipe->screen; struct bitmap_cache *cache = st->bitmap.cache; @@ -830,16 +846,16 @@ st_destroy_bitmap(struct st_context *st) } if (st->bitmap.vbuf) { - pipe_buffer_reference(&st->bitmap.vbuf, NULL); + pipe_resource_reference(&st->bitmap.vbuf, NULL); st->bitmap.vbuf = NULL; } if (cache) { if (cache->trans) { - screen->transfer_unmap(screen, cache->trans); - screen->tex_transfer_destroy(cache->trans); + pipe_transfer_unmap(pipe, cache->trans); + pipe->transfer_destroy(pipe, cache->trans); } - pipe_texture_reference(&st->bitmap.cache->texture, NULL); + pipe_resource_reference(&st->bitmap.cache->texture, NULL); free(st->bitmap.cache); st->bitmap.cache = NULL; } diff --git a/src/mesa/state_tracker/st_cb_blit.c b/src/mesa/state_tracker/st_cb_blit.c index 36e03018d9f..1c8dc0c07fb 100644 --- a/src/mesa/state_tracker/st_cb_blit.c +++ b/src/mesa/state_tracker/st_cb_blit.c @@ -68,7 +68,8 @@ st_BlitFramebuffer(GLcontext *ctx, { const GLbitfield depthStencil = (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - struct st_context *st = ctx->st; + struct st_context *st = st_context(ctx); + struct pipe_context *pipe = st->pipe; const uint pFilter = ((filter == GL_NEAREST) ? PIPE_TEX_MIPFILTER_NEAREST : PIPE_TEX_MIPFILTER_LINEAR); @@ -111,8 +112,8 @@ st_BlitFramebuffer(GLcontext *ctx, &readFB->Attachment[readFB->_ColorReadBufferIndex]; if(srcAtt->Type == GL_TEXTURE) { - struct pipe_screen *screen = ctx->st->pipe->screen; - const struct st_texture_object *srcObj = + struct pipe_screen *screen = pipe->screen; + struct st_texture_object *srcObj = st_texture_object(srcAtt->Texture); struct st_renderbuffer *dstRb = st_renderbuffer(drawFB->_ColorDrawBuffers[0]); @@ -127,12 +128,13 @@ st_BlitFramebuffer(GLcontext *ctx, srcAtt->CubeMapFace, srcAtt->TextureLevel, srcAtt->Zoffset, - PIPE_BUFFER_USAGE_GPU_READ); + PIPE_BIND_BLIT_SOURCE); if(!srcSurf) return; util_blit_pixels(st->blit, - srcSurf, srcX0, srcY0, srcX1, srcY1, + srcSurf, st_get_texture_sampler_view(srcObj, pipe), + srcX0, srcY0, srcX1, srcY1, dstSurf, dstX0, dstY0, dstX1, dstY1, 0.0, pFilter); @@ -144,10 +146,11 @@ st_BlitFramebuffer(GLcontext *ctx, struct st_renderbuffer *dstRb = st_renderbuffer(drawFB->_ColorDrawBuffers[0]); struct pipe_surface *srcSurf = srcRb->surface; + struct pipe_sampler_view *srcView = st_get_renderbuffer_sampler_view(srcRb, pipe); struct pipe_surface *dstSurf = dstRb->surface; util_blit_pixels(st->blit, - srcSurf, srcX0, srcY0, srcX1, srcY1, + srcSurf, srcView, srcX0, srcY0, srcX1, srcY1, dstSurf, dstX0, dstY0, dstX1, dstY1, 0.0, pFilter); } @@ -179,11 +182,13 @@ st_BlitFramebuffer(GLcontext *ctx, if ((mask & depthStencil) == depthStencil && srcDepthSurf == srcStencilSurf && dstDepthSurf == dstStencilSurf) { + struct pipe_sampler_view *srcView = st_get_renderbuffer_sampler_view(srcDepthRb, pipe); + /* Blitting depth and stencil values between combined * depth/stencil buffers. This is the ideal case for such buffers. */ util_blit_pixels(st->blit, - srcDepthSurf, srcX0, srcY0, srcX1, srcY1, + srcDepthSurf, srcView, srcX0, srcY0, srcX1, srcY1, dstDepthSurf, dstX0, dstY0, dstX1, dstY1, 0.0, pFilter); } diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c index b55a085cc7c..f24145844b9 100644 --- a/src/mesa/state_tracker/st_cb_bufferobjects.c +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c @@ -76,9 +76,10 @@ st_bufferobj_free(GLcontext *ctx, struct gl_buffer_object *obj) struct st_buffer_object *st_obj = st_buffer_object(obj); assert(obj->RefCount == 0); + assert(st_obj->transfer == NULL); if (st_obj->buffer) - pipe_buffer_reference(&st_obj->buffer, NULL); + pipe_resource_reference(&st_obj->buffer, NULL); free(st_obj); } @@ -116,8 +117,15 @@ st_bufferobj_subdata(GLcontext *ctx, if (!data) return; - st_cond_flush_pipe_buffer_write(st_context(ctx), st_obj->buffer, - offset, size, data); + /* Now that transfers are per-context, we don't have to figure out + * flushing here. Usually drivers won't need to flush in this case + * even if the buffer is currently referenced by hardware - they + * just queue the upload as dma rather than mapping the underlying + * buffer directly. + */ + pipe_buffer_write(st_context(ctx)->pipe, + st_obj->buffer, + offset, size, data); } @@ -141,8 +149,8 @@ st_bufferobj_get_subdata(GLcontext *ctx, if (!size) return; - st_cond_flush_pipe_buffer_read(st_context(ctx), st_obj->buffer, - offset, size, data); + pipe_buffer_read(st_context(ctx)->pipe, st_obj->buffer, + offset, size, data); } @@ -172,22 +180,24 @@ st_bufferobj_data(GLcontext *ctx, switch(target) { case GL_PIXEL_PACK_BUFFER_ARB: case GL_PIXEL_UNPACK_BUFFER_ARB: - buffer_usage = PIPE_BUFFER_USAGE_PIXEL; + buffer_usage = (PIPE_BIND_RENDER_TARGET | + PIPE_BIND_BLIT_SOURCE | + PIPE_BIND_BLIT_DESTINATION); break; case GL_ARRAY_BUFFER_ARB: - buffer_usage = PIPE_BUFFER_USAGE_VERTEX; + buffer_usage = PIPE_BIND_VERTEX_BUFFER; break; case GL_ELEMENT_ARRAY_BUFFER_ARB: - buffer_usage = PIPE_BUFFER_USAGE_INDEX; + buffer_usage = PIPE_BIND_INDEX_BUFFER; break; default: buffer_usage = 0; } - pipe_buffer_reference( &st_obj->buffer, NULL ); + pipe_resource_reference( &st_obj->buffer, NULL ); if (size != 0) { - st_obj->buffer = pipe_buffer_create(pipe->screen, 32, buffer_usage, size); + st_obj->buffer = pipe_buffer_create(pipe->screen, buffer_usage, size); if (!st_obj->buffer) { return GL_FALSE; @@ -215,21 +225,22 @@ st_bufferobj_map(GLcontext *ctx, GLenum target, GLenum access, switch (access) { case GL_WRITE_ONLY: - flags = PIPE_BUFFER_USAGE_CPU_WRITE; + flags = PIPE_TRANSFER_WRITE; break; case GL_READ_ONLY: - flags = PIPE_BUFFER_USAGE_CPU_READ; + flags = PIPE_TRANSFER_READ; break; case GL_READ_WRITE: - /* fall-through */ default: - flags = PIPE_BUFFER_USAGE_CPU_READ | PIPE_BUFFER_USAGE_CPU_WRITE; + flags = PIPE_TRANSFER_READ_WRITE; break; } - obj->Pointer = st_cond_flush_pipe_buffer_map(st_context(ctx), - st_obj->buffer, - flags); + obj->Pointer = pipe_buffer_map(st_context(ctx)->pipe, + st_obj->buffer, + flags, + &st_obj->transfer); + if (obj->Pointer) { obj->Offset = 0; obj->Length = obj->Size; @@ -255,25 +266,25 @@ st_bufferobj_map_range(GLcontext *ctx, GLenum target, { struct pipe_context *pipe = st_context(ctx)->pipe; struct st_buffer_object *st_obj = st_buffer_object(obj); - uint flags = 0x0; + enum pipe_transfer_usage flags = 0x0; if (access & GL_MAP_WRITE_BIT) - flags |= PIPE_BUFFER_USAGE_CPU_WRITE; + flags |= PIPE_TRANSFER_WRITE; if (access & GL_MAP_READ_BIT) - flags |= PIPE_BUFFER_USAGE_CPU_READ; + flags |= PIPE_TRANSFER_READ; if (access & GL_MAP_FLUSH_EXPLICIT_BIT) - flags |= PIPE_BUFFER_USAGE_FLUSH_EXPLICIT; + flags |= PIPE_TRANSFER_FLUSH_EXPLICIT; if (access & GL_MAP_UNSYNCHRONIZED_BIT) - flags |= PIPE_BUFFER_USAGE_UNSYNCHRONIZED; + flags |= PIPE_TRANSFER_UNSYNCHRONIZED; /* ... other flags ... */ if (access & MESA_MAP_NOWAIT_BIT) - flags |= PIPE_BUFFER_USAGE_DONTBLOCK; + flags |= PIPE_TRANSFER_DONTBLOCK; assert(offset >= 0); assert(length >= 0); @@ -288,7 +299,11 @@ st_bufferobj_map_range(GLcontext *ctx, GLenum target, obj->Pointer = &st_bufferobj_zero_length_range; } else { - obj->Pointer = pipe_buffer_map_range(pipe->screen, st_obj->buffer, offset, length, flags); + obj->Pointer = pipe_buffer_map_range(pipe, + st_obj->buffer, + offset, length, + flags, + &st_obj->transfer); if (obj->Pointer) { obj->Pointer = (ubyte *) obj->Pointer + offset; } @@ -316,11 +331,12 @@ st_bufferobj_flush_mapped_range(GLcontext *ctx, GLenum target, assert(offset >= 0); assert(length >= 0); assert(offset + length <= obj->Length); + assert(obj->Pointer); if (!length) return; - pipe_buffer_flush_mapped_range(pipe->screen, st_obj->buffer, + pipe_buffer_flush_mapped_range(pipe, st_obj->transfer, obj->Offset + offset, length); } @@ -334,9 +350,10 @@ 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); - if(obj->Length) - pipe_buffer_unmap(pipe->screen, st_obj->buffer); + if (obj->Length) + pipe_buffer_unmap(pipe, st_obj->buffer, st_obj->transfer); + st_obj->transfer = NULL; obj->Pointer = NULL; obj->Offset = 0; obj->Length = 0; @@ -357,6 +374,8 @@ st_copy_buffer_subdata(GLcontext *ctx, struct pipe_context *pipe = st_context(ctx)->pipe; struct st_buffer_object *srcObj = st_buffer_object(src); struct st_buffer_object *dstObj = st_buffer_object(dst); + struct pipe_transfer *src_transfer; + struct pipe_transfer *dst_transfer; ubyte *srcPtr, *dstPtr; if(!size) @@ -366,21 +385,36 @@ st_copy_buffer_subdata(GLcontext *ctx, assert(!src->Pointer); assert(!dst->Pointer); - srcPtr = (ubyte *) pipe_buffer_map_range(pipe->screen, + srcPtr = (ubyte *) pipe_buffer_map_range(pipe, srcObj->buffer, readOffset, size, - PIPE_BUFFER_USAGE_CPU_READ); + PIPE_TRANSFER_READ, + &src_transfer); - dstPtr = (ubyte *) pipe_buffer_map_range(pipe->screen, + dstPtr = (ubyte *) pipe_buffer_map_range(pipe, dstObj->buffer, writeOffset, size, - PIPE_BUFFER_USAGE_CPU_WRITE); + PIPE_TRANSFER_WRITE, + &dst_transfer); if (srcPtr && dstPtr) memcpy(dstPtr + writeOffset, srcPtr + readOffset, size); - pipe_buffer_unmap(pipe->screen, srcObj->buffer); - pipe_buffer_unmap(pipe->screen, dstObj->buffer); + pipe_buffer_unmap(pipe, srcObj->buffer, src_transfer); + pipe_buffer_unmap(pipe, dstObj->buffer, dst_transfer); +} + + +/* TODO: if buffer wasn't created with appropriate usage flags, need + * to recreate it now and copy contents -- or possibly create a + * gallium entrypoint to extend the usage flags and let the driver + * decide if a copy is necessary. + */ +void +st_bufferobj_validate_usage(struct st_context *st, + struct st_buffer_object *obj, + unsigned usage) +{ } diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.h b/src/mesa/state_tracker/st_cb_bufferobjects.h index fda6d05dd34..a27daac2bf0 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; +struct pipe_resource; /** * State_tracker vertex/pixel buffer object, derived from Mesa's @@ -39,7 +39,8 @@ struct pipe_buffer; struct st_buffer_object { struct gl_buffer_object Base; - struct pipe_buffer *buffer; + struct pipe_resource *buffer; /* GPU storage */ + struct pipe_transfer *transfer; /* In-progress map information */ }; @@ -52,6 +53,12 @@ st_buffer_object(struct gl_buffer_object *obj) extern void +st_bufferobj_validate_usage(struct st_context *st, + struct st_buffer_object *obj, + unsigned usage); + + +extern void st_init_bufferobject_functions(struct dd_function_table *functions); diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 9e66eed3634..736180ddc6c 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -43,20 +43,22 @@ #include "st_cb_clear.h" #include "st_cb_fbo.h" #include "st_program.h" -#include "st_public.h" #include "st_inlines.h" #include "pipe/p_context.h" -#include "util/u_inlines.h" #include "pipe/p_state.h" #include "pipe/p_defines.h" #include "util/u_format.h" +#include "util/u_inlines.h" #include "util/u_simple_shaders.h" #include "util/u_draw_quad.h" #include "cso_cache/cso_context.h" +/** + * Do per-context initialization for glClear. + */ void st_init_clear(struct st_context *st) { @@ -67,8 +69,7 @@ st_init_clear(struct st_context *st) st->clear.raster.gl_rasterization_rules = 1; /* fragment shader state: color pass-through program */ - st->clear.fs = - util_make_fragment_passthrough_shader(pipe); + st->clear.fs = util_make_fragment_passthrough_shader(pipe); /* vertex shader state: color/position pass-through */ { @@ -82,6 +83,9 @@ st_init_clear(struct st_context *st) } +/** + * Free per-context state for glClear. + */ void st_destroy_clear(struct st_context *st) { @@ -94,7 +98,7 @@ st_destroy_clear(struct st_context *st) st->clear.vs = NULL; } if (st->clear.vbuf) { - pipe_buffer_reference(&st->clear.vbuf, NULL); + pipe_resource_reference(&st->clear.vbuf, NULL); st->clear.vbuf = NULL; } } @@ -105,11 +109,10 @@ st_destroy_clear(struct st_context *st) * Coords are clip coords with y=0=bottom. */ static void -draw_quad(GLcontext *ctx, +draw_quad(struct st_context *st, float x0, float y0, float x1, float y1, GLfloat z, const GLfloat color[4]) { - struct st_context *st = ctx->st; struct pipe_context *pipe = st->pipe; /* XXX: Need to improve buffer_write to allow NO_WAIT (as well as @@ -126,12 +129,13 @@ draw_quad(GLcontext *ctx, GLuint i; if (st->clear.vbuf_slot >= max_slots) { - pipe_buffer_reference(&st->clear.vbuf, NULL); + pipe_resource_reference(&st->clear.vbuf, NULL); st->clear.vbuf_slot = 0; } if (!st->clear.vbuf) { - st->clear.vbuf = pipe_buffer_create(pipe->screen, 32, PIPE_BUFFER_USAGE_VERTEX, + st->clear.vbuf = pipe_buffer_create(pipe->screen, + PIPE_BIND_VERTEX_BUFFER, max_slots * sizeof(st->clear.vertices)); } @@ -160,7 +164,8 @@ draw_quad(GLcontext *ctx, /* put vertex data into vbuf */ st_no_flush_pipe_buffer_write_nooverlap(st, st->clear.vbuf, - st->clear.vbuf_slot * sizeof(st->clear.vertices), + st->clear.vbuf_slot + * sizeof(st->clear.vertices), sizeof(st->clear.vertices), st->clear.vertices); @@ -187,7 +192,7 @@ static void clear_with_quad(GLcontext *ctx, GLboolean color, GLboolean depth, GLboolean stencil) { - struct st_context *st = ctx->st; + struct st_context *st = st_context(ctx); const struct gl_framebuffer *fb = ctx->DrawBuffer; const GLfloat fb_width = (GLfloat) fb->Width; const GLfloat fb_height = (GLfloat) fb->Height; @@ -213,6 +218,7 @@ clear_with_quad(GLcontext *ctx, cso_save_clip(st->cso_context); cso_save_fragment_shader(st->cso_context); cso_save_vertex_shader(st->cso_context); + cso_save_vertex_elements(st->cso_context); /* blend state: RGBA masking */ { @@ -264,6 +270,8 @@ clear_with_quad(GLcontext *ctx, cso_set_depth_stencil_alpha(st->cso_context, &depth_stencil); } + cso_set_vertex_elements(st->cso_context, 2, st->velems_util_draw); + cso_set_rasterizer(st->cso_context, &st->clear.raster); /* viewport state: viewport matching window dims */ @@ -286,7 +294,8 @@ clear_with_quad(GLcontext *ctx, cso_set_vertex_shader_handle(st->cso_context, st->clear.vs); /* draw quad matching scissor rect (XXX verify coord round-off) */ - draw_quad(ctx, x0, y0, x1, y1, (GLfloat) ctx->Depth.Clear, ctx->Color.ClearColor); + draw_quad(st, x0, y0, x1, y1, + (GLfloat) ctx->Depth.Clear, ctx->Color.ClearColor); /* Restore pipe state */ cso_restore_blend(st->cso_context); @@ -297,6 +306,7 @@ clear_with_quad(GLcontext *ctx, cso_restore_clip(st->cso_context); cso_restore_fragment_shader(st->cso_context); cso_restore_vertex_shader(st->cso_context); + cso_restore_vertex_elements(st->cso_context); } @@ -311,18 +321,22 @@ check_clear_color_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb) ctx->Scissor.Y != 0 || ctx->Scissor.Width < rb->Width || ctx->Scissor.Height < rb->Height)) - return TRUE; + return GL_TRUE; if (!ctx->Color.ColorMask[0][0] || !ctx->Color.ColorMask[0][1] || !ctx->Color.ColorMask[0][2] || !ctx->Color.ColorMask[0][3]) - return TRUE; + return GL_TRUE; - return FALSE; + return GL_FALSE; } +/** + * Determine if we need to clear the combiend depth/stencil buffer by + * drawing a quad. + */ static INLINE GLboolean check_clear_depth_stencil_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb) { @@ -339,12 +353,12 @@ check_clear_depth_stencil_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb) ctx->Scissor.Y != 0 || ctx->Scissor.Width < rb->Width || ctx->Scissor.Height < rb->Height)) - return TRUE; + return GL_TRUE; if (maskStencil) - return TRUE; + return GL_TRUE; - return FALSE; + return GL_FALSE; } @@ -362,13 +376,12 @@ check_clear_depth_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb) ctx->Scissor.Y != 0 || ctx->Scissor.Width < rb->Width || ctx->Scissor.Height < rb->Height)) - return TRUE; + return GL_TRUE; - if (isDS && - ctx->DrawBuffer->Visual.stencilBits > 0) - return TRUE; + if (isDS && ctx->DrawBuffer->Visual.stencilBits > 0) + return GL_TRUE; - return FALSE; + return GL_FALSE; } @@ -389,35 +402,38 @@ check_clear_stencil_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb) rb->Format == MESA_FORMAT_S8_Z24); if (maskStencil) - return TRUE; + return GL_TRUE; if (ctx->Scissor.Enabled && (ctx->Scissor.X != 0 || ctx->Scissor.Y != 0 || ctx->Scissor.Width < rb->Width || ctx->Scissor.Height < rb->Height)) - return TRUE; + return GL_TRUE; /* This is correct, but it is necessary to look at the depth clear * value held in the surface when it comes time to issue the clear, * rather than taking depth and stencil clear values from the * current state. */ - if (isDS && - ctx->DrawBuffer->Visual.depthBits > 0) - return TRUE; + if (isDS && ctx->DrawBuffer->Visual.depthBits > 0) + return GL_TRUE; - return FALSE; + return GL_FALSE; } -void st_flush_clear( struct st_context *st ) +/** + * Called when we need to flush. + */ +void +st_flush_clear(struct st_context *st) { /* Release vertex buffer to avoid synchronous rendering if we were * to map it in the next frame. */ - pipe_buffer_reference(&st->clear.vbuf, NULL); + pipe_resource_reference(&st->clear.vbuf, NULL); st->clear.vbuf_slot = 0; } @@ -425,20 +441,19 @@ void st_flush_clear( struct st_context *st ) /** * Called via ctx->Driver.Clear() - * XXX: doesn't pick up the differences between front/back/left/right - * clears. Need to sort that out... */ -static void st_clear(GLcontext *ctx, GLbitfield mask) +static void +st_Clear(GLcontext *ctx, GLbitfield mask) { static const GLbitfield BUFFER_BITS_DS = (BUFFER_BIT_DEPTH | BUFFER_BIT_STENCIL); - struct st_context *st = ctx->st; + struct st_context *st = st_context(ctx); struct gl_renderbuffer *depthRb = ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer; struct gl_renderbuffer *stencilRb = ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer; - GLbitfield quad_buffers = 0; - GLbitfield clear_buffers = 0; + GLbitfield quad_buffers = 0x0; + GLbitfield clear_buffers = 0x0; GLuint i; /* This makes sure the pipe has the latest scissor, etc values */ @@ -514,8 +529,8 @@ static void st_clear(GLcontext *ctx, GLbitfield mask) mask & BUFFER_BIT_DEPTH, mask & BUFFER_BIT_STENCIL); } else if (clear_buffers) - ctx->st->pipe->clear(ctx->st->pipe, clear_buffers, ctx->Color.ClearColor, - ctx->Depth.Clear, ctx->Stencil.Clear); + st->pipe->clear(st->pipe, clear_buffers, ctx->Color.ClearColor, + ctx->Depth.Clear, ctx->Stencil.Clear); if (mask & BUFFER_BIT_ACCUM) st_clear_accum_buffer(ctx, @@ -523,7 +538,8 @@ static void st_clear(GLcontext *ctx, GLbitfield mask) } -void st_init_clear_functions(struct dd_function_table *functions) +void +st_init_clear_functions(struct dd_function_table *functions) { - functions->Clear = st_clear; + functions->Clear = st_Clear; } diff --git a/src/mesa/state_tracker/st_cb_condrender.c b/src/mesa/state_tracker/st_cb_condrender.c index 8483b93bd85..b509d43b7c6 100644 --- a/src/mesa/state_tracker/st_cb_condrender.c +++ b/src/mesa/state_tracker/st_cb_condrender.c @@ -51,7 +51,7 @@ st_BeginConditionalRender(GLcontext *ctx, struct gl_query_object *q, GLenum mode) { struct st_query_object *stq = st_query_object(q); - struct pipe_context *pipe = ctx->st->pipe; + struct pipe_context *pipe = st_context(ctx)->pipe; uint m; switch (mode) { @@ -82,7 +82,7 @@ st_BeginConditionalRender(GLcontext *ctx, struct gl_query_object *q, static void st_EndConditionalRender(GLcontext *ctx, struct gl_query_object *q) { - struct pipe_context *pipe = ctx->st->pipe; + struct pipe_context *pipe = st_context(ctx)->pipe; (void) q; pipe->render_condition(pipe, NULL, 0); } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 98453321f86..e059002f157 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -59,7 +59,6 @@ #include "util/u_draw_quad.h" #include "util/u_format.h" #include "util/u_math.h" -#include "util/u_rect.h" #include "shader/prog_instruction.h" #include "cso_cache/cso_context.h" @@ -250,13 +249,13 @@ make_passthrough_vertex_shader(struct st_context *st, ureg_DECL_output( ureg, TGSI_SEMANTIC_POSITION, 0 ), ureg_DECL_vs_input( ureg, 0 )); - /* MOV result.texcoord0, vertex.texcoord0; */ + /* MOV result.texcoord0, vertex.attr[1]; */ ureg_MOV(ureg, ureg_DECL_output( ureg, TGSI_SEMANTIC_GENERIC, 0 ), ureg_DECL_vs_input( ureg, 1 )); if (passColor) { - /* MOV result.color0, vertex.color0; */ + /* MOV result.color0, vertex.attr[2]; */ ureg_MOV(ureg, ureg_DECL_output( ureg, TGSI_SEMANTIC_COLOR, 0 ), ureg_DECL_vs_input( ureg, 2 )); @@ -293,10 +292,55 @@ base_format(GLenum format) /** + * Create a temporary texture to hold an image of the given size. + * If width, height are not POT and the driver only handles POT textures, + * allocate the next larger size of texture that is POT. + */ +static struct pipe_resource * +alloc_texture(struct st_context *st, GLsizei width, GLsizei height, + enum pipe_format texFormat) +{ + struct pipe_context *pipe = st->pipe; + struct pipe_screen *screen = pipe->screen; + struct pipe_resource *pt; + int ptw, pth; + + ptw = width; + pth = height; + + /* Need to use POT texture? */ + if (!screen->get_param(screen, PIPE_CAP_NPOT_TEXTURES)) { + int l2pt, maxSize; + + l2pt = util_logbase2(width); + if (1 << l2pt != width) { + ptw = 1 << (l2pt + 1); + } + + l2pt = util_logbase2(height); + if (1 << l2pt != height) { + pth = 1 << (l2pt + 1); + } + + /* Check against maximum texture size */ + maxSize = 1 << (pipe->screen->get_param(pipe->screen, + PIPE_CAP_MAX_TEXTURE_2D_LEVELS) - 1); + assert(ptw <= maxSize); + assert(pth <= maxSize); + } + + pt = st_texture_create(st, PIPE_TEXTURE_2D, texFormat, 0, + ptw, pth, 1, PIPE_BIND_SAMPLER_VIEW); + + return pt; +} + + +/** * Make texture containing an image for glDrawPixels image. * If 'pixels' is NULL, leave the texture image data undefined. */ -static struct pipe_texture * +static struct pipe_resource * make_texture(struct st_context *st, GLsizei width, GLsizei height, GLenum format, GLenum type, const struct gl_pixelstore_attrib *unpack, @@ -304,13 +348,11 @@ make_texture(struct st_context *st, { GLcontext *ctx = st->ctx; struct pipe_context *pipe = st->pipe; - struct pipe_screen *screen = pipe->screen; gl_format mformat; - struct pipe_texture *pt; + struct pipe_resource *pt; enum pipe_format pipeFormat; GLuint cpp; GLenum baseFormat; - int ptw, pth; baseFormat = base_format(format); @@ -325,29 +367,8 @@ make_texture(struct st_context *st, if (!pixels) return NULL; - /* Need to use POT texture? */ - ptw = width; - pth = height; - if (!screen->get_param(screen, PIPE_CAP_NPOT_TEXTURES)) { - int l2pt, maxSize; - - l2pt = util_logbase2(width); - if (1<<l2pt != width) { - ptw = 1<<(l2pt+1); - } - l2pt = util_logbase2(height); - if (1<<l2pt != height) { - pth = 1<<(l2pt+1); - } - - /* Check against maximum texture size */ - maxSize = 1 << (pipe->screen->get_param(pipe->screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS) - 1); - assert(ptw <= maxSize); - assert(pth <= maxSize); - } - - pt = st_texture_create(st, PIPE_TEXTURE_2D, pipeFormat, 0, ptw, pth, 1, - PIPE_TEXTURE_USAGE_SAMPLER); + /* alloc temporary texture */ + pt = alloc_texture(st, width, height, pipeFormat); if (!pt) { _mesa_unmap_pbo_source(ctx, unpack); return NULL; @@ -368,7 +389,7 @@ make_texture(struct st_context *st, width, height); /* map texture transfer */ - dest = screen->transfer_map(screen, transfer); + dest = pipe_transfer_map(pipe, transfer); /* Put image into texture transfer. @@ -388,8 +409,8 @@ make_texture(struct st_context *st, unpack); /* unmap */ - screen->transfer_unmap(screen, transfer); - screen->tex_transfer_destroy(transfer); + pipe_transfer_unmap(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); assert(success); @@ -405,7 +426,7 @@ make_texture(struct st_context *st, /** * Draw quad with texcoords and optional color. - * Coords are window coords with y=0=bottom. + * Coords are gallium window coords with y=0=top. * \param color may be null * \param invertTex if true, flip texcoords vertically */ @@ -430,7 +451,7 @@ draw_quad(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z, const GLfloat sLeft = 0.0f, sRight = maxXcoord; const GLfloat tTop = invertTex ? maxYcoord : 0.0f; const GLfloat tBot = invertTex ? 0.0f : maxYcoord; - GLuint tex, i; + GLuint i; /* upper-left */ verts[0][0][0] = clip_x0; /* v[0].attr[0].x */ @@ -448,32 +469,31 @@ draw_quad(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z, verts[3][0][0] = clip_x0; verts[3][0][1] = clip_y1; - tex = color ? 2 : 1; - verts[0][tex][0] = sLeft; /* v[0].attr[tex].s */ - verts[0][tex][1] = tTop; /* v[0].attr[tex].t */ - verts[1][tex][0] = sRight; - verts[1][tex][1] = tTop; - verts[2][tex][0] = sRight; - verts[2][tex][1] = tBot; - verts[3][tex][0] = sLeft; - verts[3][tex][1] = tBot; + verts[0][1][0] = sLeft; /* v[0].attr[1].S */ + verts[0][1][1] = tTop; /* v[0].attr[1].T */ + verts[1][1][0] = sRight; + verts[1][1][1] = tTop; + verts[2][1][0] = sRight; + verts[2][1][1] = tBot; + verts[3][1][0] = sLeft; + verts[3][1][1] = tBot; /* same for all verts: */ if (color) { for (i = 0; i < 4; i++) { - verts[i][0][2] = z; /*Z*/ - verts[i][0][3] = 1.0f; /*W*/ - verts[i][1][0] = color[0]; - verts[i][1][1] = color[1]; - verts[i][1][2] = color[2]; - verts[i][1][3] = color[3]; - verts[i][2][2] = 0.0f; /*R*/ - verts[i][2][3] = 1.0f; /*Q*/ + verts[i][0][2] = z; /* v[i].attr[0].z */ + verts[i][0][3] = 1.0f; /* v[i].attr[0].w */ + verts[i][2][0] = color[0]; /* v[i].attr[2].r */ + verts[i][2][1] = color[1]; /* v[i].attr[2].g */ + verts[i][2][2] = color[2]; /* v[i].attr[2].b */ + verts[i][2][3] = color[3]; /* v[i].attr[2].a */ + verts[i][1][2] = 0.0f; /* v[i].attr[1].R */ + verts[i][1][3] = 1.0f; /* v[i].attr[1].Q */ } } else { for (i = 0; i < 4; i++) { - verts[i][0][2] = z; /*Z*/ + verts[i][0][2] = z; /*Z*/ verts[i][0][3] = 1.0f; /*W*/ verts[i][1][2] = 0.0f; /*R*/ verts[i][1][3] = 1.0f; /*Q*/ @@ -482,10 +502,11 @@ draw_quad(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z, } { - struct pipe_buffer *buf; + struct pipe_resource *buf; /* allocate/load buffer object with vertex data */ - buf = pipe_buffer_create(pipe->screen, 32, PIPE_BUFFER_USAGE_VERTEX, + buf = pipe_buffer_create(pipe->screen, + PIPE_BIND_VERTEX_BUFFER, sizeof(verts)); st_no_flush_pipe_buffer_write(st, buf, 0, sizeof(verts), verts); @@ -493,7 +514,7 @@ draw_quad(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z, PIPE_PRIM_QUADS, 4, /* verts */ 3); /* attribs/vert */ - pipe_buffer_reference(&buf, NULL); + pipe_resource_reference(&buf, NULL); } } @@ -503,7 +524,7 @@ static void draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, GLsizei width, GLsizei height, GLfloat zoomX, GLfloat zoomY, - struct pipe_texture *pt, + struct pipe_sampler_view *sv, void *driver_vp, void *driver_fp, const GLfloat *color, @@ -526,9 +547,10 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, cso_save_rasterizer(cso); cso_save_viewport(cso); cso_save_samplers(cso); - cso_save_sampler_textures(cso); + cso_save_fragment_sampler_views(cso); cso_save_fragment_shader(cso); cso_save_vertex_shader(cso); + cso_save_vertex_elements(cso); /* rasterizer state: just scissor */ { @@ -581,21 +603,28 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, cso_set_viewport(cso, &vp); } + cso_set_vertex_elements(cso, 3, st->velems_util_draw); + /* texture state: */ if (st->pixel_xfer.pixelmap_enabled) { - struct pipe_texture *textures[2]; - textures[0] = pt; - textures[1] = st->pixel_xfer.pixelmap_texture; - pipe->set_fragment_sampler_textures(pipe, 2, textures); + struct pipe_sampler_view *sampler_views[2]; + sampler_views[0] = sv; + sampler_views[1] = st->pixel_xfer.pixelmap_sampler_view; + cso_set_fragment_sampler_views(cso, 2, sampler_views); } else { - pipe->set_fragment_sampler_textures(pipe, 1, &pt); + cso_set_fragment_sampler_views(cso, 1, &sv); } - /* Compute window coords (y=0=bottom) with pixel zoom. + /* Compute Gallium window coords (y=0=top) with pixel zoom. * Recall that these coords are transformed by the current * vertex shader and viewport transformation. */ + if (st_fb_orientation(ctx->DrawBuffer) == Y_0_BOTTOM) { + y = ctx->DrawBuffer->Height - (int) (y + height * ctx->Pixel.ZoomY); + invertTex = !invertTex; + } + x0 = (GLfloat) x; x1 = x + width * ctx->Pixel.ZoomX; y0 = (GLfloat) y; @@ -605,16 +634,17 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, z = z * 2.0 - 1.0; draw_quad(ctx, x0, y0, z, x1, y1, color, invertTex, - (GLfloat) width / pt->width0, - (GLfloat) height / pt->height0); + (GLfloat) width / sv->texture->width0, + (GLfloat) height / sv->texture->height0); /* restore state */ cso_restore_rasterizer(cso); cso_restore_viewport(cso); cso_restore_samplers(cso); - cso_restore_sampler_textures(cso); + cso_restore_fragment_sampler_views(cso); cso_restore_fragment_shader(cso); cso_restore_vertex_shader(cso); + cso_restore_vertex_elements(cso); } @@ -626,7 +656,6 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, { struct st_context *st = st_context(ctx); struct pipe_context *pipe = st->pipe; - struct pipe_screen *screen = pipe->screen; struct st_renderbuffer *strb; enum pipe_transfer_usage usage; struct pipe_transfer *pt; @@ -660,7 +689,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, usage, x, y, width, height); - stmap = screen->transfer_map(screen, pt); + stmap = pipe_transfer_map(pipe, pt); pixels = _mesa_map_pbo_source(ctx, &clippedUnpack, pixels); assert(pixels); @@ -705,15 +734,15 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, } /* now pack the stencil (and Z) values in the dest format */ - switch (pt->texture->format) { - case PIPE_FORMAT_S8_UNORM: + switch (pt->resource->format) { + case PIPE_FORMAT_S8_USCALED: { ubyte *dest = stmap + spanY * pt->stride + spanX; assert(usage == PIPE_TRANSFER_WRITE); memcpy(dest, sValues, spanWidth); } break; - case PIPE_FORMAT_Z24S8_UNORM: + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: if (format == GL_DEPTH_STENCIL) { uint *dest = (uint *) (stmap + spanY * pt->stride + spanX*4); GLint k; @@ -731,7 +760,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, } } break; - case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: if (format == GL_DEPTH_STENCIL) { uint *dest = (uint *) (stmap + spanY * pt->stride + spanX*4); GLint k; @@ -760,8 +789,8 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, _mesa_unmap_pbo_source(ctx, &clippedUnpack); /* unmap the stencil buffer */ - screen->transfer_unmap(screen, pt); - screen->tex_transfer_destroy(pt); + pipe_transfer_unmap(pipe, pt); + pipe->transfer_destroy(pipe, pt); } @@ -802,16 +831,21 @@ st_DrawPixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, /* draw with textured quad */ { - struct pipe_texture *pt + struct pipe_resource *pt = make_texture(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, - pt, - driver_vp, - driver_fp, - color, GL_FALSE); - pipe_texture_reference(&pt, NULL); + struct pipe_sampler_view *sv = st_create_texture_sampler_view(st->pipe, pt); + + if (sv) { + draw_textured_quad(ctx, x, y, ctx->Current.RasterPos[2], + width, height, ctx->Pixel.ZoomX, ctx->Pixel.ZoomY, + sv, + driver_vp, + driver_fp, + color, GL_FALSE); + pipe_sampler_view_reference(&sv, NULL); + } + pipe_resource_reference(&pt, NULL); } } } @@ -824,7 +858,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_context *pipe = st_context(ctx)->pipe; enum pipe_transfer_usage usage; struct pipe_transfer *ptDraw; ubyte *drawMap; @@ -856,11 +890,11 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, usage, dstx, dsty, width, height); - assert(util_format_get_blockwidth(ptDraw->texture->format) == 1); - assert(util_format_get_blockheight(ptDraw->texture->format) == 1); + assert(util_format_get_blockwidth(ptDraw->resource->format) == 1); + assert(util_format_get_blockheight(ptDraw->resource->format) == 1); /* map the stencil buffer */ - drawMap = screen->transfer_map(screen, ptDraw); + drawMap = pipe_transfer_map(pipe, ptDraw); /* draw */ /* XXX PixelZoom not handled yet */ @@ -878,8 +912,8 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, dst = drawMap + y * ptDraw->stride; src = buffer + i * width; - switch (ptDraw->texture->format) { - case PIPE_FORMAT_Z24S8_UNORM: + switch (ptDraw->resource->format) { + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: { uint *dst4 = (uint *) dst; int j; @@ -890,7 +924,7 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, } } break; - case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: { uint *dst4 = (uint *) dst; int j; @@ -901,7 +935,7 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, } } break; - case PIPE_FORMAT_S8_UNORM: + case PIPE_FORMAT_S8_USCALED: assert(usage == PIPE_TRANSFER_WRITE); memcpy(dst, src, width); break; @@ -913,8 +947,8 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, free(buffer); /* unmap the stencil buffer */ - screen->transfer_unmap(screen, ptDraw); - screen->tex_transfer_destroy(ptDraw); + pipe_transfer_unmap(pipe, ptDraw); + pipe->transfer_destroy(pipe, ptDraw); } @@ -928,43 +962,18 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, struct pipe_screen *screen = pipe->screen; struct st_renderbuffer *rbRead; void *driver_vp, *driver_fp; - struct pipe_texture *pt; + struct pipe_resource *pt; + struct pipe_sampler_view *sv; GLfloat *color; enum pipe_format srcFormat, texFormat; - int ptw, pth; + GLboolean invertTex = GL_FALSE; + GLint readX, readY, readW, readH; + struct gl_pixelstore_attrib pack = ctx->DefaultPacking; pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); st_validate_state(st); - if (srcx < 0) { - width -= -srcx; - dstx += -srcx; - srcx = 0; - } - - if (srcy < 0) { - height -= -srcy; - dsty += -srcy; - srcy = 0; - } - - if (dstx < 0) { - width -= -dstx; - srcx += -dstx; - dstx = 0; - } - - if (dsty < 0) { - height -= -dsty; - srcy += -dsty; - dsty = 0; - } - - if (width < 0 || height < 0) - return; - - if (type == GL_STENCIL) { /* can't use texturing to do stencil */ copy_stencil_pixels(ctx, srcx, srcy, width, height, dstx, dsty); @@ -988,7 +997,7 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, srcFormat = rbRead->texture->format; if (screen->is_format_supported(screen, srcFormat, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_SAMPLER, 0)) { + PIPE_BIND_SAMPLER_VIEW, 0)) { texFormat = srcFormat; } else { @@ -996,77 +1005,70 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, if (type == GL_DEPTH) { texFormat = st_choose_format(screen, GL_DEPTH_COMPONENT, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_DEPTH_STENCIL); - assert(texFormat != PIPE_FORMAT_NONE); /* XXX no depth texture formats??? */ + PIPE_BIND_DEPTH_STENCIL); + assert(texFormat != PIPE_FORMAT_NONE); } else { /* default color format */ texFormat = st_choose_format(screen, GL_RGBA, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_SAMPLER); + PIPE_BIND_SAMPLER_VIEW); assert(texFormat != PIPE_FORMAT_NONE); } } - if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) { - srcy = ctx->DrawBuffer->Height - srcy - height; - - if (srcy < 0) { - height -= -srcy; - srcy = 0; - } - - if (height < 0) - return; + /* Invert src region if needed */ + if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) { + srcy = ctx->ReadBuffer->Height - srcy - height; + invertTex = !invertTex; } - /* Need to use POT texture? */ - ptw = width; - pth = height; - if (!screen->get_param(screen, PIPE_CAP_NPOT_TEXTURES)) { - int l2pt, maxSize; - - l2pt = util_logbase2(width); - if (1<<l2pt != width) { - ptw = 1<<(l2pt+1); - } - l2pt = util_logbase2(height); - if (1<<l2pt != height) { - pth = 1<<(l2pt+1); - } - - /* Check against maximum texture size */ - maxSize = 1 << (pipe->screen->get_param(pipe->screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS) - 1); - assert(ptw <= maxSize); - assert(pth <= maxSize); - } - - pt = st_texture_create(st, PIPE_TEXTURE_2D, texFormat, 0, - ptw, pth, 1, - PIPE_TEXTURE_USAGE_SAMPLER); + /* Clip the read region against the src buffer bounds. + * We'll still allocate a temporary buffer/texture for the original + * src region size but we'll only read the region which is on-screen. + * This may mean that we draw garbage pixels into the dest region, but + * that's expected. + */ + readX = srcx; + readY = srcy; + readW = width; + readH = height; + _mesa_clip_readpixels(ctx, &readX, &readY, &readW, &readH, &pack); + readW = MAX2(0, readW); + readH = MAX2(0, readH); + + /* alloc temporary texture */ + pt = alloc_texture(st, width, height, texFormat); if (!pt) return; + sv = st_create_texture_sampler_view(st->pipe, pt); + if (!sv) { + pipe_resource_reference(&pt, NULL); + return; + } + /* Make temporary texture which is a copy of the src region. + */ 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); + PIPE_BIND_BLIT_SOURCE); struct pipe_surface *psTex = screen->get_tex_surface(screen, pt, 0, 0, 0, - PIPE_BUFFER_USAGE_GPU_WRITE ); - if (pipe->surface_copy) { - pipe->surface_copy(pipe, - psTex, /* dest */ - 0, 0, /* destx/y */ - psRead, - srcx, srcy, width, height); - } else { - util_surface_copy(pipe, FALSE, - psTex, - 0, 0, - psRead, - srcx, srcy, width, height); + PIPE_BIND_RENDER_TARGET | + PIPE_BIND_BLIT_DESTINATION); + pipe->surface_copy(pipe, + psTex, /* dest surf */ + pack.SkipPixels, pack.SkipRows, /* dest pos */ + psRead, /* src surf */ + readX, readY, readW, readH); /* src region */ + + if (0) { + /* debug */ + debug_dump_surface(pipe, "copypixsrcsurf", psRead); + debug_dump_surface(pipe, "copypixtemptex", psTex); } + pipe_surface_reference(&psRead, NULL); pipe_surface_reference(&psTex, NULL); } @@ -1074,8 +1076,8 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, /* CPU-based fallback/conversion */ struct pipe_transfer *ptRead = st_cond_flush_get_tex_transfer(st, rbRead->texture, 0, 0, 0, - PIPE_TRANSFER_READ, srcx, srcy, width, - height); + PIPE_TRANSFER_READ, + readX, readY, readW, readH); struct pipe_transfer *ptTex; enum pipe_transfer_usage transfer_usage; @@ -1090,36 +1092,40 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, ptTex = st_cond_flush_get_tex_transfer(st, pt, 0, 0, 0, transfer_usage, 0, 0, width, height); + /* copy image from ptRead surface to ptTex surface */ if (type == GL_COLOR) { /* alternate path using get/put_tile() */ GLfloat *buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - - pipe_get_tile_rgba(ptRead, 0, 0, width, height, buf); - pipe_put_tile_rgba(ptTex, 0, 0, width, height, buf); - + pipe_get_tile_rgba(pipe, ptRead, readX, readY, readW, readH, buf); + pipe_put_tile_rgba(pipe, ptTex, pack.SkipPixels, pack.SkipRows, + readW, readH, buf); free(buf); } else { /* GL_DEPTH */ GLuint *buf = (GLuint *) malloc(width * height * sizeof(GLuint)); - pipe_get_tile_z(ptRead, 0, 0, width, height, buf); - pipe_put_tile_z(ptTex, 0, 0, width, height, buf); + pipe_get_tile_z(pipe, ptRead, readX, readY, readW, readH, buf); + pipe_put_tile_z(pipe, ptTex, pack.SkipPixels, pack.SkipRows, + readW, readH, buf); free(buf); } - screen->tex_transfer_destroy(ptRead); - screen->tex_transfer_destroy(ptTex); + pipe->transfer_destroy(pipe, ptRead); + pipe->transfer_destroy(pipe, ptTex); } - /* draw textured quad */ + /* OK, the texture 'pt' contains the src image/pixels. Now draw a + * textured quad with that texture. + */ draw_textured_quad(ctx, dstx, dsty, ctx->Current.RasterPos[2], width, height, ctx->Pixel.ZoomX, ctx->Pixel.ZoomY, - pt, + sv, driver_vp, driver_fp, - color, GL_TRUE); + color, invertTex); - pipe_texture_reference(&pt, NULL); + pipe_resource_reference(&pt, NULL); + pipe_sampler_view_reference(&sv, NULL); } diff --git a/src/mesa/state_tracker/st_cb_eglimage.c b/src/mesa/state_tracker/st_cb_eglimage.c new file mode 100644 index 00000000000..0fa1848e232 --- /dev/null +++ b/src/mesa/state_tracker/st_cb_eglimage.c @@ -0,0 +1,160 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * 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, sublicense, + * 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 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 NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS 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: + * Chia-I Wu <[email protected]> + */ + +#include "main/texobj.h" +#include "main/texfetch.h" +#include "main/teximage.h" +#include "util/u_inlines.h" +#include "util/u_format.h" +#include "st_cb_eglimage.h" +#include "st_cb_fbo.h" +#include "st_texture.h" +#include "st_format.h" +#include "st_manager.h" + +#if FEATURE_OES_EGL_image + +/** + * Return the base format just like _mesa_base_fbo_format does. + */ +static GLenum +st_pipe_format_to_base_format(enum pipe_format format) +{ + GLenum base_format; + + if (util_format_is_depth_or_stencil(format)) { + if (util_format_is_depth_and_stencil(format)) { + base_format = GL_DEPTH_STENCIL; + } + else { + if (format == PIPE_FORMAT_S8_USCALED) + base_format = GL_STENCIL_INDEX; + else + base_format = GL_DEPTH_COMPONENT; + } + } + else { + /* is this enough? */ + if (util_format_has_alpha(format)) + base_format = GL_RGBA; + else + base_format = GL_RGB; + } + + return base_format; +} + +static void +st_egl_image_target_renderbuffer_storage(GLcontext *ctx, + struct gl_renderbuffer *rb, + GLeglImageOES image_handle) +{ + struct st_context *st = st_context(ctx); + struct st_renderbuffer *strb = st_renderbuffer(rb); + struct pipe_surface *ps; + unsigned usage; + + usage = PIPE_BIND_RENDER_TARGET | PIPE_BIND_BLIT_SOURCE | PIPE_BIND_BLIT_DESTINATION; + ps = st_manager_get_egl_image_surface(st, (void *) image_handle, usage); + if (ps) { + strb->Base.Width = ps->width; + strb->Base.Height = ps->height; + strb->Base.Format = st_pipe_format_to_mesa_format(ps->format); + strb->Base.DataType = st_format_datatype(ps->format); + strb->Base._BaseFormat = st_pipe_format_to_base_format(ps->format); + strb->Base.InternalFormat = strb->Base._BaseFormat; + + pipe_surface_reference(&strb->surface, ps); + pipe_resource_reference(&strb->texture, ps->texture); + + pipe_surface_reference(&ps, NULL); + } +} + +static void +st_bind_surface(GLcontext *ctx, GLenum target, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage, + struct pipe_surface *ps) +{ + struct st_texture_object *stObj; + struct st_texture_image *stImage; + GLenum internalFormat; + + /* map pipe format to base format */ + if (util_format_get_component_bits(ps->format, UTIL_FORMAT_COLORSPACE_RGB, 3) > 0) + internalFormat = GL_RGBA; + else + internalFormat = GL_RGB; + + stObj = st_texture_object(texObj); + stImage = st_texture_image(texImage); + + /* switch to surface based */ + if (!stObj->surface_based) { + _mesa_clear_texture_object(ctx, texObj); + stObj->surface_based = GL_TRUE; + } + + _mesa_init_teximage_fields(ctx, target, texImage, + ps->width, ps->height, 1, 0, internalFormat); + texImage->TexFormat = st_pipe_format_to_mesa_format(ps->format); + _mesa_set_fetch_functions(texImage, 2); + + /* FIXME create a non-default sampler view from the pipe_surface? */ + pipe_resource_reference(&stImage->pt, ps->texture); + + _mesa_dirty_texobj(ctx, texObj, GL_TRUE); +} + +static void +st_egl_image_target_texture_2d(GLcontext *ctx, GLenum target, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage, + GLeglImageOES image_handle) +{ + struct st_context *st = st_context(ctx); + struct pipe_surface *ps; + unsigned usage; + + usage = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_BLIT_DESTINATION | PIPE_BIND_BLIT_SOURCE; + ps = st_manager_get_egl_image_surface(st, (void *) image_handle, usage); + if (ps) { + st_bind_surface(ctx, target, texObj, texImage, ps); + pipe_surface_reference(&ps, NULL); + } +} + +void +st_init_eglimage_functions(struct dd_function_table *functions) +{ + functions->EGLImageTargetTexture2D = st_egl_image_target_texture_2d; + functions->EGLImageTargetRenderbufferStorage = st_egl_image_target_renderbuffer_storage; +} + +#endif /* FEATURE_OES_EGL_image */ diff --git a/src/mesa/state_tracker/st_cb_eglimage.h b/src/mesa/state_tracker/st_cb_eglimage.h new file mode 100644 index 00000000000..d6953e99f69 --- /dev/null +++ b/src/mesa/state_tracker/st_cb_eglimage.h @@ -0,0 +1,49 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * 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, sublicense, + * 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 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 NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS 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: + * Chia-I Wu <[email protected]> + */ + +#ifndef ST_CB_EGLIMAGE_H +#define ST_CB_EGLIMAGE_H + +#include "main/mtypes.h" +#include "main/dd.h" + +#if FEATURE_OES_EGL_image + +extern void +st_init_eglimage_functions(struct dd_function_table *functions); + +#else + +static INLINE void +st_init_eglimage_functions(struct dd_function_table *functions) +{ +} + +#endif + +#endif /* ST_CB_EGLIMAGE_H */ diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 8fded0c69fc..e5c956d561d 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -45,12 +45,12 @@ #include "pipe/p_screen.h" #include "st_context.h" #include "st_cb_fbo.h" +#include "st_cb_flush.h" #include "st_format.h" -#include "st_public.h" #include "st_texture.h" +#include "st_manager.h" #include "util/u_format.h" -#include "util/u_rect.h" #include "util/u_inlines.h" @@ -64,7 +64,8 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, GLenum internalFormat, GLuint width, GLuint height) { - struct pipe_screen *screen = ctx->st->pipe->screen; + struct st_context *st = st_context(ctx); + struct pipe_screen *screen = st->pipe->screen; struct st_renderbuffer *strb = st_renderbuffer(rb); enum pipe_format format; @@ -96,13 +97,13 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, return strb->data != NULL; } else { - struct pipe_texture template; - unsigned surface_usage; + struct pipe_resource template; /* Free the old surface and texture */ pipe_surface_reference( &strb->surface, NULL ); - pipe_texture_reference( &strb->texture, NULL ); + pipe_resource_reference( &strb->texture, NULL ); + pipe_sampler_view_reference(&strb->sampler_view, NULL); /* Setup new texture template. */ @@ -115,23 +116,14 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, template.last_level = 0; template.nr_samples = rb->NumSamples; if (util_format_is_depth_or_stencil(format)) { - template.tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL; + template.bind = PIPE_BIND_DEPTH_STENCIL; } else { - template.tex_usage = (PIPE_TEXTURE_USAGE_DISPLAY_TARGET | - PIPE_TEXTURE_USAGE_RENDER_TARGET); + template.bind = (PIPE_BIND_DISPLAY_TARGET | + PIPE_BIND_RENDER_TARGET); } - /* Probably need dedicated flags for surface usage too: - */ - surface_usage = (PIPE_BUFFER_USAGE_GPU_READ | - PIPE_BUFFER_USAGE_GPU_WRITE); -#if 0 - PIPE_BUFFER_USAGE_CPU_READ | - PIPE_BUFFER_USAGE_CPU_WRITE); -#endif - - strb->texture = screen->texture_create(screen, &template); + strb->texture = screen->resource_create(screen, &template); if (!strb->texture) return FALSE; @@ -139,7 +131,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, strb->surface = screen->get_tex_surface(screen, strb->texture, 0, 0, 0, - surface_usage); + template.bind); if (strb->surface) { assert(strb->surface->texture); assert(strb->surface->format); @@ -161,7 +153,8 @@ 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); + pipe_resource_reference(&strb->texture, NULL); + pipe_sampler_view_reference(&strb->sampler_view, NULL); free(strb->data); free(strb); } @@ -238,8 +231,10 @@ st_new_renderbuffer_fb(enum pipe_format format, int samples, boolean sw) strb->software = sw; switch (format) { + case PIPE_FORMAT_R8G8B8A8_UNORM: case PIPE_FORMAT_B8G8R8A8_UNORM: case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_R8G8B8X8_UNORM: case PIPE_FORMAT_B8G8R8X8_UNORM: case PIPE_FORMAT_X8R8G8B8_UNORM: case PIPE_FORMAT_B5G5R5A1_UNORM: @@ -253,13 +248,13 @@ st_new_renderbuffer_fb(enum pipe_format format, int samples, boolean sw) case PIPE_FORMAT_Z32_UNORM: strb->Base.InternalFormat = GL_DEPTH_COMPONENT32; break; - case PIPE_FORMAT_Z24S8_UNORM: - case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: case PIPE_FORMAT_Z24X8_UNORM: case PIPE_FORMAT_X8Z24_UNORM: strb->Base.InternalFormat = GL_DEPTH24_STENCIL8_EXT; break; - case PIPE_FORMAT_S8_UNORM: + case PIPE_FORMAT_S8_USCALED: strb->Base.InternalFormat = GL_STENCIL_INDEX8_EXT; break; case PIPE_FORMAT_R16G16B16A16_SNORM: @@ -318,10 +313,12 @@ st_render_texture(GLcontext *ctx, struct gl_framebuffer *fb, struct gl_renderbuffer_attachment *att) { - struct pipe_screen *screen = ctx->st->pipe->screen; + struct st_context *st = st_context(ctx); + struct pipe_context *pipe = st->pipe; + struct pipe_screen *screen = pipe->screen; struct st_renderbuffer *strb; struct gl_renderbuffer *rb; - struct pipe_texture *pt = st_get_texobj_texture(att->Texture); + struct pipe_resource *pt = st_get_texobj_resource(att->Texture); struct st_texture_object *stObj; const struct gl_texture_image *texImage; GLint pt_level; @@ -364,10 +361,13 @@ st_render_texture(GLcontext *ctx, /*printf("***** pipe texture %d x %d\n", pt->width0, pt->height0);*/ - pipe_texture_reference( &strb->texture, pt ); + pipe_resource_reference( &strb->texture, pt ); pipe_surface_reference(&strb->surface, NULL); + pipe_sampler_view_reference(&strb->sampler_view, + st_get_texture_sampler_view(stObj, pipe)); + assert(strb->rtt_level <= strb->texture->last_level); /* new surface for rendering into the texture */ @@ -376,8 +376,9 @@ st_render_texture(GLcontext *ctx, strb->rtt_face, strb->rtt_level, strb->rtt_slice, - PIPE_BUFFER_USAGE_GPU_READ | - PIPE_BUFFER_USAGE_GPU_WRITE); + PIPE_BIND_RENDER_TARGET); + + strb->format = pt->format; strb->Base.Format = st_pipe_format_to_mesa_format(pt->format); strb->Base.DataType = st_format_datatype(pt->format); @@ -403,15 +404,13 @@ static void st_finish_render_texture(GLcontext *ctx, struct gl_renderbuffer_attachment *att) { + struct st_context *st = st_context(ctx); struct st_renderbuffer *strb = st_renderbuffer(att->Renderbuffer); if (!strb) return; - st_flush( ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL ); - - if (strb->surface) - pipe_surface_reference( &strb->surface, NULL ); + st_flush(st, PIPE_FLUSH_RENDER_CACHE, NULL); strb->rtt = NULL; @@ -419,31 +418,25 @@ st_finish_render_texture(GLcontext *ctx, printf("FINISH RENDER TO TEXTURE surf=%p\n", strb->surface); */ - _mesa_reference_renderbuffer(&att->Renderbuffer, NULL); - /* restore previous framebuffer state */ st_invalidate_state(ctx, _NEW_BUFFERS); } /** - * Validate a renderbuffer attachment for a particular usage. + * Validate a renderbuffer attachment for a particular set of bindings. */ - static GLboolean st_validate_attachment(struct pipe_screen *screen, const struct gl_renderbuffer_attachment *att, - GLuint usage) + unsigned bindings) { - const struct st_texture_object *stObj = - st_texture_object(att->Texture); + const struct st_texture_object *stObj = st_texture_object(att->Texture); - /** - * Only validate texture attachments for now, since + /* Only validate texture attachments for now, since * st_renderbuffer_alloc_storage makes sure that * the format is supported. */ - if (att->Type != GL_TEXTURE) return GL_TRUE; @@ -451,10 +444,10 @@ st_validate_attachment(struct pipe_screen *screen, return GL_FALSE; return screen->is_format_supported(screen, stObj->pt->format, - PIPE_TEXTURE_2D, - usage, 0); + PIPE_TEXTURE_2D, bindings, 0); } + /** * Check that the framebuffer configuration is valid in terms of what * the driver can support. @@ -464,7 +457,8 @@ st_validate_attachment(struct pipe_screen *screen, static void st_validate_framebuffer(GLcontext *ctx, struct gl_framebuffer *fb) { - struct pipe_screen *screen = ctx->st->pipe->screen; + struct st_context *st = st_context(ctx); + struct pipe_screen *screen = st->pipe->screen; const struct gl_renderbuffer *depthRb = fb->Attachment[BUFFER_DEPTH].Renderbuffer; const struct gl_renderbuffer *stencilRb = @@ -478,20 +472,20 @@ st_validate_framebuffer(GLcontext *ctx, struct gl_framebuffer *fb) if (!st_validate_attachment(screen, &fb->Attachment[BUFFER_DEPTH], - PIPE_TEXTURE_USAGE_DEPTH_STENCIL)) { + PIPE_BIND_DEPTH_STENCIL)) { fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT; return; } if (!st_validate_attachment(screen, &fb->Attachment[BUFFER_STENCIL], - PIPE_TEXTURE_USAGE_DEPTH_STENCIL)) { + PIPE_BIND_DEPTH_STENCIL)) { fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT; return; } for (i = 0; i < ctx->Const.MaxColorAttachments; i++) { if (!st_validate_attachment(screen, &fb->Attachment[BUFFER_COLOR0 + i], - PIPE_TEXTURE_USAGE_RENDER_TARGET)) { + PIPE_BIND_RENDER_TARGET)) { fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT; return; } @@ -500,126 +494,23 @@ st_validate_framebuffer(GLcontext *ctx, struct gl_framebuffer *fb) /** - * Copy back color buffer to front color buffer. - */ -static void -copy_back_to_front(struct st_context *st, - struct gl_framebuffer *fb, - gl_buffer_index frontIndex, - gl_buffer_index backIndex) - -{ - struct st_framebuffer *stfb = (struct st_framebuffer *) fb; - struct pipe_surface *surf_front, *surf_back; - - (void) st_get_framebuffer_surface(stfb, frontIndex, &surf_front); - (void) st_get_framebuffer_surface(stfb, backIndex, &surf_back); - - if (surf_front && surf_back) { - if (st->pipe->surface_copy) { - st->pipe->surface_copy(st->pipe, - surf_front, 0, 0, /* dest */ - surf_back, 0, 0, /* src */ - fb->Width, fb->Height); - } else { - util_surface_copy(st->pipe, FALSE, - surf_front, 0, 0, - surf_back, 0, 0, - fb->Width, fb->Height); - } - } -} - - -/** - * Check if we're drawing into, or read from, a front color buffer. If the - * front buffer is missing, create it now. - * - * The back color buffer must exist since we'll use its format/samples info - * for creating the front buffer. - * - * \param frontIndex either BUFFER_FRONT_LEFT or BUFFER_FRONT_RIGHT - * \param backIndex either BUFFER_BACK_LEFT or BUFFER_BACK_RIGHT - */ -static void -check_create_front_buffer(GLcontext *ctx, struct gl_framebuffer *fb, - gl_buffer_index frontIndex, - gl_buffer_index backIndex) -{ - if (fb->Attachment[frontIndex].Renderbuffer == NULL) { - GLboolean create = GL_FALSE; - - /* check if drawing to or reading from front buffer */ - if (fb->_ColorReadBufferIndex == frontIndex) { - create = GL_TRUE; - } - else { - GLuint b; - for (b = 0; b < fb->_NumColorDrawBuffers; b++) { - if (fb->_ColorDrawBufferIndexes[b] == frontIndex) { - create = GL_TRUE; - break; - } - } - } - - if (create) { - struct st_renderbuffer *back; - struct gl_renderbuffer *front; - enum pipe_format colorFormat; - uint samples; - - if (0) - _mesa_debug(ctx, "Allocate new front buffer\n"); - - /* get back renderbuffer info */ - back = st_renderbuffer(fb->Attachment[backIndex].Renderbuffer); - colorFormat = back->format; - samples = back->Base.NumSamples; - - /* create front renderbuffer */ - front = st_new_renderbuffer_fb(colorFormat, samples, FALSE); - _mesa_add_renderbuffer(fb, frontIndex, front); - - /* alloc texture/surface for new front buffer */ - front->AllocStorage(ctx, front, front->InternalFormat, - fb->Width, fb->Height); - - /* initialize the front color buffer contents by copying - * the back buffer. - */ - copy_back_to_front(ctx->st, fb, frontIndex, backIndex); - } - } -} - - -/** - * If front left/right color buffers are missing, create them now. - */ -static void -check_create_front_buffers(GLcontext *ctx, struct gl_framebuffer *fb) -{ - /* check if we need to create the front left buffer now */ - check_create_front_buffer(ctx, fb, BUFFER_FRONT_LEFT, BUFFER_BACK_LEFT); - - if (fb->Visual.stereoMode) { - check_create_front_buffer(ctx, fb, BUFFER_FRONT_RIGHT, BUFFER_BACK_RIGHT); - } - - st_invalidate_state(ctx, _NEW_BUFFERS); -} - - -/** * Called via glDrawBuffer. */ static void st_DrawBuffers(GLcontext *ctx, GLsizei count, const GLenum *buffers) { + struct st_context *st = st_context(ctx); + GLframebuffer *fb = ctx->DrawBuffer; + GLuint i; + (void) count; (void) buffers; - check_create_front_buffers(ctx, ctx->DrawBuffer); + + /* add the renderbuffers on demand */ + for (i = 0; i < fb->_NumColorDrawBuffers; i++) { + gl_buffer_index idx = fb->_ColorDrawBufferIndexes[i]; + st_manager_add_color_renderbuffer(st, fb, idx); + } } @@ -629,8 +520,13 @@ st_DrawBuffers(GLcontext *ctx, GLsizei count, const GLenum *buffers) static void st_ReadBuffer(GLcontext *ctx, GLenum buffer) { + struct st_context *st = st_context(ctx); + GLframebuffer *fb = ctx->ReadBuffer; + (void) buffer; - check_create_front_buffers(ctx, ctx->ReadBuffer); + + /* add the renderbuffer on demand */ + st_manager_add_color_renderbuffer(st, fb, fb->_ColorReadBufferIndex); } @@ -650,3 +546,14 @@ void st_init_fbo_functions(struct dd_function_table *functions) functions->DrawBuffers = st_DrawBuffers; functions->ReadBuffer = st_ReadBuffer; } + +struct pipe_sampler_view * +st_get_renderbuffer_sampler_view(struct st_renderbuffer *rb, + struct pipe_context *pipe) +{ + if (!rb->sampler_view) { + rb->sampler_view = st_create_texture_sampler_view(pipe, rb->texture); + } + + return rb->sampler_view; +} diff --git a/src/mesa/state_tracker/st_cb_fbo.h b/src/mesa/state_tracker/st_cb_fbo.h index bea6eb89c3e..beb26ab4da1 100644 --- a/src/mesa/state_tracker/st_cb_fbo.h +++ b/src/mesa/state_tracker/st_cb_fbo.h @@ -37,8 +37,9 @@ struct st_renderbuffer { struct gl_renderbuffer Base; - struct pipe_texture *texture; + struct pipe_resource *texture; struct pipe_surface *surface; /* temporary view into texture */ + struct pipe_sampler_view *sampler_view; enum pipe_format format; /** preferred format, or PIPE_FORMAT_NONE */ GLboolean defined; /**< defined contents? */ @@ -53,8 +54,9 @@ struct st_renderbuffer int rtt_level, rtt_face, rtt_slice; /** Render to texture state */ - struct pipe_texture *texture_save; + struct pipe_resource *texture_save; struct pipe_surface *surface_save; + struct pipe_sampler_view *sampler_view_save; }; @@ -71,5 +73,9 @@ st_new_renderbuffer_fb(enum pipe_format format, int samples, boolean sw); extern void st_init_fbo_functions(struct dd_function_table *functions); +extern struct pipe_sampler_view * +st_get_renderbuffer_sampler_view(struct st_renderbuffer *rb, + struct pipe_context *pipe); + #endif /* ST_CB_FBO_H */ diff --git a/src/mesa/state_tracker/st_cb_feedback.c b/src/mesa/state_tracker/st_cb_feedback.c index 37b1fb55f4a..c85d3da84a2 100644 --- a/src/mesa/state_tracker/st_cb_feedback.c +++ b/src/mesa/state_tracker/st_cb_feedback.c @@ -80,7 +80,7 @@ static void feedback_vertex(GLcontext *ctx, const struct draw_context *draw, const struct vertex_header *v) { - const struct st_context *st = ctx->st; + const struct st_context *st = st_context(ctx); GLfloat win[4]; const GLfloat *color, *texcoord; GLuint slot; @@ -271,7 +271,7 @@ draw_glselect_stage(GLcontext *ctx, struct draw_context *draw) static void st_RenderMode(GLcontext *ctx, GLenum newMode ) { - struct st_context *st = ctx->st; + struct st_context *st = st_context(ctx); struct draw_context *draw = st->draw; if (newMode == GL_RENDER) { diff --git a/src/mesa/state_tracker/st_cb_flush.c b/src/mesa/state_tracker/st_cb_flush.c index 1329f807bc9..8c9959f9544 100644 --- a/src/mesa/state_tracker/st_cb_flush.c +++ b/src/mesa/state_tracker/st_cb_flush.c @@ -39,7 +39,7 @@ #include "st_cb_flush.h" #include "st_cb_clear.h" #include "st_cb_fbo.h" -#include "st_public.h" +#include "st_manager.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_screen.h" @@ -51,15 +51,10 @@ static INLINE GLboolean is_front_buffer_dirty(struct st_context *st) { - if (st->frontbuffer_status == FRONT_STATUS_DIRTY) { - return GL_TRUE; - } - else { - GLframebuffer *fb = st->ctx->DrawBuffer; - struct st_renderbuffer *strb - = st_renderbuffer(fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer); - return strb && strb->defined; - } + GLframebuffer *fb = st->ctx->DrawBuffer; + struct st_renderbuffer *strb + = st_renderbuffer(fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer); + return strb && strb->defined; } @@ -74,16 +69,9 @@ display_front_buffer(struct st_context *st) = st_renderbuffer(fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer); if (strb) { - struct pipe_surface *front_surf = strb->surface; - /* Hook for copying "fake" frontbuffer if necessary: */ - st->pipe->screen->flush_frontbuffer( st->pipe->screen, front_surf, - st->pipe->priv ); - - /* - st->frontbuffer_status = FRONT_STATUS_UNDEFINED; - */ + st_manager_flush_frontbuffer(st); } } @@ -127,7 +115,7 @@ void st_finish( struct st_context *st ) */ static void st_glFlush(GLcontext *ctx) { - struct st_context *st = ctx->st; + struct st_context *st = st_context(ctx); /* Don't call st_finish() here. It is not the state tracker's * responsibilty to inject sleeps in the hope of avoiding buffer @@ -147,7 +135,7 @@ static void st_glFlush(GLcontext *ctx) */ static void st_glFinish(GLcontext *ctx) { - struct st_context *st = ctx->st; + struct st_context *st = st_context(ctx); st_finish(st); diff --git a/src/mesa/state_tracker/st_cb_flush.h b/src/mesa/state_tracker/st_cb_flush.h index c26f7792259..7fca0176a30 100644 --- a/src/mesa/state_tracker/st_cb_flush.h +++ b/src/mesa/state_tracker/st_cb_flush.h @@ -33,6 +33,13 @@ extern void st_init_flush_functions(struct dd_function_table *functions); +extern void +st_flush(struct st_context *st, uint pipeFlushFlags, + struct pipe_fence_handle **fence); + +extern void +st_finish(struct st_context *st); + #endif /* ST_CB_FLUSH_H */ diff --git a/src/mesa/state_tracker/st_cb_queryobj.c b/src/mesa/state_tracker/st_cb_queryobj.c index c66729b1244..1896663932c 100644 --- a/src/mesa/state_tracker/st_cb_queryobj.c +++ b/src/mesa/state_tracker/st_cb_queryobj.c @@ -61,7 +61,7 @@ st_NewQueryObject(GLcontext *ctx, GLuint id) static void st_DeleteQuery(GLcontext *ctx, struct gl_query_object *q) { - struct pipe_context *pipe = ctx->st->pipe; + struct pipe_context *pipe = st_context(ctx)->pipe; struct st_query_object *stq = st_query_object(q); if (stq->pq) { @@ -76,7 +76,7 @@ st_DeleteQuery(GLcontext *ctx, struct gl_query_object *q) static void st_BeginQuery(GLcontext *ctx, struct gl_query_object *q) { - struct pipe_context *pipe = ctx->st->pipe; + struct pipe_context *pipe = st_context(ctx)->pipe; struct st_query_object *stq = st_query_object(q); switch (q->Target) { @@ -96,7 +96,7 @@ st_BeginQuery(GLcontext *ctx, struct gl_query_object *q) static void st_EndQuery(GLcontext *ctx, struct gl_query_object *q) { - struct pipe_context *pipe = ctx->st->pipe; + struct pipe_context *pipe = st_context(ctx)->pipe; struct st_query_object *stq = st_query_object(q); pipe->end_query(pipe, stq->pq); @@ -106,7 +106,7 @@ st_EndQuery(GLcontext *ctx, struct gl_query_object *q) static void st_WaitQuery(GLcontext *ctx, struct gl_query_object *q) { - struct pipe_context *pipe = ctx->st->pipe; + struct pipe_context *pipe = st_context(ctx)->pipe; struct st_query_object *stq = st_query_object(q); /* this function should only be called if we don't have a ready result */ @@ -128,7 +128,7 @@ st_WaitQuery(GLcontext *ctx, struct gl_query_object *q) static void st_CheckQuery(GLcontext *ctx, struct gl_query_object *q) { - struct pipe_context *pipe = ctx->st->pipe; + struct pipe_context *pipe = st_context(ctx)->pipe; struct st_query_object *stq = st_query_object(q); assert(!q->Ready); /* we should not get called if Ready is TRUE */ q->Ready = pipe->get_query_result(pipe, stq->pq, FALSE, &q->Result); diff --git a/src/mesa/state_tracker/st_cb_rasterpos.c b/src/mesa/state_tracker/st_cb_rasterpos.c index 752b411b5fc..843f3200278 100644 --- a/src/mesa/state_tracker/st_cb_rasterpos.c +++ b/src/mesa/state_tracker/st_cb_rasterpos.c @@ -133,7 +133,7 @@ rastpos_point(struct draw_stage *stage, struct prim_header *prim) { struct rastpos_stage *rs = rastpos_stage(stage); GLcontext *ctx = rs->ctx; - struct st_context *st = ctx->st; + struct st_context *st = st_context(ctx); const GLfloat height = (GLfloat) ctx->DrawBuffer->Height; const GLuint *outputMapping = st->vertex_result_to_slot; const GLfloat *pos; @@ -221,7 +221,7 @@ new_draw_rastpos_stage(GLcontext *ctx, struct draw_context *draw) static void st_RasterPos(GLcontext *ctx, const GLfloat v[4]) { - struct st_context *st = ctx->st; + struct st_context *st = st_context(ctx); struct draw_context *draw = st->draw; struct rastpos_stage *rs; @@ -239,7 +239,7 @@ st_RasterPos(GLcontext *ctx, const GLfloat v[4]) draw_set_rasterize_stage(st->draw, st->rastpos_stage); /* make sure everything's up to date */ - st_validate_state(ctx->st); + st_validate_state(st); /* This will get set only if rastpos_point(), above, gets called */ ctx->Current.RasterPosValid = GL_FALSE; diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c index 952d9ce9156..69950ac44bb 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -45,9 +45,9 @@ #include "st_debug.h" #include "st_context.h" +#include "st_atom.h" #include "st_cb_readpixels.h" #include "st_cb_fbo.h" -#include "st_public.h" #include "st_texture.h" #include "st_inlines.h" @@ -63,7 +63,7 @@ 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 pipe_context *pipe = st_context(ctx)->pipe; struct st_renderbuffer *strb = st_renderbuffer(fb->_StencilBuffer); struct pipe_transfer *pt; ubyte *stmap; @@ -81,7 +81,7 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, width, height); /* map the stencil buffer */ - stmap = screen->transfer_map(screen, pt); + stmap = pipe_transfer_map(pipe, pt); /* width should never be > MAX_WIDTH since we did clipping earlier */ ASSERT(width <= MAX_WIDTH); @@ -101,14 +101,14 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, } /* get stencil (and Z) values */ - switch (pt->texture->format) { - case PIPE_FORMAT_S8_UNORM: + switch (pt->resource->format) { + case PIPE_FORMAT_S8_USCALED: { const ubyte *src = stmap + srcY * pt->stride; memcpy(sValues, src, width); } break; - case PIPE_FORMAT_Z24S8_UNORM: + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: if (format == GL_DEPTH_STENCIL) { const uint *src = (uint *) (stmap + srcY * pt->stride); const GLfloat scale = 1.0f / (0xffffff); @@ -126,7 +126,7 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, } } break; - case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: if (format == GL_DEPTH_STENCIL) { const uint *src = (uint *) (stmap + srcY * pt->stride); const GLfloat scale = 1.0f / (0xffffff); @@ -161,15 +161,14 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, } /* unmap the stencil buffer */ - screen->transfer_unmap(screen, pt); - screen->tex_transfer_destroy(pt); + pipe_transfer_unmap(pipe, pt); + pipe->transfer_destroy(pipe, pt); } /** * Return renderbuffer to use for reading color pixels for glRead/CopyPixel * commands. - * Special care is needed for the front buffer. */ struct st_renderbuffer * st_get_color_read_renderbuffer(GLcontext *ctx) @@ -177,18 +176,6 @@ st_get_color_read_renderbuffer(GLcontext *ctx) struct gl_framebuffer *fb = ctx->ReadBuffer; struct st_renderbuffer *strb = st_renderbuffer(fb->_ColorReadBuffer); - struct st_renderbuffer *front = - st_renderbuffer(fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer); - - if (strb == front - && ctx->st->frontbuffer_status == FRONT_STATUS_COPY_OF_BACK) { - /* reading from front color buffer, which is a logical copy of the - * back color buffer. - */ - struct st_renderbuffer *back = - st_renderbuffer(fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer); - strb = back; - } return strb; } @@ -233,14 +220,14 @@ st_fast_readpixels(GLcontext *ctx, struct st_renderbuffer *strb, /*printf("st_fast_readpixels combo %d\n", (GLint) combo);*/ { - struct pipe_context *pipe = ctx->st->pipe; - struct pipe_screen *screen = pipe->screen; + struct pipe_context *pipe = st_context(ctx)->pipe; struct pipe_transfer *trans; const GLubyte *map; GLubyte *dst; GLint row, col, dy, dstStride; if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) { + /* convert GL Y to Gallium Y */ y = strb->texture->height0 - y - height; } @@ -252,17 +239,22 @@ st_fast_readpixels(GLcontext *ctx, struct st_renderbuffer *strb, return GL_FALSE; } - map = screen->transfer_map(screen, trans); + map = pipe_transfer_map(pipe, trans); if (!map) { - screen->tex_transfer_destroy(trans); + pipe->transfer_destroy(pipe, trans); return GL_FALSE; } + /* We always write to the user/dest buffer from low addr to high addr + * but the read order depends on renderbuffer orientation + */ if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) { + /* read source rows from bottom to top */ y = height - 1; dy = -1; } else { + /* read source rows from top to bottom */ y = 0; dy = 1; } @@ -311,8 +303,8 @@ st_fast_readpixels(GLcontext *ctx, struct st_renderbuffer *strb, ; /* nothing */ } - screen->transfer_unmap(screen, trans); - screen->tex_transfer_destroy(trans); + pipe_transfer_unmap(pipe, trans); + pipe->transfer_destroy(pipe, trans); } return GL_TRUE; @@ -330,8 +322,8 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, const struct gl_pixelstore_attrib *pack, GLvoid *dest) { - struct pipe_context *pipe = ctx->st->pipe; - struct pipe_screen *screen = pipe->screen; + struct st_context *st = st_context(ctx); + struct pipe_context *pipe = st->pipe; GLfloat temp[MAX_WIDTH][4]; const GLbitfield transferOps = ctx->_ImageTransferState; GLsizei i, j; @@ -346,6 +338,8 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, /* XXX convolution not done yet */ assert((transferOps & IMAGE_CONVOLUTION_BIT) == 0); + st_validate_state(st); + /* 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 transfer is totally outside the window bounds */ @@ -356,7 +350,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, if (!dest) return; - st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); + st_flush(st, PIPE_FLUSH_RENDER_CACHE, NULL); if (format == GL_STENCIL_INDEX || format == GL_DEPTH_STENCIL) { @@ -396,6 +390,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, } if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) { + /* convert GL Y to Gallium Y */ y = strb->Base.Height - y - height; } @@ -429,14 +424,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 (trans->texture->format == PIPE_FORMAT_Z24S8_UNORM || - trans->texture->format == PIPE_FORMAT_Z24X8_UNORM) { + if (trans->resource->format == PIPE_FORMAT_Z24_UNORM_S8_USCALED || + trans->resource->format == PIPE_FORMAT_Z24X8_UNORM) { if (format == GL_DEPTH_COMPONENT) { for (i = 0; i < height; i++) { GLuint ztemp[MAX_WIDTH]; GLfloat zfloat[MAX_WIDTH]; const double scale = 1.0 / ((1 << 24) - 1); - pipe_get_tile_raw(trans, 0, y, width, 1, ztemp, 0); + pipe_get_tile_raw(pipe, trans, 0, y, width, 1, ztemp, 0); y += yStep; for (j = 0; j < width; j++) { zfloat[j] = (float) (scale * (ztemp[j] & 0xffffff)); @@ -451,7 +446,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, assert(format == GL_DEPTH_STENCIL_EXT); for (i = 0; i < height; i++) { GLuint *zshort = (GLuint *)dst; - pipe_get_tile_raw(trans, 0, y, width, 1, dst, 0); + pipe_get_tile_raw(pipe, trans, 0, y, width, 1, dst, 0); y += yStep; /* Reverse into 24/8 */ for (j = 0; j < width; j++) { @@ -461,14 +456,14 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, } } } - else if (trans->texture->format == PIPE_FORMAT_S8Z24_UNORM || - trans->texture->format == PIPE_FORMAT_X8Z24_UNORM) { + else if (trans->resource->format == PIPE_FORMAT_S8_USCALED_Z24_UNORM || + trans->resource->format == PIPE_FORMAT_X8Z24_UNORM) { if (format == GL_DEPTH_COMPONENT) { for (i = 0; i < height; i++) { GLuint ztemp[MAX_WIDTH]; GLfloat zfloat[MAX_WIDTH]; const double scale = 1.0 / ((1 << 24) - 1); - pipe_get_tile_raw(trans, 0, y, width, 1, ztemp, 0); + pipe_get_tile_raw(pipe, trans, 0, y, width, 1, ztemp, 0); y += yStep; for (j = 0; j < width; j++) { zfloat[j] = (float) (scale * ((ztemp[j] >> 8) & 0xffffff)); @@ -482,18 +477,18 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, /* XXX: unreachable code -- should be before st_read_stencil_pixels */ assert(format == GL_DEPTH_STENCIL_EXT); for (i = 0; i < height; i++) { - pipe_get_tile_raw(trans, 0, y, width, 1, dst, 0); + pipe_get_tile_raw(pipe, trans, 0, y, width, 1, dst, 0); y += yStep; dst += dstStride; } } } - else if (trans->texture->format == PIPE_FORMAT_Z16_UNORM) { + else if (trans->resource->format == PIPE_FORMAT_Z16_UNORM) { for (i = 0; i < height; i++) { GLushort ztemp[MAX_WIDTH]; GLfloat zfloat[MAX_WIDTH]; const double scale = 1.0 / 0xffff; - pipe_get_tile_raw(trans, 0, y, width, 1, ztemp, 0); + pipe_get_tile_raw(pipe, trans, 0, y, width, 1, ztemp, 0); y += yStep; for (j = 0; j < width; j++) { zfloat[j] = (float) (scale * ztemp[j]); @@ -503,12 +498,12 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, dst += dstStride; } } - else if (trans->texture->format == PIPE_FORMAT_Z32_UNORM) { + else if (trans->resource->format == PIPE_FORMAT_Z32_UNORM) { for (i = 0; i < height; i++) { GLuint ztemp[MAX_WIDTH]; GLfloat zfloat[MAX_WIDTH]; const double scale = 1.0 / 0xffffffff; - pipe_get_tile_raw(trans, 0, y, width, 1, ztemp, 0); + pipe_get_tile_raw(pipe, trans, 0, y, width, 1, ztemp, 0); y += yStep; for (j = 0; j < width; j++) { zfloat[j] = (float) (scale * ztemp[j]); @@ -522,7 +517,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(trans, 0, y, width, 1, df); + pipe_get_tile_rgba(pipe, trans, 0, y, width, 1, df); y += yStep; df += dfStride; if (!dfStride) { @@ -534,7 +529,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, } } - screen->tex_transfer_destroy(trans); + pipe->transfer_destroy(pipe, trans); _mesa_unmap_pbo_dest(ctx, &clippedPacking); } diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index c849132e74c..3457214ca4c 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -49,7 +49,6 @@ #include "state_tracker/st_cb_fbo.h" #include "state_tracker/st_cb_texture.h" #include "state_tracker/st_format.h" -#include "state_tracker/st_public.h" #include "state_tracker/st_texture.h" #include "state_tracker/st_gen_mipmap.h" #include "state_tracker/st_inlines.h" @@ -63,6 +62,7 @@ #include "util/u_blit.h" #include "util/u_format.h" #include "util/u_surface.h" +#include "util/u_sampler.h" #include "util/u_math.h" @@ -120,10 +120,21 @@ static void st_DeleteTextureObject(GLcontext *ctx, struct gl_texture_object *texObj) { + struct st_context *st = st_context(ctx); struct st_texture_object *stObj = st_texture_object(texObj); if (stObj->pt) - pipe_texture_reference(&stObj->pt, NULL); - + pipe_resource_reference(&stObj->pt, NULL); + if (stObj->sampler_view) { + if (stObj->sampler_view->context != st->pipe) { + /* Take "ownership" of this texture sampler view by setting + * its context pointer to this context. This avoids potential + * crashes when the texture object is shared among contexts + * and the original/owner context has already been destroyed. + */ + stObj->sampler_view->context = st->pipe; + } + pipe_sampler_view_reference(&stObj->sampler_view, NULL); + } _mesa_delete_texture_object(ctx, texObj); } @@ -137,7 +148,7 @@ st_FreeTextureImageData(GLcontext * ctx, struct gl_texture_image *texImage) DBG("%s\n", __FUNCTION__); if (stImage->pt) { - pipe_texture_reference(&stImage->pt, NULL); + pipe_resource_reference(&stImage->pt, NULL); } if (texImage->Data) { @@ -198,22 +209,30 @@ do_memcpy(void *dest, const void *src, size_t n) /** - * Return default texture usage bitmask for the given texture format. + * Return default texture resource binding bitmask for the given format. */ static GLuint -default_usage(enum pipe_format fmt) +default_bindings(struct st_context *st, enum pipe_format format) { - GLuint usage = PIPE_TEXTURE_USAGE_SAMPLER; - if (util_format_is_depth_or_stencil(fmt)) - usage |= PIPE_TEXTURE_USAGE_DEPTH_STENCIL; + struct pipe_screen *screen = st->pipe->screen; + const unsigned target = PIPE_TEXTURE_2D; + const unsigned geom = 0x0; + unsigned bindings; + + if (util_format_is_depth_or_stencil(format)) + bindings = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_DEPTH_STENCIL; + else + bindings = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET; + + if (screen->is_format_supported(screen, format, target, bindings, geom)) + return bindings; else - usage |= PIPE_TEXTURE_USAGE_RENDER_TARGET; - return usage; + return PIPE_BIND_SAMPLER_VIEW; } /** - * Allocate a pipe_texture object for the given st_texture_object using + * Allocate a pipe_resource object for the given st_texture_object using * the given st_texture_image to guess the mipmap size/levels. * * [comments...] @@ -236,7 +255,7 @@ guess_and_alloc_texture(struct st_context *st, GLuint width = stImage->base.Width2; /* size w/out border */ GLuint height = stImage->base.Height2; GLuint depth = stImage->base.Depth2; - GLuint i, usage; + GLuint i, bindings; enum pipe_format fmt; DBG("%s\n", __FUNCTION__); @@ -301,7 +320,7 @@ guess_and_alloc_texture(struct st_context *st, fmt = st_mesa_format_to_pipe_format(stImage->base.TexFormat); - usage = default_usage(fmt); + bindings = default_bindings(st, fmt); stObj->pt = st_texture_create(st, gl_target_to_pipe(stObj->base.Target), @@ -310,7 +329,7 @@ guess_and_alloc_texture(struct st_context *st, width, height, depth, - usage); + bindings); DBG("%s - success\n", __FUNCTION__); } @@ -371,10 +390,14 @@ compress_with_blit(GLcontext * ctx, { const GLuint dstImageOffsets[1] = {0}; struct st_texture_image *stImage = st_texture_image(texImage); - struct pipe_screen *screen = ctx->st->pipe->screen; + struct st_context *st = st_context(ctx); + struct pipe_context *pipe = st->pipe; + struct pipe_screen *screen = pipe->screen; gl_format mesa_format; - struct pipe_texture templ; - struct pipe_texture *src_tex; + struct pipe_resource templ; + struct pipe_resource *src_tex; + struct pipe_sampler_view view_templ; + struct pipe_sampler_view *src_view; struct pipe_surface *dst_surface; struct pipe_transfer *tex_xfer; void *map; @@ -387,7 +410,7 @@ compress_with_blit(GLcontext * ctx, /* get destination surface (in the compressed texture) */ dst_surface = screen->get_tex_surface(screen, stImage->pt, stImage->face, stImage->level, 0, - PIPE_BUFFER_USAGE_GPU_WRITE); + PIPE_BIND_BLIT_DESTINATION); if (!dst_surface) { /* can't render into this format (or other problem) */ return GL_FALSE; @@ -409,8 +432,9 @@ compress_with_blit(GLcontext * ctx, templ.height0 = height; templ.depth0 = 1; templ.last_level = 0; - templ.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER; - src_tex = screen->texture_create(screen, &templ); + templ.usage = PIPE_USAGE_DEFAULT; + templ.bind = PIPE_BIND_SAMPLER_VIEW; + src_tex = screen->resource_create(screen, &templ); if (!src_tex) return GL_FALSE; @@ -421,7 +445,7 @@ compress_with_blit(GLcontext * ctx, 0, 0, 0, /* face, level are zero */ PIPE_TRANSFER_WRITE, 0, 0, width, height); /* x, y, w, h */ - map = screen->transfer_map(screen, tex_xfer); + map = pipe_transfer_map(pipe, tex_xfer); _mesa_texstore(ctx, 2, GL_RGBA, mesa_format, map, /* dest ptr */ @@ -433,12 +457,19 @@ compress_with_blit(GLcontext * ctx, pixels, /* source data */ unpack); /* source data packing */ - screen->transfer_unmap(screen, tex_xfer); - screen->tex_transfer_destroy(tex_xfer); + pipe_transfer_unmap(pipe, tex_xfer); + pipe->transfer_destroy(pipe, tex_xfer); + + /* Create temporary sampler view */ + u_sampler_view_default_template(&view_templ, + src_tex, + src_tex->format); + src_view = pipe->create_sampler_view(pipe, src_tex, &view_templ); + /* copy / compress image */ - util_blit_pixels_tex(ctx->st->blit, - src_tex, /* pipe_texture (src) */ + util_blit_pixels_tex(st->blit, + src_view, /* sampler view (src) */ 0, 0, /* src x0, y0 */ width, height, /* src x1, y1 */ dst_surface, /* pipe_surface (dst) */ @@ -449,7 +480,8 @@ compress_with_blit(GLcontext * ctx, PIPE_TEX_MIPFILTER_NEAREST); pipe_surface_reference(&dst_surface, NULL); - pipe_texture_reference(&src_tex, NULL); + pipe_resource_reference(&src_tex, NULL); + pipe_sampler_view_reference(&src_view, NULL); return GL_TRUE; } @@ -471,7 +503,8 @@ st_TexImage(GLcontext * ctx, struct gl_texture_image *texImage, GLsizei imageSize, GLboolean compressed_src) { - struct pipe_screen *screen = ctx->st->pipe->screen; + struct st_context *st = st_context(ctx); + struct pipe_screen *screen = st->pipe->screen; struct st_texture_object *stObj = st_texture_object(texObj); struct st_texture_image *stImage = st_texture_image(texImage); GLint postConvWidth, postConvHeight; @@ -536,7 +569,7 @@ st_TexImage(GLcontext * ctx, * Release any old malloced memory. */ if (stImage->pt) { - pipe_texture_reference(&stImage->pt, NULL); + pipe_resource_reference(&stImage->pt, NULL); assert(!texImage->Data); } else if (texImage->Data) { @@ -553,8 +586,9 @@ st_TexImage(GLcontext * ctx, !st_texture_match_image(stObj->pt, &stImage->base, stImage->face, stImage->level)) { DBG("release it\n"); - pipe_texture_reference(&stObj->pt, NULL); + pipe_resource_reference(&stObj->pt, NULL); assert(!stObj->pt); + pipe_sampler_view_reference(&stObj->sampler_view, NULL); stObj->teximage_realloc = FALSE; } } @@ -565,13 +599,13 @@ st_TexImage(GLcontext * ctx, } if (!stObj->pt) { - guess_and_alloc_texture(ctx->st, stObj, stImage); + guess_and_alloc_texture(st, stObj, stImage); if (!stObj->pt) { /* Probably out of memory. * Try flushing any pending rendering, then retry. */ - st_finish(ctx->st); - guess_and_alloc_texture(ctx->st, stObj, stImage); + st_finish(st); + guess_and_alloc_texture(st, stObj, stImage); if (!stObj->pt) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage"); return; @@ -585,7 +619,7 @@ st_TexImage(GLcontext * ctx, st_texture_match_image(stObj->pt, &stImage->base, stImage->face, stImage->level)) { - pipe_texture_reference(&stImage->pt, stObj->pt); + pipe_resource_reference(&stImage->pt, stObj->pt); assert(stImage->pt); } @@ -619,7 +653,7 @@ st_TexImage(GLcontext * ctx, screen->is_format_supported(screen, stImage->pt->format, stImage->pt->target, - PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) { + PIPE_BIND_RENDER_TARGET, 0)) { if (!pixels) goto done; @@ -636,7 +670,7 @@ st_TexImage(GLcontext * ctx, else transfer_usage = PIPE_TRANSFER_WRITE; - texImage->Data = st_texture_image_map(ctx->st, stImage, 0, + texImage->Data = st_texture_image_map(st, stImage, 0, transfer_usage, 0, 0, stImage->base.Width, stImage->base.Height); @@ -717,9 +751,9 @@ st_TexImage(GLcontext * ctx, if (stImage->pt && i + 1 < depth) { /* unmap this slice */ - st_texture_image_unmap(ctx->st, stImage); + st_texture_image_unmap(st, stImage); /* map next slice of 3D texture */ - texImage->Data = st_texture_image_map(ctx->st, stImage, i + 1, + texImage->Data = st_texture_image_map(st, stImage, i + 1, transfer_usage, 0, 0, stImage->base.Width, stImage->base.Height); @@ -732,7 +766,7 @@ done: _mesa_unmap_teximage_pbo(ctx, unpack); if (stImage->pt && texImage->Data) { - st_texture_image_unmap(ctx->st, stImage); + st_texture_image_unmap(st, stImage); texImage->Data = NULL; } } @@ -809,16 +843,24 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level, struct gl_texture_object *texObj, struct gl_texture_image *texImage) { - struct pipe_screen *screen = ctx->st->pipe->screen; + struct st_context *st = st_context(ctx); + struct pipe_context *pipe = st->pipe; + struct pipe_screen *screen = pipe->screen; struct st_texture_image *stImage = st_texture_image(texImage); + struct st_texture_object *stObj = st_texture_object(texObj); + struct pipe_sampler_view *src_view = + st_get_texture_sampler_view(stObj, pipe); const GLuint width = texImage->Width; const GLuint height = texImage->Height; struct pipe_surface *dst_surface; - struct pipe_texture *dst_texture; + struct pipe_resource *dst_texture; struct pipe_transfer *tex_xfer; + unsigned bind = (PIPE_BIND_BLIT_DESTINATION | + PIPE_BIND_RENDER_TARGET | /* util_blit may choose to render */ + PIPE_BIND_TRANSFER_READ); /* create temp / dest surface */ - if (!util_create_rgba_surface(screen, width, height, + if (!util_create_rgba_surface(screen, width, height, bind, &dst_texture, &dst_surface)) { _mesa_problem(ctx, "util_create_rgba_surface() failed " "in decompress_with_blit()"); @@ -826,8 +868,8 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level, } /* blit/render/decompress */ - util_blit_pixels_tex(ctx->st->blit, - stImage->pt, /* pipe_texture (src) */ + util_blit_pixels_tex(st->blit, + src_view, /* pipe_resource (src) */ 0, 0, /* src x0, y0 */ width, height, /* src x1, y1 */ dst_surface, /* pipe_surface (dst) */ @@ -848,7 +890,7 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level, if (st_equal_formats(stImage->pt->format, format, type)) { /* memcpy */ const uint bytesPerRow = width * util_format_get_blocksize(stImage->pt->format); - ubyte *map = screen->transfer_map(screen, tex_xfer); + ubyte *map = pipe_transfer_map(pipe, tex_xfer); GLuint row; for (row = 0; row < height; row++) { GLvoid *dest = _mesa_image_address2d(&ctx->Pack, pixels, width, @@ -856,7 +898,7 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level, memcpy(dest, map, bytesPerRow); map += tex_xfer->stride; } - screen->transfer_unmap(screen, tex_xfer); + pipe_transfer_unmap(pipe, tex_xfer); } else { /* format translation via floats */ @@ -871,7 +913,7 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level, debug_printf("%s: fallback format translation\n", __FUNCTION__); /* get float[4] rgba row from surface */ - pipe_get_tile_rgba(tex_xfer, 0, row, width, 1, rgba); + pipe_get_tile_rgba(pipe, tex_xfer, 0, row, width, 1, rgba); _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba, format, type, dest, &ctx->Pack, transferOps); @@ -880,6 +922,8 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level, _mesa_unmap_pbo_dest(ctx, &ctx->Pack); + pipe->transfer_destroy(pipe, tex_xfer); + /* destroy the temp / dest surface */ util_destroy_rgba_surface(dst_texture, dst_surface); } @@ -896,6 +940,7 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level, struct gl_texture_object *texObj, struct gl_texture_image *texImage, GLboolean compressed_dst) { + struct st_context *st = st_context(ctx); struct st_texture_image *stImage = st_texture_image(texImage); const GLuint dstImageStride = _mesa_image_image_stride(&ctx->Pack, texImage->Width, texImage->Height, @@ -904,7 +949,7 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level, GLubyte *dest; if (stImage->pt && - util_format_is_compressed(stImage->pt->format) && + util_format_is_s3tc(stImage->pt->format) && !compressed_dst) { /* Need to decompress the texture. * We'll do this by rendering a textured quad. @@ -922,14 +967,17 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level, */ unsigned face = _mesa_tex_target_to_face(target); - st_teximage_flush_before_map(ctx->st, stImage->pt, face, level, + st_teximage_flush_before_map(st, stImage->pt, face, level, PIPE_TRANSFER_READ); - texImage->Data = st_texture_image_map(ctx->st, stImage, 0, + texImage->Data = st_texture_image_map(st, stImage, 0, PIPE_TRANSFER_READ, 0, 0, stImage->base.Width, stImage->base.Height); - texImage->RowStride = stImage->transfer->stride / util_format_get_blocksize(stImage->pt->format); + /* compute stride in texels from stride in bytes */ + texImage->RowStride = stImage->transfer->stride + * util_format_get_blockwidth(stImage->pt->format) + / util_format_get_blocksize(stImage->pt->format); } else { /* Otherwise, the image should actually be stored in @@ -960,9 +1008,9 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level, if (stImage->pt && i + 1 < depth) { /* unmap this slice */ - st_texture_image_unmap(ctx->st, stImage); + st_texture_image_unmap(st, stImage); /* map next slice of 3D texture */ - texImage->Data = st_texture_image_map(ctx->st, stImage, i + 1, + texImage->Data = st_texture_image_map(st, stImage, i + 1, PIPE_TRANSFER_READ, 0, 0, stImage->base.Width, stImage->base.Height); @@ -974,7 +1022,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(st, stImage); texImage->Data = NULL; } } @@ -1012,7 +1060,8 @@ st_TexSubimage(GLcontext *ctx, GLint dims, GLenum target, GLint level, struct gl_texture_object *texObj, struct gl_texture_image *texImage) { - struct pipe_screen *screen = ctx->st->pipe->screen; + struct st_context *st = st_context(ctx); + struct pipe_screen *screen = st->pipe->screen; struct st_texture_image *stImage = st_texture_image(texImage); GLuint dstRowStride; const GLuint srcImageStride = @@ -1039,7 +1088,7 @@ st_TexSubimage(GLcontext *ctx, GLint dims, GLenum target, GLint level, screen->is_format_supported(screen, stImage->pt->format, stImage->pt->target, - PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) { + PIPE_BIND_RENDER_TARGET, 0)) { if (compress_with_blit(ctx, target, level, xoffset, yoffset, zoffset, width, height, depth, @@ -1060,9 +1109,9 @@ st_TexSubimage(GLcontext *ctx, GLint dims, GLenum target, GLint level, else transfer_usage = PIPE_TRANSFER_WRITE; - st_teximage_flush_before_map(ctx->st, stImage->pt, face, level, + st_teximage_flush_before_map(st, stImage->pt, face, level, transfer_usage); - texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset, + texImage->Data = st_texture_image_map(st, stImage, zoffset, transfer_usage, xoffset, yoffset, width, height); @@ -1090,9 +1139,9 @@ st_TexSubimage(GLcontext *ctx, GLint dims, GLenum target, GLint level, if (stImage->pt && i + 1 < depth) { /* unmap this slice */ - st_texture_image_unmap(ctx->st, stImage); + st_texture_image_unmap(st, stImage); /* map next slice of 3D texture */ - texImage->Data = st_texture_image_map(ctx->st, stImage, + texImage->Data = st_texture_image_map(st, stImage, zoffset + i + 1, transfer_usage, xoffset, yoffset, @@ -1105,7 +1154,7 @@ done: _mesa_unmap_teximage_pbo(ctx, packing); if (stImage->pt && texImage->Data) { - st_texture_image_unmap(ctx->st, stImage); + st_texture_image_unmap(st, stImage); texImage->Data = NULL; } } @@ -1176,18 +1225,20 @@ st_CompressedTexSubImage2D(GLcontext *ctx, GLenum target, GLint level, struct gl_texture_object *texObj, struct gl_texture_image *texImage) { + struct st_context *st = st_context(ctx); struct st_texture_image *stImage = st_texture_image(texImage); int srcBlockStride; int dstBlockStride; int y; - enum pipe_format pformat= stImage->pt->format; + enum pipe_format pformat; if (stImage->pt) { unsigned face = _mesa_tex_target_to_face(target); + pformat = stImage->pt->format; - st_teximage_flush_before_map(ctx->st, stImage->pt, face, level, + st_teximage_flush_before_map(st, stImage->pt, face, level, PIPE_TRANSFER_WRITE); - texImage->Data = st_texture_image_map(ctx->st, stImage, 0, + texImage->Data = st_texture_image_map(st, stImage, 0, PIPE_TRANSFER_WRITE, xoffset, yoffset, width, height); @@ -1219,7 +1270,7 @@ st_CompressedTexSubImage2D(GLcontext *ctx, GLenum target, GLint level, } if (stImage->pt) { - st_texture_image_unmap(ctx->st, stImage); + st_texture_image_unmap(st, stImage); texImage->Data = NULL; } } @@ -1255,8 +1306,8 @@ fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level, GLint srcX, GLint srcY, GLsizei width, GLsizei height) { - struct pipe_context *pipe = ctx->st->pipe; - struct pipe_screen *screen = pipe->screen; + struct st_context *st = st_context(ctx); + struct pipe_context *pipe = st->pipe; struct pipe_transfer *src_trans; GLvoid *texDest; enum pipe_transfer_usage transfer_usage; @@ -1284,10 +1335,10 @@ fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level, else transfer_usage = PIPE_TRANSFER_WRITE; - st_teximage_flush_before_map(ctx->st, stImage->pt, 0, 0, + st_teximage_flush_before_map(st, stImage->pt, 0, 0, transfer_usage); - texDest = st_texture_image_map(ctx->st, stImage, 0, transfer_usage, + texDest = st_texture_image_map(st, stImage, 0, transfer_usage, destX, destY, width, height); if (baseFormat == GL_DEPTH_COMPONENT || @@ -1309,11 +1360,11 @@ fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level, /* To avoid a large temp memory allocation, do copy row by row */ for (row = 0; row < height; row++, srcY += yStep) { uint data[MAX_WIDTH]; - pipe_get_tile_z(src_trans, 0, srcY, width, 1, data); + pipe_get_tile_z(pipe, src_trans, 0, srcY, width, 1, data); if (scaleOrBias) { _mesa_scale_and_bias_depth_uint(ctx, width, data); } - pipe_put_tile_z(stImage->transfer, 0, row, width, 1, data); + pipe_put_tile_z(pipe, stImage->transfer, 0, row, width, 1, data); } } else { @@ -1335,7 +1386,7 @@ fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level, /* XXX this usually involves a lot of int/float conversion. * try to avoid that someday. */ - pipe_get_tile_rgba(src_trans, 0, 0, width, height, tempSrc); + pipe_get_tile_rgba(pipe, src_trans, 0, 0, width, height, tempSrc); /* Store into texture memory. * Note that this does some special things such as pixel transfer @@ -1362,8 +1413,8 @@ fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level, free(tempSrc); } - st_texture_image_unmap(ctx->st, stImage); - screen->tex_transfer_destroy(src_trans); + st_texture_image_unmap(st, stImage); + pipe->transfer_destroy(pipe, src_trans); } @@ -1458,7 +1509,8 @@ st_copy_texsubimage(GLcontext *ctx, const GLenum texBaseFormat = texImage->_BaseFormat; struct gl_framebuffer *fb = ctx->ReadBuffer; struct st_renderbuffer *strb; - struct pipe_context *pipe = ctx->st->pipe; + struct st_context *st = st_context(ctx); + struct pipe_context *pipe = st->pipe; struct pipe_screen *screen = pipe->screen; enum pipe_format dest_format, src_format; GLboolean use_fallback = GL_TRUE; @@ -1468,11 +1520,11 @@ st_copy_texsubimage(GLcontext *ctx, GLboolean do_flip = (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP); /* any rendering in progress must flushed before we grab the fb image */ - st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); + st_flush(st, PIPE_FLUSH_RENDER_CACHE, NULL); /* make sure finalize_textures has been called? */ - if (0) st_validate_state(ctx->st); + if (0) st_validate_state(st); /* determine if copying depth or color data */ if (texBaseFormat == GL_DEPTH_COMPONENT || @@ -1539,8 +1591,7 @@ st_copy_texsubimage(GLcontext *ctx, if (ctx->_ImageTransferState == 0x0) { - if (pipe->surface_copy && - matching_base_formats && + if (matching_base_formats && src_format == dest_format && !do_flip) { @@ -1549,7 +1600,7 @@ st_copy_texsubimage(GLcontext *ctx, dest_surface = screen->get_tex_surface(screen, stImage->pt, stImage->face, stImage->level, destZ, - PIPE_BUFFER_USAGE_GPU_WRITE); + PIPE_BIND_BLIT_DESTINATION); /* for surface_copy(), y=0=top, always */ pipe->surface_copy(pipe, @@ -1568,11 +1619,11 @@ st_copy_texsubimage(GLcontext *ctx, texBaseFormat != GL_DEPTH_STENCIL && screen->is_format_supported(screen, src_format, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_SAMPLER, + PIPE_BIND_SAMPLER_VIEW, 0) && screen->is_format_supported(screen, dest_format, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_RENDER_TARGET, + PIPE_BIND_RENDER_TARGET, 0)) { /* draw textured quad to do the copy */ GLint srcY0, srcY1; @@ -1580,7 +1631,7 @@ st_copy_texsubimage(GLcontext *ctx, dest_surface = screen->get_tex_surface(screen, stImage->pt, stImage->face, stImage->level, destZ, - PIPE_BUFFER_USAGE_GPU_WRITE); + PIPE_BIND_BLIT_DESTINATION); if (do_flip) { srcY1 = strb->Base.Height - srcY - height; @@ -1590,8 +1641,9 @@ st_copy_texsubimage(GLcontext *ctx, srcY0 = srcY; srcY1 = srcY0 + height; } - util_blit_pixels_writemask(ctx->st->blit, + util_blit_pixels_writemask(st->blit, strb->surface, + st_get_renderbuffer_sampler_view(strb, pipe), srcX, srcY0, srcX + width, srcY1, dest_surface, @@ -1719,7 +1771,7 @@ copy_image_data_to_texture(struct st_context *st, stImage->pt, /* src texture */ stImage->face); - pipe_texture_reference(&stImage->pt, NULL); + pipe_resource_reference(&stImage->pt, NULL); } else if (stImage->base.Data) { /* More straightforward upload. @@ -1741,7 +1793,7 @@ copy_image_data_to_texture(struct st_context *st, stImage->base.Data = NULL; } - pipe_texture_reference(&stImage->pt, stObj->pt); + pipe_resource_reference(&stImage->pt, stObj->pt); } @@ -1756,6 +1808,7 @@ st_finalize_texture(GLcontext *ctx, struct gl_texture_object *tObj, GLboolean *needFlush) { + struct st_context *st = st_context(ctx); struct st_texture_object *stObj = st_texture_object(tObj); const GLuint nr_faces = (stObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1; GLuint blockSize, face; @@ -1787,7 +1840,8 @@ st_finalize_texture(GLcontext *ctx, if (firstImage->pt && firstImage->pt != stObj->pt && firstImage->pt->last_level >= stObj->lastLevel) { - pipe_texture_reference(&stObj->pt, firstImage->pt); + pipe_resource_reference(&stObj->pt, firstImage->pt); + pipe_sampler_view_reference(&stObj->sampler_view, NULL); } /* bytes per pixel block (blocks are usually 1x1) */ @@ -1806,8 +1860,9 @@ st_finalize_texture(GLcontext *ctx, stObj->pt->height0 != firstImage->base.Height2 || stObj->pt->depth0 != firstImage->base.Depth2) { - pipe_texture_reference(&stObj->pt, NULL); - ctx->st->dirty.st |= ST_NEW_FRAMEBUFFER; + pipe_resource_reference(&stObj->pt, NULL); + pipe_sampler_view_reference(&stObj->sampler_view, NULL); + st->dirty.st |= ST_NEW_FRAMEBUFFER; } } @@ -1816,16 +1871,16 @@ st_finalize_texture(GLcontext *ctx, if (!stObj->pt) { const enum pipe_format fmt = st_mesa_format_to_pipe_format(firstImage->base.TexFormat); - GLuint usage = default_usage(fmt); + GLuint bindings = default_bindings(st, fmt); - stObj->pt = st_texture_create(ctx->st, + stObj->pt = st_texture_create(st, gl_target_to_pipe(stObj->base.Target), fmt, stObj->lastLevel, firstImage->base.Width2, firstImage->base.Height2, firstImage->base.Depth2, - usage); + bindings); if (!stObj->pt) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage"); @@ -1844,7 +1899,7 @@ st_finalize_texture(GLcontext *ctx, /* Need to import images in main memory or held in other textures. */ if (stImage && stObj->pt != stImage->pt) { - copy_image_data_to_texture(ctx->st, stObj, level, stImage); + copy_image_data_to_texture(st, stObj, level, stImage); *needFlush = GL_TRUE; } } diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index de8beaf5e25..5fcb6b9dcf9 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -30,9 +30,8 @@ #include "vbo/vbo.h" #include "shader/shader_api.h" #include "glapi/glapi.h" -#include "st_public.h" -#include "st_debug.h" #include "st_context.h" +#include "st_debug.h" #include "st_cb_accum.h" #include "st_cb_bitmap.h" #include "st_cb_blit.h" @@ -46,6 +45,7 @@ #if FEATURE_OES_draw_texture #include "st_cb_drawtex.h" #endif +#include "st_cb_eglimage.h" #include "st_cb_fbo.h" #if FEATURE_feedback #include "st_cb_feedback.h" @@ -63,6 +63,7 @@ #include "st_program.h" #include "pipe/p_context.h" #include "util/u_inlines.h" +#include "util/u_rect.h" #include "draw/draw_context.h" #include "cso_cache/cso_context.h" @@ -97,6 +98,19 @@ st_get_msaa(void) } +/** Default method for pipe_context::surface_copy() */ +static void +st_surface_copy(struct pipe_context *pipe, + struct pipe_surface *dst, + unsigned dst_x, unsigned dst_y, + struct pipe_surface *src, + unsigned src_x, unsigned src_y, + unsigned w, unsigned h) +{ + util_surface_copy(pipe, FALSE, dst, dst_x, dst_y, src, src_x, src_y, w, h); +} + + static struct st_context * st_create_context_priv( GLcontext *ctx, struct pipe_context *pipe ) { @@ -115,7 +129,7 @@ st_create_context_priv( GLcontext *ctx, struct pipe_context *pipe ) _vbo_CreateContext(ctx); #if FEATURE_feedback || FEATURE_drawpix - st->draw = draw_create(); /* for selection/feedback */ + st->draw = draw_create(pipe); /* for selection/feedback */ /* Disable draw options that might convert points/lines to tris, etc. * as that would foul-up feedback/selection mode. @@ -141,6 +155,14 @@ st_create_context_priv( GLcontext *ctx, struct pipe_context *pipe ) for (i = 0; i < PIPE_MAX_SAMPLERS; i++) st->state.sampler_list[i] = &st->state.samplers[i]; + for (i = 0; i < 3; i++) { + memset(&st->velems_util_draw[i], 0, sizeof(struct pipe_vertex_element)); + st->velems_util_draw[i].src_offset = i * 4 * sizeof(float); + st->velems_util_draw[i].instance_divisor = 0; + st->velems_util_draw[i].vertex_buffer_index = 0; + st->velems_util_draw[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + } + /* we want all vertex data to be placed in buffer objects */ vbo_use_buffer_objects(ctx); @@ -158,6 +180,10 @@ st_create_context_priv( GLcontext *ctx, struct pipe_context *pipe ) st_init_limits(st); st_init_extensions(st); + /* plug in helper driver functions if needed */ + if (!pipe->surface_copy) + pipe->surface_copy = st_surface_copy; + return st; } @@ -207,13 +233,13 @@ static void st_destroy_context_priv( struct st_context *st ) st_destroy_drawtex(st); #endif - for (i = 0; i < Elements(st->state.sampler_texture); i++) { - pipe_texture_reference(&st->state.sampler_texture[i], NULL); + for (i = 0; i < Elements(st->state.sampler_views); i++) { + pipe_sampler_view_reference(&st->state.sampler_views[i], NULL); } for (i = 0; i < Elements(st->state.constants); i++) { if (st->state.constants[i]) { - pipe_buffer_reference(&st->state.constants[i], NULL); + pipe_resource_reference(&st->state.constants[i], NULL); } } @@ -261,52 +287,6 @@ void st_destroy_context( struct st_context *st ) } -GLboolean -st_make_current(struct st_context *st, - struct st_framebuffer *draw, - struct st_framebuffer *read) -{ - /* Call this periodically to detect when the user has begun using - * GL rendering from multiple threads. - */ - _glapi_check_multithread(); - - if (st) { - if (!_mesa_make_current(st->ctx, &draw->Base, &read->Base)) - return GL_FALSE; - - _mesa_check_init_viewport(st->ctx, draw->InitWidth, draw->InitHeight); - - return GL_TRUE; - } - else { - return _mesa_make_current(NULL, NULL, NULL); - } -} - -struct st_context *st_get_current(void) -{ - GET_CURRENT_CONTEXT(ctx); - - return (ctx == NULL) ? NULL : ctx->st; -} - -void st_copy_context_state(struct st_context *dst, - struct st_context *src, - uint mask) -{ - _mesa_copy_context(dst->ctx, src->ctx, mask); -} - - - -st_proc st_get_proc_address(const char *procname) -{ - return (st_proc) _glapi_get_proc_address(procname); -} - - - void st_init_driver_functions(struct dd_function_table *functions) { _mesa_init_glsl_driver_functions(functions); @@ -329,6 +309,8 @@ void st_init_driver_functions(struct dd_function_table *functions) st_init_drawtex_functions(functions); #endif + st_init_eglimage_functions(functions); + st_init_fbo_functions(functions); #if FEATURE_feedback st_init_feedback_functions(functions); diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 045c029c305..3637f6e75f0 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -31,6 +31,7 @@ #include "main/mtypes.h" #include "shader/prog_cache.h" #include "pipe/p_state.h" +#include "state_tracker/st_api.h" struct st_context; @@ -45,12 +46,6 @@ struct blit_state; struct bitmap_cache; -/** XXX we'd like to get rid of these */ -#define FRONT_STATUS_UNDEFINED 0 -#define FRONT_STATUS_DIRTY 1 -#define FRONT_STATUS_COPY_OF_BACK 2 - - #define ST_NEW_MESA 0x1 /* Mesa state has changed */ #define ST_NEW_FRAGMENT_PROGRAM 0x2 #define ST_NEW_VERTEX_PROGRAM 0x4 @@ -73,6 +68,8 @@ struct st_tracked_state { struct st_context { + struct st_context_iface iface; + GLcontext *ctx; struct pipe_context *pipe; @@ -92,9 +89,9 @@ struct st_context struct pipe_sampler_state samplers[PIPE_MAX_SAMPLERS]; struct pipe_sampler_state *sampler_list[PIPE_MAX_SAMPLERS]; struct pipe_clip_state clip; - struct pipe_buffer *constants[2]; + struct pipe_resource *constants[2]; struct pipe_framebuffer_state framebuffer; - struct pipe_texture *sampler_texture[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS]; struct pipe_scissor_state scissor; struct pipe_viewport_state viewport; @@ -113,8 +110,6 @@ struct st_context struct gl_fragment_program *fragment_program; } cb; - GLuint frontbuffer_status; /**< one of FRONT_STATUS_ (XXX to be removed) */ - char vendor[100]; char renderer[100]; @@ -140,7 +135,8 @@ struct st_context GLuint user_prog_sn; /**< user fragment program serial no. */ struct st_fragment_program *combined_prog; GLuint combined_prog_sn; - struct pipe_texture *pixelmap_texture; + struct pipe_resource *pixelmap_texture; + struct pipe_sampler_view *pixelmap_sampler_view; boolean pixelmap_enabled; /**< use the pixelmap texture? */ } pixel_xfer; @@ -151,7 +147,7 @@ struct st_context enum pipe_format tex_format; void *vs; float vertices[4][3][4]; /**< vertex pos + color + texcoord */ - struct pipe_buffer *vbuf; + struct pipe_resource *vbuf; unsigned vbuf_slot; /* next free slot in vbuf */ struct bitmap_cache *cache; } bitmap; @@ -170,10 +166,13 @@ struct st_context void *vs; void *fs; float vertices[4][2][4]; /**< vertex pos + color */ - struct pipe_buffer *vbuf; + struct pipe_resource *vbuf; unsigned vbuf_slot; } clear; + /** used for anything using util_draw_vertex_buffer */ + struct pipe_vertex_element velems_util_draw[3]; + void *passthrough_fs; /**< simple pass-through frag shader */ struct gen_mipmap_state *gen_mipmap; @@ -182,6 +181,7 @@ struct st_context struct cso_context *cso_context; int force_msaa; + void *winsys_drawable_handle; }; @@ -201,7 +201,11 @@ struct st_framebuffer { GLframebuffer Base; void *Private; - GLuint InitWidth, InitHeight; + + struct st_framebuffer_iface *iface; + enum st_attachment_type statts[ST_ATTACHMENT_COUNT]; + unsigned num_statts; + int32_t revalidate; }; @@ -246,5 +250,12 @@ st_fb_orientation(const struct gl_framebuffer *fb) extern int st_get_msaa(void); +extern struct st_context * +st_create_context(struct pipe_context *pipe, const __GLcontextModes *visual, + struct st_context *share); + +extern void +st_destroy_context(struct st_context *st); + #endif diff --git a/src/mesa/state_tracker/st_debug.c b/src/mesa/state_tracker/st_debug.c index 5dbabfa5c2f..2da27fc4bd1 100644 --- a/src/mesa/state_tracker/st_debug.c +++ b/src/mesa/state_tracker/st_debug.c @@ -47,6 +47,7 @@ int ST_DEBUG = 0; static const struct debug_named_value st_debug_flags[] = { { "mesa", DEBUG_MESA }, { "tgsi", DEBUG_TGSI }, + { "constants",DEBUG_CONSTANTS }, { "pipe", DEBUG_PIPE }, { "tex", DEBUG_TEX }, { "fallback", DEBUG_FALLBACK }, @@ -75,7 +76,7 @@ void st_print_current(void) { GET_CURRENT_CONTEXT(ctx); - struct st_context *st = ctx->st; + struct st_context *st = st_context(ctx); #if 0 int i; diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index 32b9a473cfc..4137596bd40 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -57,6 +57,7 @@ #include "pipe/p_defines.h" #include "util/u_inlines.h" #include "util/u_format.h" +#include "cso_cache/cso_context.h" static GLuint double_types[4] = { @@ -73,6 +74,13 @@ static GLuint float_types[4] = { PIPE_FORMAT_R32G32B32A32_FLOAT }; +static GLuint half_float_types[4] = { + PIPE_FORMAT_R16_FLOAT, + PIPE_FORMAT_R16G16_FLOAT, + PIPE_FORMAT_R16G16B16_FLOAT, + PIPE_FORMAT_R16G16B16A16_FLOAT +}; + static GLuint uint_types_norm[4] = { PIPE_FORMAT_R32_UNORM, PIPE_FORMAT_R32G32_UNORM, @@ -174,7 +182,7 @@ st_pipe_vertex_format(GLenum type, GLuint size, GLenum format, GLboolean normalized) { assert((type >= GL_BYTE && type <= GL_DOUBLE) || - type == GL_FIXED); + type == GL_FIXED || type == GL_HALF_FLOAT); assert(size >= 1); assert(size <= 4); assert(format == GL_RGBA || format == GL_BGRA); @@ -183,13 +191,14 @@ st_pipe_vertex_format(GLenum type, GLuint size, GLenum format, /* this is an odd-ball case */ assert(type == GL_UNSIGNED_BYTE); assert(normalized); - return PIPE_FORMAT_A8R8G8B8_UNORM; + return PIPE_FORMAT_B8G8R8A8_UNORM; } if (normalized) { switch (type) { case GL_DOUBLE: return double_types[size-1]; case GL_FLOAT: return float_types[size-1]; + case GL_HALF_FLOAT: return half_float_types[size-1]; case GL_INT: return int_types_norm[size-1]; case GL_SHORT: return short_types_norm[size-1]; case GL_BYTE: return byte_types_norm[size-1]; @@ -204,6 +213,7 @@ st_pipe_vertex_format(GLenum type, GLuint size, GLenum format, switch (type) { case GL_DOUBLE: return double_types[size-1]; case GL_FLOAT: return float_types[size-1]; + case GL_HALF_FLOAT: return half_float_types[size-1]; case GL_INT: return int_types_scale[size-1]; case GL_SHORT: return short_types_scale[size-1]; case GL_BYTE: return byte_types_scale[size-1]; @@ -272,7 +282,8 @@ is_interleaved_arrays(const struct st_vertex_program *vp, } *userSpace = (num_client_arrays == vpv->num_inputs); - /* printf("user space: %d (%d %d)\n", (int) *userSpace,num_client_arrays,vp->num_inputs); */ + /* debug_printf("user space: %s (%d arrays, %d inputs)\n", + (int)*userSpace ? "Yes" : "No", num_client_arrays, vp->num_inputs); */ return GL_TRUE; } @@ -292,6 +303,8 @@ get_arrays_bounds(const struct st_vertex_program *vp, const GLubyte *high_addr = NULL; GLuint attr; + /* debug_printf("get_arrays_bounds: Handling %u attrs\n", vpv->num_inputs); */ + for (attr = 0; attr < vpv->num_inputs; attr++) { const GLuint mesaAttr = vp->index_to_input[attr]; const GLint stride = arrays[mesaAttr]->StrideB; @@ -300,6 +313,9 @@ get_arrays_bounds(const struct st_vertex_program *vp, _mesa_sizeof_type(arrays[mesaAttr]->Type)); const GLubyte *end = start + (max_index * stride) + sz; + /* debug_printf("attr %u: stride %d size %u start %p end %p\n", + attr, stride, sz, start, end); */ + if (attr == 0) { low_addr = start; high_addr = end; @@ -331,7 +347,8 @@ setup_interleaved_attribs(GLcontext *ctx, struct pipe_vertex_buffer *vbuffer, struct pipe_vertex_element velements[]) { - struct pipe_context *pipe = ctx->st->pipe; + struct st_context *st = st_context(ctx); + struct pipe_context *pipe = st->pipe; GLuint attr; const GLubyte *offset0 = NULL; @@ -347,17 +364,19 @@ setup_interleaved_attribs(GLcontext *ctx, const GLubyte *low, *high; get_arrays_bounds(vp, vpv, arrays, max_index, &low, &high); - /*printf("buffer range: %p %p %d\n", low, high, high-low);*/ + /* debug_printf("buffer range: %p %p range %d max index %u\n", + low, high, high - low, max_index); */ offset0 = low; if (userSpace) { vbuffer->buffer = - pipe_user_buffer_create(pipe->screen, (void *) low, high - low); + pipe_user_buffer_create(pipe->screen, (void *) low, high - low, + PIPE_BIND_VERTEX_BUFFER); vbuffer->buffer_offset = 0; } else { vbuffer->buffer = NULL; - pipe_buffer_reference(&vbuffer->buffer, stobj->buffer); + pipe_resource_reference(&vbuffer->buffer, stobj->buffer); vbuffer->buffer_offset = pointer_to_offset(low); } vbuffer->stride = stride; /* in bytes */ @@ -368,7 +387,6 @@ setup_interleaved_attribs(GLcontext *ctx, (unsigned) (arrays[mesaAttr]->Ptr - offset0); velements[attr].instance_divisor = 0; velements[attr].vertex_buffer_index = 0; - velements[attr].nr_components = arrays[mesaAttr]->Size; velements[attr].src_format = st_pipe_vertex_format(arrays[mesaAttr]->Type, arrays[mesaAttr]->Size, @@ -395,7 +413,8 @@ setup_non_interleaved_attribs(GLcontext *ctx, struct pipe_vertex_buffer vbuffer[], struct pipe_vertex_element velements[]) { - struct pipe_context *pipe = ctx->st->pipe; + struct st_context *st = st_context(ctx); + struct pipe_context *pipe = st->pipe; GLuint attr; for (attr = 0; attr < vpv->num_inputs; attr++) { @@ -415,7 +434,7 @@ setup_non_interleaved_attribs(GLcontext *ctx, /*printf("stobj %u = %p\n", attr, (void*) stobj);*/ vbuffer[attr].buffer = NULL; - pipe_buffer_reference(&vbuffer[attr].buffer, stobj->buffer); + pipe_resource_reference(&vbuffer[attr].buffer, stobj->buffer); vbuffer[attr].buffer_offset = pointer_to_offset(arrays[mesaAttr]->Ptr); velements[attr].src_offset = 0; } @@ -436,14 +455,19 @@ setup_non_interleaved_attribs(GLcontext *ctx, bytes = arrays[mesaAttr]->Size * _mesa_sizeof_type(arrays[mesaAttr]->Type); } - vbuffer[attr].buffer = pipe_user_buffer_create(pipe->screen, - (void *) arrays[mesaAttr]->Ptr, bytes); + vbuffer[attr].buffer = + pipe_user_buffer_create(pipe->screen, + (void *) arrays[mesaAttr]->Ptr, bytes, + PIPE_BIND_VERTEX_BUFFER); } else { /* no array, use ctx->Current.Attrib[] value */ bytes = sizeof(ctx->Current.Attrib[0]); - vbuffer[attr].buffer = pipe_user_buffer_create(pipe->screen, - (void *) ctx->Current.Attrib[mesaAttr], bytes); + vbuffer[attr].buffer = + pipe_user_buffer_create(pipe->screen, + (void *) ctx->Current.Attrib[mesaAttr], + bytes, + PIPE_BIND_VERTEX_BUFFER); stride = 0; } @@ -458,7 +482,6 @@ setup_non_interleaved_attribs(GLcontext *ctx, vbuffer[attr].max_index = max_index; velements[attr].instance_divisor = 0; velements[attr].vertex_buffer_index = attr; - velements[attr].nr_components = arrays[mesaAttr]->Size; velements[attr].src_format = st_pipe_vertex_format(arrays[mesaAttr]->Type, arrays[mesaAttr]->Size, @@ -522,7 +545,8 @@ st_draw_vbo(GLcontext *ctx, GLuint min_index, GLuint max_index) { - struct pipe_context *pipe = ctx->st->pipe; + struct st_context *st = st_context(ctx); + struct pipe_context *pipe = st->pipe; const struct st_vertex_program *vp; const struct st_vp_varient *vpv; struct pipe_vertex_buffer vbuffer[PIPE_MAX_SHADER_INPUTS]; @@ -545,16 +569,16 @@ st_draw_vbo(GLcontext *ctx, vertDataEdgeFlags = arrays[VERT_ATTRIB_EDGEFLAG]->BufferObj && arrays[VERT_ATTRIB_EDGEFLAG]->BufferObj->Name; - if (vertDataEdgeFlags != ctx->st->vertdata_edgeflags) { - ctx->st->vertdata_edgeflags = vertDataEdgeFlags; - ctx->st->dirty.st |= ST_NEW_EDGEFLAGS_DATA; + if (vertDataEdgeFlags != st->vertdata_edgeflags) { + st->vertdata_edgeflags = vertDataEdgeFlags; + st->dirty.st |= ST_NEW_EDGEFLAGS_DATA; } - st_validate_state(ctx->st); + st_validate_state(st); /* must get these after state validation! */ - vp = ctx->st->vp; - vpv = ctx->st->vp_varient; + vp = st->vp; + vpv = st->vp_varient; #if 0 if (MESA_VERBOSE & VERBOSE_GLSL) { @@ -564,6 +588,7 @@ st_draw_vbo(GLcontext *ctx, (void) check_uniforms; #endif + memset(velements, 0, sizeof(struct pipe_vertex_element) * vpv->num_inputs); /* * Setup the vbuffer[] and velements[] arrays. */ @@ -596,14 +621,13 @@ st_draw_vbo(GLcontext *ctx, for (i = 0; i < num_velements; i++) { printf("vlements[%d].vbuffer_index = %u\n", i, velements[i].vertex_buffer_index); printf("vlements[%d].src_offset = %u\n", i, velements[i].src_offset); - printf("vlements[%d].nr_comps = %u\n", i, velements[i].nr_components); printf("vlements[%d].format = %s\n", i, util_format_name(velements[i].src_format)); } } #endif pipe->set_vertex_buffers(pipe, num_vbuffers, vbuffer); - pipe->set_vertex_elements(pipe, num_velements, velements); + cso_set_vertex_elements(st->cso_context, num_velements, velements); if (num_vbuffers == 0 || num_velements == 0) return; @@ -612,7 +636,7 @@ st_draw_vbo(GLcontext *ctx, if (ib) { /* indexed primitive */ struct gl_buffer_object *bufobj = ib->obj; - struct pipe_buffer *indexBuf = NULL; + struct pipe_resource *indexBuf = NULL; unsigned indexSize, indexOffset, i; unsigned prim; @@ -635,13 +659,14 @@ 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(&indexBuf, stobj->buffer); + pipe_resource_reference(&indexBuf, stobj->buffer); indexOffset = pointer_to_offset(ib->ptr) / indexSize; } else { /* element/indicies are in user space memory */ indexBuf = pipe_user_buffer_create(pipe->screen, (void *) ib->ptr, - ib->count * indexSize); + ib->count * indexSize, + PIPE_BIND_INDEX_BUFFER); indexOffset = 0; } @@ -654,7 +679,7 @@ st_draw_vbo(GLcontext *ctx, for (i = 0; i < nr_prims; i++) { prim = translate_prim( ctx, prims[i].mode ); - pipe->draw_range_elements(pipe, indexBuf, indexSize, + pipe->draw_range_elements(pipe, indexBuf, indexSize, 0, min_index, max_index, prim, prims[i].start + indexOffset, prims[i].count); } @@ -663,13 +688,21 @@ st_draw_vbo(GLcontext *ctx, for (i = 0; i < nr_prims; i++) { prim = translate_prim( ctx, prims[i].mode ); - pipe->draw_elements(pipe, indexBuf, indexSize, - prim, - prims[i].start + indexOffset, prims[i].count); + if (prims[i].num_instances == 1) { + pipe->draw_elements(pipe, indexBuf, indexSize, 0, prim, + prims[i].start + indexOffset, + prims[i].count); + } + else { + pipe->draw_elements_instanced(pipe, indexBuf, indexSize, 0, prim, + prims[i].start + indexOffset, + prims[i].count, + 0, prims[i].num_instances); + } } } - pipe_buffer_reference(&indexBuf, NULL); + pipe_resource_reference(&indexBuf, NULL); } else { /* non-indexed */ @@ -679,13 +712,20 @@ st_draw_vbo(GLcontext *ctx, for (i = 0; i < nr_prims; i++) { prim = translate_prim( ctx, prims[i].mode ); - pipe->draw_arrays(pipe, prim, prims[i].start, prims[i].count); + if (prims[i].num_instances == 1) { + pipe->draw_arrays(pipe, prim, prims[i].start, prims[i].count); + } + else { + pipe->draw_arrays_instanced(pipe, prim, prims[i].start, + prims[i].count, + 0, prims[i].num_instances); + } } } /* unreference buffers (frees wrapped user-space buffer objects) */ for (attr = 0; attr < num_vbuffers; attr++) { - pipe_buffer_reference(&vbuffer[attr].buffer, NULL); + pipe_resource_reference(&vbuffer[attr].buffer, NULL); assert(!vbuffer[attr].buffer); } diff --git a/src/mesa/state_tracker/st_draw_feedback.c b/src/mesa/state_tracker/st_draw_feedback.c index 087f2f22bbf..a1f70e86936 100644 --- a/src/mesa/state_tracker/st_draw_feedback.c +++ b/src/mesa/state_tracker/st_draw_feedback.c @@ -55,7 +55,7 @@ static void set_feedback_vertex_format(GLcontext *ctx) { #if 0 - struct st_context *st = ctx->st; + struct st_context *st = st_context(ctx); struct vertex_info vinfo; GLuint i; @@ -99,26 +99,29 @@ st_feedback_draw_vbo(GLcontext *ctx, GLuint min_index, GLuint max_index) { - struct st_context *st = ctx->st; + struct st_context *st = st_context(ctx); struct pipe_context *pipe = st->pipe; struct draw_context *draw = st->draw; const struct st_vertex_program *vp; const struct pipe_shader_state *vs; - struct pipe_buffer *index_buffer_handle = 0; + struct pipe_resource *index_buffer_handle = 0; struct pipe_vertex_buffer vbuffers[PIPE_MAX_SHADER_INPUTS]; struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS]; + struct pipe_transfer *vb_transfer[PIPE_MAX_ATTRIBS]; + struct pipe_transfer *ib_transfer = NULL; + struct pipe_transfer *cb_transfer; GLuint attr, i; ubyte *mapped_constants; assert(draw); - st_validate_state(ctx->st); + st_validate_state(st); if (!index_bounds_valid) vbo_get_minmax_index(ctx, prims, ib, &min_index, &max_index); /* must get these after state validation! */ - vp = ctx->st->vp; + vp = st->vp; vs = &st->vp_varient->tgsi; if (!st->vp_varient->draw_shader) { @@ -134,7 +137,7 @@ st_feedback_draw_vbo(GLcontext *ctx, assert(draw); draw_set_viewport_state(draw, &st->state.viewport); draw_set_clip_state(draw, &st->state.clip); - draw_set_rasterizer_state(draw, &st->state.rasterizer); + draw_set_rasterizer_state(draw, &st->state.rasterizer, NULL); draw_bind_vertex_shader(draw, st->vp_varient->draw_shader); set_feedback_vertex_format(ctx); @@ -155,7 +158,7 @@ st_feedback_draw_vbo(GLcontext *ctx, assert(stobj->buffer); vbuffers[attr].buffer = NULL; - pipe_buffer_reference(&vbuffers[attr].buffer, stobj->buffer); + pipe_resource_reference(&vbuffers[attr].buffer, stobj->buffer); vbuffers[attr].buffer_offset = pointer_to_offset(arrays[0]->Ptr); velements[attr].src_offset = arrays[mesaAttr]->Ptr - arrays[0]->Ptr; } @@ -168,7 +171,8 @@ st_feedback_draw_vbo(GLcontext *ctx, /* wrap user data */ vbuffers[attr].buffer = pipe_user_buffer_create(pipe->screen, (void *) arrays[mesaAttr]->Ptr, - bytes); + bytes, + PIPE_BIND_VERTEX_BUFFER); vbuffers[attr].buffer_offset = 0; velements[attr].src_offset = 0; } @@ -178,7 +182,6 @@ st_feedback_draw_vbo(GLcontext *ctx, vbuffers[attr].max_index = max_index; velements[attr].instance_divisor = 0; velements[attr].vertex_buffer_index = attr; - velements[attr].nr_components = arrays[mesaAttr]->Size; velements[attr].src_format = st_pipe_vertex_format(arrays[mesaAttr]->Type, arrays[mesaAttr]->Size, @@ -192,8 +195,9 @@ st_feedback_draw_vbo(GLcontext *ctx, #endif /* map the attrib buffer */ - map = pipe_buffer_map(pipe->screen, vbuffers[attr].buffer, - PIPE_BUFFER_USAGE_CPU_READ); + map = pipe_buffer_map(pipe, vbuffers[attr].buffer, + PIPE_TRANSFER_READ, + &vb_transfer[attr]); draw_set_mapped_vertex_buffer(draw, attr, map); } @@ -222,28 +226,30 @@ st_feedback_draw_vbo(GLcontext *ctx, index_buffer_handle = stobj->buffer; - map = pipe_buffer_map(pipe->screen, index_buffer_handle, - PIPE_BUFFER_USAGE_CPU_READ); + map = pipe_buffer_map(pipe, index_buffer_handle, + PIPE_TRANSFER_READ, &ib_transfer); - draw_set_mapped_element_buffer(draw, indexSize, map); + draw_set_mapped_element_buffer(draw, indexSize, 0, map); } else { - draw_set_mapped_element_buffer(draw, indexSize, (void *) ib->ptr); + draw_set_mapped_element_buffer(draw, indexSize, 0, (void *) ib->ptr); + ib_transfer = NULL; } } else { /* no index/element buffer */ - draw_set_mapped_element_buffer(draw, 0, NULL); + draw_set_mapped_element_buffer(draw, 0, 0, NULL); } /* map constant buffers */ - mapped_constants = pipe_buffer_map(pipe->screen, + mapped_constants = pipe_buffer_map(pipe, st->state.constants[PIPE_SHADER_VERTEX], - PIPE_BUFFER_USAGE_CPU_READ); + PIPE_TRANSFER_READ, + &cb_transfer); draw_set_mapped_constant_buffer(st->draw, PIPE_SHADER_VERTEX, 0, mapped_constants, - st->state.constants[PIPE_SHADER_VERTEX]->size); + st->state.constants[PIPE_SHADER_VERTEX]->width0); /* draw here */ @@ -253,21 +259,23 @@ st_feedback_draw_vbo(GLcontext *ctx, /* unmap constant buffers */ - pipe_buffer_unmap(pipe->screen, st->state.constants[PIPE_SHADER_VERTEX]); + pipe_buffer_unmap(pipe, st->state.constants[PIPE_SHADER_VERTEX], + cb_transfer); /* * unmap vertex/index buffers */ for (i = 0; i < PIPE_MAX_ATTRIBS; i++) { if (draw->pt.vertex_buffer[i].buffer) { - pipe_buffer_unmap(pipe->screen, draw->pt.vertex_buffer[i].buffer); - pipe_buffer_reference(&draw->pt.vertex_buffer[i].buffer, NULL); + pipe_buffer_unmap(pipe, draw->pt.vertex_buffer[i].buffer, + vb_transfer[i]); + pipe_resource_reference(&draw->pt.vertex_buffer[i].buffer, NULL); draw_set_mapped_vertex_buffer(draw, i, NULL); } } if (index_buffer_handle) { - pipe_buffer_unmap(pipe->screen, index_buffer_handle); - draw_set_mapped_element_buffer(draw, 0, NULL); + pipe_buffer_unmap(pipe, index_buffer_handle, ib_transfer); + draw_set_mapped_element_buffer(draw, 0, 0, NULL); } } diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c index 79be833768f..b2045cf3fcb 100644 --- a/src/mesa/state_tracker/st_extensions.c +++ b/src/mesa/state_tracker/st_extensions.c @@ -137,6 +137,9 @@ void st_init_limits(struct st_context *st) /* XXX separate query for early function return? */ st->ctx->Shader.EmitContReturn = screen->get_param(screen, PIPE_CAP_TGSI_CONT_SUPPORTED); + + /* Quads always follow GL provoking rules. */ + c->QuadsFollowProvokingVertexConvention = GL_FALSE; } @@ -169,6 +172,7 @@ void st_init_extensions(struct st_context *st) ctx->Extensions.ARB_vertex_array_object = GL_TRUE; ctx->Extensions.ARB_vertex_buffer_object = GL_TRUE; ctx->Extensions.ARB_vertex_program = GL_TRUE; + ctx->Extensions.ARB_window_pos = GL_TRUE; ctx->Extensions.EXT_blend_color = GL_TRUE; ctx->Extensions.EXT_blend_func_separate = GL_TRUE; @@ -179,6 +183,7 @@ void st_init_extensions(struct st_context *st) ctx->Extensions.EXT_framebuffer_object = GL_TRUE; ctx->Extensions.EXT_framebuffer_multisample = GL_TRUE; ctx->Extensions.EXT_fog_coord = GL_TRUE; + ctx->Extensions.EXT_gpu_program_parameters = GL_TRUE; ctx->Extensions.EXT_multi_draw_arrays = GL_TRUE; ctx->Extensions.EXT_pixel_buffer_object = GL_TRUE; ctx->Extensions.EXT_point_parameters = GL_TRUE; @@ -193,10 +198,21 @@ void st_init_extensions(struct st_context *st) ctx->Extensions.APPLE_vertex_array_object = GL_TRUE; + ctx->Extensions.MESA_pack_invert = GL_TRUE; + ctx->Extensions.NV_blend_square = GL_TRUE; ctx->Extensions.NV_texgen_reflection = GL_TRUE; ctx->Extensions.NV_texture_env_combine4 = GL_TRUE; + ctx->Extensions.NV_texture_rectangle = GL_TRUE; +#if 0 + /* possibly could support the following two */ + ctx->Extensions.NV_vertex_program = GL_TRUE; + ctx->Extensions.NV_vertex_program1_1 = GL_TRUE; +#endif +#if FEATURE_OES_EGL_image + ctx->Extensions.OES_EGL_image = GL_TRUE; +#endif #if FEATURE_OES_draw_texture ctx->Extensions.OES_draw_texture = GL_TRUE; #endif @@ -229,11 +245,11 @@ void st_init_extensions(struct st_context *st) if (screen->get_param(screen, PIPE_CAP_TEXTURE_MIRROR_CLAMP) > 0) { ctx->Extensions.EXT_texture_mirror_clamp = GL_TRUE; + ctx->Extensions.ATI_texture_mirror_once = GL_TRUE; } if (screen->get_param(screen, PIPE_CAP_NPOT_TEXTURES)) { ctx->Extensions.ARB_texture_non_power_of_two = GL_TRUE; - ctx->Extensions.NV_texture_rectangle = GL_TRUE; } if (screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS) > 1) { @@ -270,41 +286,41 @@ void st_init_extensions(struct st_context *st) /* GL_EXT_packed_depth_stencil requires both the ability to render to * a depth/stencil buffer and texture from depth/stencil source. */ - if (screen->is_format_supported(screen, PIPE_FORMAT_S8Z24_UNORM, + if (screen->is_format_supported(screen, PIPE_FORMAT_S8_USCALED_Z24_UNORM, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0) && - screen->is_format_supported(screen, PIPE_FORMAT_S8Z24_UNORM, + PIPE_BIND_DEPTH_STENCIL, 0) && + screen->is_format_supported(screen, PIPE_FORMAT_S8_USCALED_Z24_UNORM, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_SAMPLER, 0)) { + PIPE_BIND_SAMPLER_VIEW, 0)) { ctx->Extensions.EXT_packed_depth_stencil = GL_TRUE; } - else if (screen->is_format_supported(screen, PIPE_FORMAT_Z24S8_UNORM, + else if (screen->is_format_supported(screen, PIPE_FORMAT_Z24_UNORM_S8_USCALED, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0) && - screen->is_format_supported(screen, PIPE_FORMAT_Z24S8_UNORM, + PIPE_BIND_DEPTH_STENCIL, 0) && + screen->is_format_supported(screen, PIPE_FORMAT_Z24_UNORM_S8_USCALED, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_SAMPLER, 0)) { + PIPE_BIND_SAMPLER_VIEW, 0)) { ctx->Extensions.EXT_packed_depth_stencil = GL_TRUE; } /* sRGB support */ if (screen->is_format_supported(screen, PIPE_FORMAT_A8B8G8R8_SRGB, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_SAMPLER, 0) || + PIPE_BIND_SAMPLER_VIEW, 0) || screen->is_format_supported(screen, PIPE_FORMAT_B8G8R8A8_SRGB, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_SAMPLER, 0)) { + PIPE_BIND_SAMPLER_VIEW, 0)) { ctx->Extensions.EXT_texture_sRGB = GL_TRUE; } /* s3tc support */ if (screen->is_format_supported(screen, PIPE_FORMAT_DXT5_RGBA, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_SAMPLER, 0) && + PIPE_BIND_SAMPLER_VIEW, 0) && (ctx->Mesa_DXTn || screen->is_format_supported(screen, PIPE_FORMAT_DXT5_RGBA, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_RENDER_TARGET, 0))) { + PIPE_BIND_RENDER_TARGET, 0))) { ctx->Extensions.EXT_texture_compression_s3tc = GL_TRUE; ctx->Extensions.S3_s3tc = GL_TRUE; } @@ -312,10 +328,10 @@ void st_init_extensions(struct st_context *st) /* ycbcr support */ if (screen->is_format_supported(screen, PIPE_FORMAT_UYVY, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_SAMPLER, 0) || + PIPE_BIND_SAMPLER_VIEW, 0) || screen->is_format_supported(screen, PIPE_FORMAT_YUYV, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_SAMPLER, 0)) { + PIPE_BIND_SAMPLER_VIEW, 0)) { ctx->Extensions.MESA_ycbcr_texture = GL_TRUE; } diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c index 9ae0c9f9bab..d7d2be6d454 100644 --- a/src/mesa/state_tracker/st_format.c +++ b/src/mesa/state_tracker/st_format.c @@ -36,6 +36,7 @@ #include "main/context.h" #include "main/texstore.h" #include "main/enums.h" +#include "main/image.h" #include "main/macros.h" #include "pipe/p_context.h" @@ -76,8 +77,8 @@ st_format_datatype(enum pipe_format format) format == PIPE_FORMAT_B5G6R5_UNORM) { return GL_UNSIGNED_SHORT; } - else if (format == PIPE_FORMAT_Z24S8_UNORM || - format == PIPE_FORMAT_S8Z24_UNORM) { + else if (format == PIPE_FORMAT_Z24_UNORM_S8_USCALED || + format == PIPE_FORMAT_S8_USCALED_Z24_UNORM) { return GL_UNSIGNED_INT_24_8; } else { @@ -126,12 +127,18 @@ enum pipe_format st_mesa_format_to_pipe_format(gl_format mesaFormat) { switch (mesaFormat) { - /* fix this */ - case MESA_FORMAT_ARGB8888_REV: + case MESA_FORMAT_RGBA8888: + return PIPE_FORMAT_A8B8G8R8_UNORM; + case MESA_FORMAT_RGBA8888_REV: + return PIPE_FORMAT_R8G8B8A8_UNORM; case MESA_FORMAT_ARGB8888: return PIPE_FORMAT_B8G8R8A8_UNORM; + case MESA_FORMAT_ARGB8888_REV: + return PIPE_FORMAT_A8R8G8B8_UNORM; case MESA_FORMAT_XRGB8888: return PIPE_FORMAT_B8G8R8X8_UNORM; + case MESA_FORMAT_XRGB8888_REV: + return PIPE_FORMAT_X8R8G8B8_UNORM; case MESA_FORMAT_ARGB1555: return PIPE_FORMAT_B5G5R5A1_UNORM; case MESA_FORMAT_ARGB4444: @@ -151,9 +158,13 @@ st_mesa_format_to_pipe_format(gl_format mesaFormat) case MESA_FORMAT_Z32: return PIPE_FORMAT_Z32_UNORM; case MESA_FORMAT_Z24_S8: - return PIPE_FORMAT_S8Z24_UNORM; + return PIPE_FORMAT_S8_USCALED_Z24_UNORM; case MESA_FORMAT_S8_Z24: - return PIPE_FORMAT_Z24S8_UNORM; + return PIPE_FORMAT_Z24_UNORM_S8_USCALED; + case MESA_FORMAT_Z24_X8: + return PIPE_FORMAT_X8Z24_UNORM; + case MESA_FORMAT_X8_Z24: + return PIPE_FORMAT_Z24X8_UNORM; case MESA_FORMAT_YCBCR: return PIPE_FORMAT_UYVY; #if FEATURE_texture_s3tc @@ -190,7 +201,7 @@ st_mesa_format_to_pipe_format(gl_format mesaFormat) #endif default: assert(0); - return 0; + return PIPE_FORMAT_NONE; } } @@ -202,12 +213,16 @@ gl_format st_pipe_format_to_mesa_format(enum pipe_format format) { switch (format) { + case PIPE_FORMAT_A8B8G8R8_UNORM: + return MESA_FORMAT_RGBA8888; + case PIPE_FORMAT_R8G8B8A8_UNORM: + return MESA_FORMAT_RGBA8888_REV; case PIPE_FORMAT_B8G8R8A8_UNORM: return MESA_FORMAT_ARGB8888; - case PIPE_FORMAT_B8G8R8X8_UNORM: - return MESA_FORMAT_XRGB8888; case PIPE_FORMAT_A8R8G8B8_UNORM: return MESA_FORMAT_ARGB8888_REV; + case PIPE_FORMAT_B8G8R8X8_UNORM: + return MESA_FORMAT_XRGB8888; case PIPE_FORMAT_X8R8G8B8_UNORM: return MESA_FORMAT_XRGB8888_REV; case PIPE_FORMAT_B5G5R5A1_UNORM: @@ -224,7 +239,7 @@ st_pipe_format_to_mesa_format(enum pipe_format format) return MESA_FORMAT_L8; case PIPE_FORMAT_I8_UNORM: return MESA_FORMAT_I8; - case PIPE_FORMAT_S8_UNORM: + case PIPE_FORMAT_S8_USCALED: return MESA_FORMAT_S8; case PIPE_FORMAT_R16G16B16A16_SNORM: @@ -234,13 +249,13 @@ st_pipe_format_to_mesa_format(enum pipe_format format) return MESA_FORMAT_Z16; case PIPE_FORMAT_Z32_UNORM: return MESA_FORMAT_Z32; - case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_S8_USCALED_Z24_UNORM: return MESA_FORMAT_Z24_S8; case PIPE_FORMAT_X8Z24_UNORM: return MESA_FORMAT_Z24_X8; case PIPE_FORMAT_Z24X8_UNORM: return MESA_FORMAT_X8_Z24; - case PIPE_FORMAT_Z24S8_UNORM: + case PIPE_FORMAT_Z24_UNORM_S8_USCALED: return MESA_FORMAT_S8_Z24; case PIPE_FORMAT_UYVY: @@ -289,6 +304,28 @@ st_pipe_format_to_mesa_format(enum pipe_format format) /** + * Return first supported format from the given list. + */ +static enum pipe_format +find_supported_format(struct pipe_screen *screen, + const enum pipe_format formats[], + uint num_formats, + enum pipe_texture_target target, + unsigned tex_usage, + unsigned geom_flags) +{ + uint i; + for (i = 0; i < num_formats; i++) { + if (screen->is_format_supported(screen, formats[i], target, + tex_usage, geom_flags)) { + return formats[i]; + } + } + return PIPE_FORMAT_NONE; +} + + +/** * Find an RGBA format supported by the context/winsys. */ static enum pipe_format @@ -303,15 +340,11 @@ default_rgba_format(struct pipe_screen *screen, PIPE_FORMAT_A8B8G8R8_UNORM, PIPE_FORMAT_B5G6R5_UNORM }; - uint i; - for (i = 0; i < Elements(colorFormats); i++) { - if (screen->is_format_supported( screen, colorFormats[i], target, tex_usage, geom_flags )) { - return colorFormats[i]; - } - } - return PIPE_FORMAT_NONE; + return find_supported_format(screen, colorFormats, Elements(colorFormats), + target, tex_usage, geom_flags); } + /** * Find an RGB format supported by the context/winsys. */ @@ -330,13 +363,8 @@ default_rgb_format(struct pipe_screen *screen, PIPE_FORMAT_A8B8G8R8_UNORM, PIPE_FORMAT_B5G6R5_UNORM }; - uint i; - for (i = 0; i < Elements(colorFormats); i++) { - if (screen->is_format_supported( screen, colorFormats[i], target, tex_usage, geom_flags )) { - return colorFormats[i]; - } - } - return PIPE_FORMAT_NONE; + return find_supported_format(screen, colorFormats, Elements(colorFormats), + target, tex_usage, geom_flags); } /** @@ -353,115 +381,72 @@ default_srgba_format(struct pipe_screen *screen, PIPE_FORMAT_A8R8G8B8_SRGB, PIPE_FORMAT_A8B8G8R8_SRGB, }; - uint i; - for (i = 0; i < Elements(colorFormats); i++) { - if (screen->is_format_supported( screen, colorFormats[i], target, tex_usage, geom_flags )) { - return colorFormats[i]; - } - } - return PIPE_FORMAT_NONE; -} - -/** - * Search list of formats for first RGBA format with >8 bits/channel. - */ -static enum pipe_format -default_deep_rgba_format(struct pipe_screen *screen, - enum pipe_texture_target target, - unsigned tex_usage, - unsigned geom_flags) -{ - if (screen->is_format_supported(screen, PIPE_FORMAT_R16G16B16A16_SNORM, target, tex_usage, geom_flags)) { - return PIPE_FORMAT_R16G16B16A16_SNORM; - } - if (tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET) - return default_rgba_format(screen, target, tex_usage, geom_flags); - else - return PIPE_FORMAT_NONE; -} - - -/** - * Find an Z format supported by the context/winsys. - */ -static enum pipe_format -default_depth_format(struct pipe_screen *screen, - enum pipe_texture_target target, - unsigned tex_usage, - unsigned geom_flags) -{ - static const enum pipe_format zFormats[] = { - PIPE_FORMAT_Z16_UNORM, - PIPE_FORMAT_Z32_UNORM, - PIPE_FORMAT_Z24S8_UNORM, - PIPE_FORMAT_S8Z24_UNORM - }; - uint i; - for (i = 0; i < Elements(zFormats); i++) { - if (screen->is_format_supported( screen, zFormats[i], target, tex_usage, geom_flags )) { - return zFormats[i]; - } - } - return PIPE_FORMAT_NONE; + return find_supported_format(screen, colorFormats, Elements(colorFormats), + target, tex_usage, geom_flags); } /** * Given an OpenGL internalFormat value for a texture or surface, return * the best matching PIPE_FORMAT_x, or PIPE_FORMAT_NONE if there's no match. + * This is called during glTexImage2D, for example. + * + * The bindings parameter typically has PIPE_BIND_SAMPLER_VIEW set, plus + * either PIPE_BINDING_RENDER_TARGET or PIPE_BINDING_DEPTH_STENCIL if + * we want render-to-texture ability. + * + * \param internalFormat the user value passed to glTexImage2D * \param target one of PIPE_TEXTURE_x - * \param tex_usage either PIPE_TEXTURE_USAGE_RENDER_TARGET - * or PIPE_TEXTURE_USAGE_SAMPLER + * \param bindings bitmask of PIPE_BIND_x flags. */ enum pipe_format st_choose_format(struct pipe_screen *screen, GLenum internalFormat, - enum pipe_texture_target target, unsigned tex_usage) + enum pipe_texture_target target, unsigned bindings) { - unsigned geom_flags = 0; + unsigned geom_flags = 0; /* we don't care about POT vs. NPOT here, yet */ switch (internalFormat) { case 4: case GL_RGBA: - case GL_COMPRESSED_RGBA: case GL_RGBA8: case GL_RGB10_A2: case GL_RGBA12: - return default_rgba_format( screen, target, tex_usage, geom_flags ); + return default_rgba_format( screen, target, bindings, geom_flags ); case 3: case GL_RGB: - case GL_COMPRESSED_RGB: - return default_rgb_format( screen, target, tex_usage, geom_flags ); + return default_rgb_format( screen, target, bindings, geom_flags ); case GL_RGBA16: - if (tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET) - return default_deep_rgba_format( screen, target, tex_usage, geom_flags ); - else - return default_rgba_format( screen, target, tex_usage, geom_flags ); + return default_rgba_format( screen, target, bindings, geom_flags ); case GL_RGBA4: case GL_RGBA2: - if (screen->is_format_supported( screen, PIPE_FORMAT_B4G4R4A4_UNORM, target, tex_usage, geom_flags )) + if (screen->is_format_supported( screen, PIPE_FORMAT_B4G4R4A4_UNORM, + target, bindings, geom_flags )) return PIPE_FORMAT_B4G4R4A4_UNORM; - return default_rgba_format( screen, target, tex_usage, geom_flags ); + return default_rgba_format( screen, target, bindings, geom_flags ); case GL_RGB5_A1: - if (screen->is_format_supported( screen, PIPE_FORMAT_B5G5R5A1_UNORM, target, tex_usage, geom_flags )) + if (screen->is_format_supported( screen, PIPE_FORMAT_B5G5R5A1_UNORM, + target, bindings, geom_flags )) return PIPE_FORMAT_B5G5R5A1_UNORM; - return default_rgba_format( screen, target, tex_usage, geom_flags ); + return default_rgba_format( screen, target, bindings, geom_flags ); case GL_RGB8: case GL_RGB10: case GL_RGB12: case GL_RGB16: - return default_rgb_format( screen, target, tex_usage, geom_flags ); + return default_rgb_format( screen, target, bindings, geom_flags ); case GL_RGB5: case GL_RGB4: case GL_R3_G3_B2: - if (screen->is_format_supported( screen, PIPE_FORMAT_B5G6R5_UNORM, target, tex_usage, geom_flags )) + if (screen->is_format_supported( screen, PIPE_FORMAT_B5G6R5_UNORM, + target, bindings, geom_flags )) return PIPE_FORMAT_B5G6R5_UNORM; - if (screen->is_format_supported( screen, PIPE_FORMAT_B5G5R5A1_UNORM, target, tex_usage, geom_flags )) + if (screen->is_format_supported( screen, PIPE_FORMAT_B5G5R5A1_UNORM, + target, bindings, geom_flags )) return PIPE_FORMAT_B5G5R5A1_UNORM; - return default_rgba_format( screen, target, tex_usage, geom_flags ); + return default_rgba_format( screen, target, bindings, geom_flags ); case GL_ALPHA: case GL_ALPHA4: @@ -469,9 +454,10 @@ st_choose_format(struct pipe_screen *screen, GLenum internalFormat, case GL_ALPHA12: case GL_ALPHA16: case GL_COMPRESSED_ALPHA: - if (screen->is_format_supported( screen, PIPE_FORMAT_A8_UNORM, target, tex_usage, geom_flags )) + if (screen->is_format_supported( screen, PIPE_FORMAT_A8_UNORM, target, + bindings, geom_flags )) return PIPE_FORMAT_A8_UNORM; - return default_rgba_format( screen, target, tex_usage, geom_flags ); + return default_rgba_format( screen, target, bindings, geom_flags ); case 1: case GL_LUMINANCE: @@ -480,9 +466,10 @@ st_choose_format(struct pipe_screen *screen, GLenum internalFormat, case GL_LUMINANCE12: case GL_LUMINANCE16: case GL_COMPRESSED_LUMINANCE: - if (screen->is_format_supported( screen, PIPE_FORMAT_L8_UNORM, target, tex_usage, geom_flags )) + if (screen->is_format_supported( screen, PIPE_FORMAT_L8_UNORM, target, + bindings, geom_flags )) return PIPE_FORMAT_L8_UNORM; - return default_rgba_format( screen, target, tex_usage, geom_flags ); + return default_rgba_format( screen, target, bindings, geom_flags ); case 2: case GL_LUMINANCE_ALPHA: @@ -493,9 +480,10 @@ st_choose_format(struct pipe_screen *screen, GLenum internalFormat, case GL_LUMINANCE12_ALPHA12: case GL_LUMINANCE16_ALPHA16: case GL_COMPRESSED_LUMINANCE_ALPHA: - if (screen->is_format_supported( screen, PIPE_FORMAT_L8A8_UNORM, target, tex_usage, geom_flags )) + if (screen->is_format_supported( screen, PIPE_FORMAT_L8A8_UNORM, target, + bindings, geom_flags )) return PIPE_FORMAT_L8A8_UNORM; - return default_rgba_format( screen, target, tex_usage, geom_flags ); + return default_rgba_format( screen, target, bindings, geom_flags ); case GL_INTENSITY: case GL_INTENSITY4: @@ -503,36 +491,73 @@ st_choose_format(struct pipe_screen *screen, GLenum internalFormat, case GL_INTENSITY12: case GL_INTENSITY16: case GL_COMPRESSED_INTENSITY: - if (screen->is_format_supported( screen, PIPE_FORMAT_I8_UNORM, target, tex_usage, geom_flags )) + if (screen->is_format_supported( screen, PIPE_FORMAT_I8_UNORM, target, + bindings, geom_flags )) return PIPE_FORMAT_I8_UNORM; - return default_rgba_format( screen, target, tex_usage, geom_flags ); + return default_rgba_format( screen, target, bindings, geom_flags ); case GL_YCBCR_MESA: if (screen->is_format_supported(screen, PIPE_FORMAT_UYVY, - target, tex_usage, geom_flags)) { + target, bindings, geom_flags)) { return PIPE_FORMAT_UYVY; } if (screen->is_format_supported(screen, PIPE_FORMAT_YUYV, - target, tex_usage, geom_flags)) { + target, bindings, geom_flags)) { return PIPE_FORMAT_YUYV; } return PIPE_FORMAT_NONE; + case GL_COMPRESSED_RGB: + /* can only sample from compressed formats */ + if (bindings & ~PIPE_BIND_SAMPLER_VIEW) + return PIPE_FORMAT_NONE; + else if (screen->is_format_supported(screen, PIPE_FORMAT_DXT1_RGB, + target, bindings, geom_flags)) + return PIPE_FORMAT_DXT1_RGB; + else + return default_rgb_format(screen, target, bindings, geom_flags); + + case GL_COMPRESSED_RGBA: + /* can only sample from compressed formats */ + if (bindings & ~PIPE_BIND_SAMPLER_VIEW) + return PIPE_FORMAT_NONE; + else if (screen->is_format_supported(screen, PIPE_FORMAT_DXT3_RGBA, + target, bindings, geom_flags)) + return PIPE_FORMAT_DXT3_RGBA; + else + return default_rgba_format(screen, target, bindings, geom_flags); + case GL_RGB_S3TC: case GL_RGB4_S3TC: case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: - return PIPE_FORMAT_DXT1_RGB; + if (screen->is_format_supported(screen, PIPE_FORMAT_DXT1_RGB, + target, bindings, geom_flags)) + return PIPE_FORMAT_DXT1_RGB; + else + return PIPE_FORMAT_NONE; case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: - return PIPE_FORMAT_DXT1_RGBA; + if (screen->is_format_supported(screen, PIPE_FORMAT_DXT1_RGBA, + target, bindings, geom_flags)) + return PIPE_FORMAT_DXT1_RGBA; + else + return PIPE_FORMAT_NONE; case GL_RGBA_S3TC: case GL_RGBA4_S3TC: case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: - return PIPE_FORMAT_DXT3_RGBA; + if (screen->is_format_supported(screen, PIPE_FORMAT_DXT3_RGBA, + target, bindings, geom_flags)) + return PIPE_FORMAT_DXT3_RGBA; + else + return PIPE_FORMAT_NONE; case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: - return PIPE_FORMAT_DXT5_RGBA; + if (screen->is_format_supported(screen, PIPE_FORMAT_DXT5_RGBA, + target, bindings, geom_flags)) + return PIPE_FORMAT_DXT5_RGBA; + else + return PIPE_FORMAT_NONE; #if 0 case GL_COMPRESSED_RGB_FXT1_3DFX: @@ -542,42 +567,60 @@ st_choose_format(struct pipe_screen *screen, GLenum internalFormat, #endif case GL_DEPTH_COMPONENT16: - if (screen->is_format_supported( screen, PIPE_FORMAT_Z16_UNORM, target, tex_usage, geom_flags )) + if (screen->is_format_supported(screen, PIPE_FORMAT_Z16_UNORM, target, + bindings, geom_flags)) return PIPE_FORMAT_Z16_UNORM; /* fall-through */ case GL_DEPTH_COMPONENT24: - if (screen->is_format_supported( screen, PIPE_FORMAT_Z24S8_UNORM, target, tex_usage, geom_flags )) - return PIPE_FORMAT_Z24S8_UNORM; - if (screen->is_format_supported( screen, PIPE_FORMAT_S8Z24_UNORM, target, tex_usage, geom_flags )) - return PIPE_FORMAT_S8Z24_UNORM; + if (screen->is_format_supported(screen, PIPE_FORMAT_Z24_UNORM_S8_USCALED, + target, bindings, geom_flags)) + return PIPE_FORMAT_Z24_UNORM_S8_USCALED; + if (screen->is_format_supported(screen, PIPE_FORMAT_S8_USCALED_Z24_UNORM, + target, bindings, geom_flags)) + return PIPE_FORMAT_S8_USCALED_Z24_UNORM; /* fall-through */ case GL_DEPTH_COMPONENT32: - if (screen->is_format_supported( screen, PIPE_FORMAT_Z32_UNORM, target, tex_usage, geom_flags )) + if (screen->is_format_supported(screen, PIPE_FORMAT_Z32_UNORM, + target, bindings, geom_flags)) return PIPE_FORMAT_Z32_UNORM; /* fall-through */ case GL_DEPTH_COMPONENT: - return default_depth_format( screen, target, tex_usage, geom_flags ); + { + static const enum pipe_format formats[] = { + PIPE_FORMAT_Z16_UNORM, + PIPE_FORMAT_Z32_UNORM, + PIPE_FORMAT_Z24_UNORM_S8_USCALED, + PIPE_FORMAT_S8_USCALED_Z24_UNORM + }; + return find_supported_format(screen, formats, Elements(formats), + target, bindings, geom_flags); + } 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 (screen->is_format_supported( screen, PIPE_FORMAT_S8_UNORM, target, tex_usage, geom_flags )) - return PIPE_FORMAT_S8_UNORM; - if (screen->is_format_supported( screen, PIPE_FORMAT_Z24S8_UNORM, target, tex_usage, geom_flags )) - return PIPE_FORMAT_Z24S8_UNORM; - if (screen->is_format_supported( screen, PIPE_FORMAT_S8Z24_UNORM, target, tex_usage, geom_flags )) - return PIPE_FORMAT_S8Z24_UNORM; - return PIPE_FORMAT_NONE; + { + static const enum pipe_format formats[] = { + PIPE_FORMAT_S8_USCALED, + PIPE_FORMAT_Z24_UNORM_S8_USCALED, + PIPE_FORMAT_S8_USCALED_Z24_UNORM + }; + return find_supported_format(screen, formats, Elements(formats), + target, bindings, geom_flags); + } case GL_DEPTH_STENCIL_EXT: case GL_DEPTH24_STENCIL8_EXT: - if (screen->is_format_supported( screen, PIPE_FORMAT_Z24S8_UNORM, target, tex_usage, geom_flags )) - return PIPE_FORMAT_Z24S8_UNORM; - if (screen->is_format_supported( screen, PIPE_FORMAT_S8Z24_UNORM, target, tex_usage, geom_flags )) - return PIPE_FORMAT_S8Z24_UNORM; - return PIPE_FORMAT_NONE; + { + static const enum pipe_format formats[] = { + PIPE_FORMAT_Z24_UNORM_S8_USCALED, + PIPE_FORMAT_S8_USCALED_Z24_UNORM + }; + return find_supported_format(screen, formats, Elements(formats), + target, bindings, geom_flags); + } case GL_SRGB_EXT: case GL_SRGB8_EXT: @@ -585,7 +628,7 @@ st_choose_format(struct pipe_screen *screen, GLenum internalFormat, case GL_COMPRESSED_SRGB_ALPHA_EXT: case GL_SRGB_ALPHA_EXT: case GL_SRGB8_ALPHA8_EXT: - return default_srgba_format( screen, target, tex_usage, geom_flags ); + return default_srgba_format( screen, target, bindings, geom_flags ); case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: return PIPE_FORMAT_DXT1_SRGB; case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: @@ -599,15 +642,17 @@ st_choose_format(struct pipe_screen *screen, GLenum internalFormat, case GL_SLUMINANCE8_ALPHA8_EXT: case GL_COMPRESSED_SLUMINANCE_EXT: case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT: - if (screen->is_format_supported( screen, PIPE_FORMAT_L8A8_SRGB, target, tex_usage, geom_flags )) + if (screen->is_format_supported(screen, PIPE_FORMAT_L8A8_SRGB, + target, bindings, geom_flags)) return PIPE_FORMAT_L8A8_SRGB; - return default_srgba_format( screen, target, tex_usage, geom_flags ); + return default_srgba_format( screen, target, bindings, geom_flags ); case GL_SLUMINANCE_EXT: case GL_SLUMINANCE8_EXT: - if (screen->is_format_supported( screen, PIPE_FORMAT_L8_SRGB, target, tex_usage, geom_flags )) + if (screen->is_format_supported(screen, PIPE_FORMAT_L8_SRGB, + target, bindings, geom_flags)) return PIPE_FORMAT_L8_SRGB; - return default_srgba_format( screen, target, tex_usage, geom_flags ); + return default_srgba_format( screen, target, bindings, geom_flags ); default: return PIPE_FORMAT_NONE; @@ -615,27 +660,6 @@ st_choose_format(struct pipe_screen *screen, GLenum internalFormat, } -static GLboolean -is_depth_or_stencil_format(GLenum internalFormat) -{ - switch (internalFormat) { - case GL_DEPTH_COMPONENT: - case GL_DEPTH_COMPONENT16: - case GL_DEPTH_COMPONENT24: - case GL_DEPTH_COMPONENT32: - case GL_STENCIL_INDEX: - case GL_STENCIL_INDEX1_EXT: - case GL_STENCIL_INDEX4_EXT: - case GL_STENCIL_INDEX8_EXT: - case GL_STENCIL_INDEX16_EXT: - case GL_DEPTH_STENCIL_EXT: - case GL_DEPTH24_STENCIL8_EXT: - return GL_TRUE; - default: - return GL_FALSE; - } -} - /** * Called by FBO code to choose a PIPE_FORMAT_ for drawing surfaces. */ @@ -644,10 +668,10 @@ st_choose_renderbuffer_format(struct pipe_screen *screen, GLenum internalFormat) { uint usage; - if (is_depth_or_stencil_format(internalFormat)) - usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL; + if (_mesa_is_depth_or_stencil_format(internalFormat)) + usage = PIPE_BIND_DEPTH_STENCIL; else - usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; + usage = PIPE_BIND_RENDER_TARGET; return st_choose_format(screen, internalFormat, PIPE_TEXTURE_2D, usage); } @@ -659,15 +683,35 @@ gl_format st_ChooseTextureFormat(GLcontext *ctx, GLint internalFormat, GLenum format, GLenum type) { + struct pipe_screen *screen = st_context(ctx)->pipe->screen; enum pipe_format pFormat; + uint bindings; (void) format; (void) type; - pFormat = st_choose_format(ctx->st->pipe->screen, internalFormat, - PIPE_TEXTURE_2D, PIPE_TEXTURE_USAGE_SAMPLER); - if (pFormat == PIPE_FORMAT_NONE) + /* GL textures may wind up being render targets, but we don't know + * that in advance. Specify potential render target flags now. + */ + if (_mesa_is_depth_format(internalFormat) || + _mesa_is_depthstencil_format(internalFormat)) + bindings = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_DEPTH_STENCIL; + else + bindings = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET; + + pFormat = st_choose_format(screen, internalFormat, + PIPE_TEXTURE_2D, bindings); + + if (pFormat == PIPE_FORMAT_NONE) { + /* try choosing format again, this time without render target bindings */ + pFormat = st_choose_format(screen, internalFormat, + PIPE_TEXTURE_2D, PIPE_BIND_SAMPLER_VIEW); + } + + if (pFormat == PIPE_FORMAT_NONE) { + /* no luck at all */ return MESA_FORMAT_NONE; + } return st_pipe_format_to_mesa_format(pFormat); } diff --git a/src/mesa/state_tracker/st_framebuffer.c b/src/mesa/state_tracker/st_framebuffer.c deleted file mode 100644 index 1d35e8d6574..00000000000 --- a/src/mesa/state_tracker/st_framebuffer.c +++ /dev/null @@ -1,433 +0,0 @@ -/************************************************************************** - * - * Copyright 2003 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 "main/imports.h" -#include "main/buffers.h" -#include "main/context.h" -#include "main/framebuffer.h" -#include "main/renderbuffer.h" -#include "st_context.h" -#include "st_cb_fbo.h" -#include "st_public.h" -#include "pipe/p_defines.h" -#include "util/u_inlines.h" - - -struct st_framebuffer * -st_create_framebuffer( const __GLcontextModes *visual, - enum pipe_format colorFormat, - enum pipe_format depthFormat, - enum pipe_format stencilFormat, - uint width, uint height, - void *private) -{ - struct st_framebuffer *stfb = ST_CALLOC_STRUCT(st_framebuffer); - if (stfb) { - int samples = st_get_msaa(); - int i; - - if (visual->sampleBuffers) - samples = visual->samples; - - _mesa_initialize_window_framebuffer(&stfb->Base, visual); - - if (visual->doubleBufferMode) { - struct gl_renderbuffer *rb - = st_new_renderbuffer_fb(colorFormat, samples, FALSE); - _mesa_add_renderbuffer(&stfb->Base, BUFFER_BACK_LEFT, rb); - } - else { - /* Only allocate front buffer right now if we're single buffered. - * If double-buffered, allocate front buffer on demand later. - * See check_create_front_buffers() and st_set_framebuffer_surface(). - */ - struct gl_renderbuffer *rb - = st_new_renderbuffer_fb(colorFormat, samples, FALSE); - _mesa_add_renderbuffer(&stfb->Base, BUFFER_FRONT_LEFT, rb); - } - - if (depthFormat == stencilFormat && depthFormat != PIPE_FORMAT_NONE) { - /* combined depth/stencil buffer */ - struct gl_renderbuffer *depthStencilRb - = st_new_renderbuffer_fb(depthFormat, samples, FALSE); - /* note: bind RB to two attachment points */ - _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthStencilRb); - _mesa_add_renderbuffer(&stfb->Base, BUFFER_STENCIL, depthStencilRb); - } - else { - /* separate depth and/or stencil */ - - if (visual->depthBits == 32) { - /* 32-bit depth buffer */ - struct gl_renderbuffer *depthRb - = st_new_renderbuffer_fb(depthFormat, samples, 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(depthFormat, samples, 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(depthFormat, samples, FALSE); - _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, depthRb); - } - - if (visual->stencilBits > 0) { - /* 8-bit stencil */ - struct gl_renderbuffer *stencilRb - = st_new_renderbuffer_fb(stencilFormat, samples, FALSE); - _mesa_add_renderbuffer(&stfb->Base, BUFFER_STENCIL, stencilRb); - } - } - - if (visual->accumRedBits > 0) { - /* 16-bit/channel accum */ - /* TODO: query the pipe screen for accumulation buffer format support */ - struct gl_renderbuffer *accumRb - = st_new_renderbuffer_fb(PIPE_FORMAT_R16G16B16A16_SNORM, 0, TRUE); - _mesa_add_renderbuffer(&stfb->Base, BUFFER_ACCUM, accumRb); - } - - for (i = 0; i < visual->numAuxBuffers; i++) { - struct gl_renderbuffer *aux - = st_new_renderbuffer_fb(colorFormat, 0, FALSE); - _mesa_add_renderbuffer(&stfb->Base, BUFFER_AUX0 + i, aux); - } - - stfb->Base.Initialized = GL_TRUE; - stfb->InitWidth = width; - stfb->InitHeight = height; - stfb->Private = private; - } - return stfb; -} - - -void st_resize_framebuffer( struct st_framebuffer *stfb, - uint width, uint height ) -{ - if (stfb->Base.Width != width || stfb->Base.Height != height) { - GET_CURRENT_CONTEXT(ctx); - if (ctx) { - _mesa_check_init_viewport(ctx, width, height); - - _mesa_resize_framebuffer(ctx, &stfb->Base, width, height); - - assert(stfb->Base.Width == width); - assert(stfb->Base.Height == height); - } - } -} - - -void st_unreference_framebuffer( struct st_framebuffer *stfb ) -{ - _mesa_reference_framebuffer((struct gl_framebuffer **) &stfb, NULL); -} - - - -/** - * Set/replace a framebuffer surface. - * The user of the state tracker can use this instead of - * st_resize_framebuffer() to provide new surfaces when a window is resized. - * \param surfIndex an ST_SURFACE_x index - */ -void -st_set_framebuffer_surface(struct st_framebuffer *stfb, - uint surfIndex, struct pipe_surface *surf) -{ - GET_CURRENT_CONTEXT(ctx); - static const GLuint invalid_size = 9999999; - struct st_renderbuffer *strb; - GLuint width, height, i; - - /* sanity checks */ - assert(ST_SURFACE_FRONT_LEFT == BUFFER_FRONT_LEFT); - assert(ST_SURFACE_BACK_LEFT == BUFFER_BACK_LEFT); - assert(ST_SURFACE_FRONT_RIGHT == BUFFER_FRONT_RIGHT); - assert(ST_SURFACE_BACK_RIGHT == BUFFER_BACK_RIGHT); - assert(ST_SURFACE_DEPTH == BUFFER_DEPTH); - - assert(surfIndex < BUFFER_COUNT); - - strb = st_renderbuffer(stfb->Base.Attachment[surfIndex].Renderbuffer); - - if (!strb) { - if (surfIndex == ST_SURFACE_FRONT_LEFT) { - /* Delayed creation when the window system supplies a fake front buffer */ - struct st_renderbuffer *strb_back - = st_renderbuffer(stfb->Base.Attachment[ST_SURFACE_BACK_LEFT].Renderbuffer); - struct gl_renderbuffer *rb - = st_new_renderbuffer_fb(surf->format, strb_back->Base.NumSamples, FALSE); - _mesa_add_renderbuffer(&stfb->Base, BUFFER_FRONT_LEFT, rb); - strb = st_renderbuffer(rb); - } else { - /* fail */ - return; - } - } - - /* replace the renderbuffer's surface/texture pointers */ - pipe_surface_reference( &strb->surface, surf ); - pipe_texture_reference( &strb->texture, surf->texture ); - - if (ctx) { - /* If ctx isn't set, we've likely not made current yet. - * But when we do, we need to start setting this dirty bit - * to ensure the renderbuffer attachements are up-to-date - * via update_framebuffer. - */ - ctx->st->dirty.st |= ST_NEW_FRAMEBUFFER; - } - - /* update renderbuffer's width/height */ - strb->Base.Width = surf->width; - strb->Base.Height = surf->height; - - /* Try to update the framebuffer's width/height from the renderbuffer - * sizes. Before we start drawing, all the rbs _should_ be the same size. - */ - width = height = invalid_size; - for (i = 0; i < BUFFER_COUNT; i++) { - if (stfb->Base.Attachment[i].Renderbuffer) { - if (width == invalid_size) { - width = stfb->Base.Attachment[i].Renderbuffer->Width; - height = stfb->Base.Attachment[i].Renderbuffer->Height; - } - else if (width != stfb->Base.Attachment[i].Renderbuffer->Width || - height != stfb->Base.Attachment[i].Renderbuffer->Height) { - /* inconsistant renderbuffer sizes, bail out */ - return; - } - } - } - - if (width != invalid_size) { - /* OK, the renderbuffers are of a consistant size, so update the - * parent framebuffer's size. - */ - stfb->Base.Width = width; - stfb->Base.Height = height; - } -} - - - -/** - * Return the pipe_surface for the given renderbuffer. - */ -int -st_get_framebuffer_surface(struct st_framebuffer *stfb, uint surfIndex, struct pipe_surface **surface) -{ - struct st_renderbuffer *strb; - - assert(surfIndex <= ST_SURFACE_DEPTH); - - /* sanity checks, ST tokens should match Mesa tokens */ - assert(ST_SURFACE_FRONT_LEFT == BUFFER_FRONT_LEFT); - assert(ST_SURFACE_BACK_RIGHT == BUFFER_BACK_RIGHT); - - strb = st_renderbuffer(stfb->Base.Attachment[surfIndex].Renderbuffer); - if (strb) { - *surface = strb->surface; - return GL_TRUE; - } - - *surface = NULL; - return GL_FALSE; -} - -int -st_get_framebuffer_texture(struct st_framebuffer *stfb, uint surfIndex, struct pipe_texture **texture) -{ - struct st_renderbuffer *strb; - - assert(surfIndex <= ST_SURFACE_DEPTH); - - /* sanity checks, ST tokens should match Mesa tokens */ - assert(ST_SURFACE_FRONT_LEFT == BUFFER_FRONT_LEFT); - assert(ST_SURFACE_BACK_RIGHT == BUFFER_BACK_RIGHT); - - strb = st_renderbuffer(stfb->Base.Attachment[surfIndex].Renderbuffer); - if (strb) { - *texture = strb->texture; - return GL_TRUE; - } - - *texture = NULL; - return GL_FALSE; -} - -/** - * This function is to be called prior to SwapBuffers on the given - * framebuffer. It checks if the current context is bound to the framebuffer - * and flushes rendering if needed. - */ -void -st_notify_swapbuffers(struct st_framebuffer *stfb) -{ - GET_CURRENT_CONTEXT(ctx); - - if (ctx && ctx->DrawBuffer == &stfb->Base) { - st_flush( ctx->st, - PIPE_FLUSH_RENDER_CACHE | - PIPE_FLUSH_SWAPBUFFERS | - PIPE_FLUSH_FRAME, - NULL ); - if (st_renderbuffer(stfb->Base.Attachment[BUFFER_BACK_LEFT].Renderbuffer)) - ctx->st->frontbuffer_status = FRONT_STATUS_COPY_OF_BACK; - } -} - - -/** - * Swap the front/back color buffers. Exchange the front/back pointers - * and update some derived state. - * No need to call st_notify_swapbuffers() first. - * - * For a single-buffered framebuffer, no swap occurs, but we still return - * the pointer(s) to the front color buffer(s). - * - * \param front_left returns pointer to front-left renderbuffer after swap - * \param front_right returns pointer to front-right renderbuffer after swap - */ -void -st_swapbuffers(struct st_framebuffer *stfb, - struct pipe_surface **front_left, - struct pipe_surface **front_right) -{ - struct gl_framebuffer *fb = &stfb->Base; - - GET_CURRENT_CONTEXT(ctx); - - if (ctx && ctx->DrawBuffer == &stfb->Base) { - st_flush( ctx->st, - PIPE_FLUSH_RENDER_CACHE | - PIPE_FLUSH_SWAPBUFFERS | - PIPE_FLUSH_FRAME, - NULL ); - } - - if (!fb->Visual.doubleBufferMode) { - /* single buffer mode - return pointers to front surfaces */ - if (front_left) { - struct st_renderbuffer *strb = - st_renderbuffer(fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer); - *front_left = strb->surface; - } - if (front_right) { - struct st_renderbuffer *strb = - st_renderbuffer(fb->Attachment[BUFFER_FRONT_RIGHT].Renderbuffer); - *front_right = strb ? strb->surface : NULL; - } - return; - } - - /* swap left buffers */ - if (fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer && - fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer) { - struct gl_renderbuffer *rbTemp; - rbTemp = fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer; - fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer = - fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer; - fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer = rbTemp; - if (front_left) { - struct st_renderbuffer *strb = - st_renderbuffer(fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer); - *front_left = strb->surface; - } - /* mark back buffer contents as undefined */ - { - struct st_renderbuffer *back = - st_renderbuffer(fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer); - back->defined = GL_FALSE; - } - } - else { - /* no front buffer, display the back buffer */ - if (front_left) { - struct st_renderbuffer *strb = - st_renderbuffer(fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer); - *front_left = strb->surface; - } - } - - /* swap right buffers (for stereo) */ - if (fb->Attachment[BUFFER_FRONT_RIGHT].Renderbuffer && - fb->Attachment[BUFFER_BACK_RIGHT].Renderbuffer) { - struct gl_renderbuffer *rbTemp; - rbTemp = fb->Attachment[BUFFER_FRONT_RIGHT].Renderbuffer; - fb->Attachment[BUFFER_FRONT_RIGHT].Renderbuffer = - fb->Attachment[BUFFER_BACK_RIGHT].Renderbuffer; - fb->Attachment[BUFFER_BACK_RIGHT].Renderbuffer = rbTemp; - if (front_right) { - struct st_renderbuffer *strb = - st_renderbuffer(fb->Attachment[BUFFER_FRONT_RIGHT].Renderbuffer); - *front_right = strb->surface; - } - /* mark back buffer contents as undefined */ - { - struct st_renderbuffer *back = - st_renderbuffer(fb->Attachment[BUFFER_BACK_RIGHT].Renderbuffer); - back->defined = GL_FALSE; - } - } - else { - /* no front right buffer, display back right buffer (if exists) */ - if (front_right) { - struct st_renderbuffer *strb = - st_renderbuffer(fb->Attachment[BUFFER_BACK_RIGHT].Renderbuffer); - *front_right = strb ? strb->surface : NULL; - } - } - - /* Update the _ColorDrawBuffers[] array and _ColorReadBuffer pointer */ - _mesa_update_framebuffer(ctx); - - /* Make sure we draw into the new back surface */ - st_invalidate_state(ctx, _NEW_BUFFERS); -} - - -void *st_framebuffer_private( struct st_framebuffer *stfb ) -{ - return stfb->Private; -} - -void st_get_framebuffer_dimensions( struct st_framebuffer *stfb, - uint *width, - uint *height) -{ - *width = stfb->Base.Width; - *height = stfb->Base.Height; -} diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c index f67d7b4cb5c..b8b75c7de62 100644 --- a/src/mesa/state_tracker/st_gen_mipmap.c +++ b/src/mesa/state_tracker/st_gen_mipmap.c @@ -27,27 +27,19 @@ #include "main/imports.h" -#include "main/macros.h" #include "main/mipmap.h" #include "main/teximage.h" #include "main/texformat.h" -#include "shader/prog_instruction.h" - #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "util/u_inlines.h" #include "util/u_format.h" #include "util/u_gen_mipmap.h" -#include "util/u_math.h" - -#include "cso_cache/cso_cache.h" -#include "cso_cache/cso_context.h" #include "st_debug.h" #include "st_context.h" #include "st_gen_mipmap.h" -#include "st_texture.h" #include "st_cb_texture.h" #include "st_inlines.h" @@ -79,52 +71,106 @@ st_destroy_generate_mipmap(struct st_context *st) static boolean st_render_mipmap(struct st_context *st, GLenum target, - struct pipe_texture *pt, + struct st_texture_object *stObj, uint baseLevel, uint lastLevel) { struct pipe_context *pipe = st->pipe; struct pipe_screen *screen = pipe->screen; + struct pipe_sampler_view *psv = st_get_texture_sampler_view(stObj, pipe); const uint face = _mesa_tex_target_to_face(target); assert(target != GL_TEXTURE_3D); /* not done yet */ /* check if we can render in the texture's format */ - if (!screen->is_format_supported(screen, pt->format, pt->target, - PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) { + if (!screen->is_format_supported(screen, psv->format, psv->texture->target, + PIPE_BIND_RENDER_TARGET, 0)) { return FALSE; } - util_gen_mipmap(st->gen_mipmap, pt, face, baseLevel, lastLevel, + util_gen_mipmap(st->gen_mipmap, psv, face, baseLevel, lastLevel, PIPE_TEX_FILTER_LINEAR); return TRUE; } +/** + * Helper function to decompress an image. The result is a 32-bpp RGBA + * image with stride==width. + */ +static void +decompress_image(enum pipe_format format, + const uint8_t *src, uint8_t *dst, + unsigned width, unsigned height) +{ + const struct util_format_description *desc = util_format_description(format); + const uint dst_stride = 4 * width; + const uint src_stride = util_format_get_stride(format, width); + + desc->unpack_rgba_8unorm(dst, dst_stride, src, src_stride, width, height); +} + + +/** + * Helper function to compress an image. The source is a 32-bpp RGBA image + * with stride==width. + */ +static void +compress_image(enum pipe_format format, + const uint8_t *src, uint8_t *dst, + unsigned width, unsigned height) +{ + const struct util_format_description *desc = util_format_description(format); + const uint dst_stride = util_format_get_stride(format, width); + const uint src_stride = 4 * width; + + desc->pack_rgba_8unorm(dst, dst_stride, src, src_stride, width, height); +} + + +/** + * Software fallback for generate mipmap levels. + */ static void 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_texture *pt = st_get_texobj_texture(texObj); + struct pipe_context *pipe = st_context(ctx)->pipe; + struct pipe_resource *pt = st_get_texobj_resource(texObj); const uint baseLevel = texObj->BaseLevel; const uint lastLevel = pt->last_level; const uint face = _mesa_tex_target_to_face(target), zslice = 0; uint dstLevel; GLenum datatype; GLuint comps; + GLboolean compressed; if (ST_DEBUG & DEBUG_FALLBACK) debug_printf("%s: fallback processing\n", __FUNCTION__); assert(target != GL_TEXTURE_3D); /* not done yet */ - _mesa_format_to_type_and_comps(texObj->Image[face][baseLevel]->TexFormat, - &datatype, &comps); + compressed = + _mesa_is_format_compressed(texObj->Image[face][baseLevel]->TexFormat); + + if (compressed) { + datatype = GL_UNSIGNED_BYTE; + comps = 4; + } + else { + _mesa_format_to_type_and_comps(texObj->Image[face][baseLevel]->TexFormat, + &datatype, &comps); + assert(comps > 0 && "bad texture format in fallback_generate_mipmap()"); + } for (dstLevel = baseLevel + 1; dstLevel <= lastLevel; dstLevel++) { const uint srcLevel = dstLevel - 1; + const uint srcWidth = u_minify(pt->width0, srcLevel); + const uint srcHeight = u_minify(pt->height0, srcLevel); + const uint srcDepth = u_minify(pt->depth0, srcLevel); + const uint dstWidth = u_minify(pt->width0, dstLevel); + const uint dstHeight = u_minify(pt->height0, dstLevel); + const uint dstDepth = u_minify(pt->depth0, dstLevel); struct pipe_transfer *srcTrans, *dstTrans; const ubyte *srcData; ubyte *dstData; @@ -133,39 +179,69 @@ fallback_generate_mipmap(GLcontext *ctx, GLenum target, srcTrans = st_cond_flush_get_tex_transfer(st_context(ctx), pt, face, srcLevel, zslice, PIPE_TRANSFER_READ, 0, 0, - u_minify(pt->width0, srcLevel), - u_minify(pt->height0, srcLevel)); + srcWidth, srcHeight); + dstTrans = st_cond_flush_get_tex_transfer(st_context(ctx), pt, face, dstLevel, zslice, PIPE_TRANSFER_WRITE, 0, 0, - u_minify(pt->width0, dstLevel), - u_minify(pt->height0, dstLevel)); - - srcData = (ubyte *) screen->transfer_map(screen, srcTrans); - dstData = (ubyte *) screen->transfer_map(screen, dstTrans); - - srcStride = srcTrans->stride / util_format_get_blocksize(srcTrans->texture->format); - dstStride = dstTrans->stride / util_format_get_blocksize(dstTrans->texture->format); - - _mesa_generate_mipmap_level(target, datatype, comps, - 0 /*border*/, - u_minify(pt->width0, srcLevel), - u_minify(pt->height0, srcLevel), - u_minify(pt->depth0, srcLevel), - srcData, - srcStride, /* stride in texels */ - u_minify(pt->width0, dstLevel), - u_minify(pt->height0, dstLevel), - u_minify(pt->depth0, dstLevel), - dstData, - dstStride); /* stride in texels */ - - screen->transfer_unmap(screen, srcTrans); - screen->transfer_unmap(screen, dstTrans); - - screen->tex_transfer_destroy(srcTrans); - screen->tex_transfer_destroy(dstTrans); + dstWidth, dstHeight); + + srcData = (ubyte *) pipe_transfer_map(pipe, srcTrans); + dstData = (ubyte *) pipe_transfer_map(pipe, dstTrans); + + srcStride = srcTrans->stride / util_format_get_blocksize(srcTrans->resource->format); + dstStride = dstTrans->stride / util_format_get_blocksize(dstTrans->resource->format); + + if (compressed) { + const enum pipe_format format = pt->format; + const uint bw = util_format_get_blockwidth(format); + const uint bh = util_format_get_blockheight(format); + const uint srcWidth2 = align(srcWidth, bw); + const uint srcHeight2 = align(srcHeight, bh); + const uint dstWidth2 = align(dstWidth, bw); + const uint dstHeight2 = align(dstHeight, bh); + uint8_t *srcTemp, *dstTemp; + + assert(comps == 4); + + srcTemp = malloc(srcWidth2 * srcHeight2 * comps + 000); + dstTemp = malloc(dstWidth2 * dstHeight2 * comps + 000); + + /* decompress the src image: srcData -> srcTemp */ + decompress_image(format, srcData, srcTemp, srcWidth, srcHeight); + + _mesa_generate_mipmap_level(target, datatype, comps, + 0 /*border*/, + srcWidth2, srcHeight2, srcDepth, + srcTemp, + srcWidth2, /* stride in texels */ + dstWidth2, dstHeight2, dstDepth, + dstTemp, + dstWidth2); /* stride in texels */ + + /* compress the new image: dstTemp -> dstData */ + compress_image(format, dstTemp, dstData, dstWidth2, dstHeight2); + + free(srcTemp); + free(dstTemp); + } + else { + _mesa_generate_mipmap_level(target, datatype, comps, + 0 /*border*/, + srcWidth, srcHeight, srcDepth, + srcData, + srcStride, /* stride in texels */ + dstWidth, dstHeight, dstDepth, + dstData, + dstStride); /* stride in texels */ + } + + pipe_transfer_unmap(pipe, srcTrans); + pipe_transfer_unmap(pipe, dstTrans); + + pipe->transfer_destroy(pipe, srcTrans); + pipe->transfer_destroy(pipe, dstTrans); } } @@ -174,7 +250,7 @@ fallback_generate_mipmap(GLcontext *ctx, GLenum target, * Compute the expected number of mipmap levels in the texture given * the width/height/depth of the base image and the GL_TEXTURE_BASE_LEVEL/ * GL_TEXTURE_MAX_LEVEL settings. This will tell us how many mipmap - * level should be generated. + * levels should be generated. */ static GLuint compute_num_levels(GLcontext *ctx, @@ -207,12 +283,16 @@ compute_num_levels(GLcontext *ctx, } +/** + * Called via ctx->Driver.GenerateMipmap(). + */ void st_generate_mipmap(GLcontext *ctx, GLenum target, struct gl_texture_object *texObj) { - struct st_context *st = ctx->st; - struct pipe_texture *pt = st_get_texobj_texture(texObj); + struct st_context *st = st_context(ctx); + struct st_texture_object *stObj = st_texture_object(texObj); + struct pipe_resource *pt = st_get_texobj_resource(texObj); const uint baseLevel = texObj->BaseLevel; uint lastLevel; uint dstLevel; @@ -230,8 +310,7 @@ st_generate_mipmap(GLcontext *ctx, GLenum target, /* The current gallium texture doesn't have space for all the * mipmap levels we need to generate. So allocate a new texture. */ - struct st_texture_object *stObj = st_texture_object(texObj); - struct pipe_texture *oldTex = stObj->pt; + struct pipe_resource *oldTex = stObj->pt; GLboolean needFlush; /* create new texture with space for more levels */ @@ -242,7 +321,7 @@ st_generate_mipmap(GLcontext *ctx, GLenum target, oldTex->width0, oldTex->height0, oldTex->depth0, - oldTex->tex_usage); + oldTex->bind); /* The texture isn't in a "complete" state yet so set the expected * lastLevel here, since it won't get done in st_finalize_texture(). @@ -255,7 +334,8 @@ st_generate_mipmap(GLcontext *ctx, GLenum target, st_finalize_texture(ctx, st->pipe, texObj, &needFlush); /* release the old tex (will likely be freed too) */ - pipe_texture_reference(&oldTex, NULL); + pipe_resource_reference(&oldTex, NULL); + pipe_sampler_view_reference(&stObj->sampler_view, NULL); pt = stObj->pt; } @@ -265,7 +345,7 @@ st_generate_mipmap(GLcontext *ctx, GLenum target, /* Recall that the Mesa BaseLevel image is stored in the gallium * texture's level[0] position. So pass baseLevel=0 here. */ - if (!st_render_mipmap(st, target, pt, 0, lastLevel)) { + if (!st_render_mipmap(st, target, stObj, 0, lastLevel)) { fallback_generate_mipmap(ctx, target, texObj); } @@ -297,7 +377,9 @@ st_generate_mipmap(GLcontext *ctx, GLenum target, dstImage->TexFormat = srcImage->TexFormat; - stImage = (struct st_texture_image *) dstImage; - pipe_texture_reference(&stImage->pt, pt); + stImage = st_texture_image(dstImage); + stImage->level = dstLevel; + + pipe_resource_reference(&stImage->pt, pt); } } diff --git a/src/mesa/state_tracker/st_gl_api.h b/src/mesa/state_tracker/st_gl_api.h new file mode 100644 index 00000000000..52c3fa0b417 --- /dev/null +++ b/src/mesa/state_tracker/st_gl_api.h @@ -0,0 +1,9 @@ + +#ifndef ST_GL_API_H +#define ST_GL_API_H + +#include "state_tracker/st_api.h" + +struct st_api * st_gl_api_create(void); + +#endif diff --git a/src/mesa/state_tracker/st_inlines.h b/src/mesa/state_tracker/st_inlines.h index e105870bc75..3bf7ba185e5 100644 --- a/src/mesa/state_tracker/st_inlines.h +++ b/src/mesa/state_tracker/st_inlines.h @@ -37,15 +37,16 @@ #include "pipe/p_screen.h" #include "pipe/p_defines.h" #include "util/u_inlines.h" +#include "util/u_box.h" #include "pipe/p_state.h" #include "st_context.h" #include "st_texture.h" -#include "st_public.h" +#include "st_cb_flush.h" static INLINE struct pipe_transfer * st_cond_flush_get_tex_transfer(struct st_context *st, - struct pipe_texture *pt, + struct pipe_resource *pt, unsigned int face, unsigned int level, unsigned int zslice, @@ -53,16 +54,27 @@ st_cond_flush_get_tex_transfer(struct st_context *st, unsigned int x, unsigned int y, unsigned int w, unsigned int h) { - struct pipe_screen *screen = st->pipe->screen; + struct pipe_context *context = st->pipe; + struct pipe_subresource subresource; + struct pipe_box box; + + subresource.face = face; + subresource.level = level; + + u_box_2d_zslice(x, y, zslice, w, h, &box); st_teximage_flush_before_map(st, pt, face, level, usage); - return screen->get_tex_transfer(screen, pt, face, level, zslice, usage, - x, y, w, h); + + return context->get_transfer(context, + pt, + subresource, + usage, + &box); } static INLINE struct pipe_transfer * st_no_flush_get_tex_transfer(struct st_context *st, - struct pipe_texture *pt, + struct pipe_resource *pt, unsigned int face, unsigned int level, unsigned int zslice, @@ -70,94 +82,77 @@ st_no_flush_get_tex_transfer(struct st_context *st, unsigned int x, unsigned int y, unsigned int w, unsigned int h) { - struct pipe_screen *screen = st->pipe->screen; - - return screen->get_tex_transfer(screen, pt, face, level, - zslice, usage, x, y, w, h); -} - -static INLINE void * -st_cond_flush_pipe_buffer_map(struct st_context *st, - struct pipe_buffer *buf, - unsigned int map_flags) -{ - struct pipe_context *pipe = st->pipe; - unsigned int referenced = pipe->is_buffer_referenced(pipe, buf); - - if (referenced && ((referenced & PIPE_REFERENCED_FOR_WRITE) || - (map_flags & PIPE_BUFFER_USAGE_CPU_WRITE))) - st_flush(st, PIPE_FLUSH_RENDER_CACHE, NULL); - - return pipe_buffer_map(pipe->screen, buf, map_flags); -} - -static INLINE void * -st_no_flush_pipe_buffer_map(struct st_context *st, - struct pipe_buffer *buf, - unsigned int map_flags) -{ - return pipe_buffer_map(st->pipe->screen, buf, map_flags); + struct pipe_context *context = st->pipe; + struct pipe_box box; + struct pipe_subresource subresource = u_subresource( face, level ); + + u_box_2d_zslice( x, y, zslice, + w, h, + &box ); + + return context->get_transfer(context, + pt, + subresource, + usage, + &box); } static INLINE void st_cond_flush_pipe_buffer_write(struct st_context *st, - struct pipe_buffer *buf, + struct pipe_resource *buf, unsigned int offset, unsigned int size, const void * data) { struct pipe_context *pipe = st->pipe; - if (pipe->is_buffer_referenced(pipe, buf)) - st_flush(st, PIPE_FLUSH_RENDER_CACHE, NULL); - - pipe_buffer_write(pipe->screen, buf, offset, size, data); + pipe_buffer_write(pipe, buf, offset, size, data); } static INLINE void st_no_flush_pipe_buffer_write(struct st_context *st, - struct pipe_buffer *buf, + struct pipe_resource *buf, unsigned int offset, unsigned int size, const void * data) { - pipe_buffer_write(st->pipe->screen, buf, offset, size, data); + pipe_buffer_write(st->pipe, buf, offset, size, data); } static INLINE void st_no_flush_pipe_buffer_write_nooverlap(struct st_context *st, - struct pipe_buffer *buf, + struct pipe_resource *buf, unsigned int offset, unsigned int size, const void * data) { - pipe_buffer_write_nooverlap(st->pipe->screen, buf, offset, size, data); + pipe_buffer_write_nooverlap(st->pipe, buf, offset, size, data); } static INLINE void st_cond_flush_pipe_buffer_read(struct st_context *st, - struct pipe_buffer *buf, + struct pipe_resource *buf, unsigned int offset, unsigned int size, void * data) { struct pipe_context *pipe = st->pipe; - if (pipe->is_buffer_referenced(pipe, buf) & PIPE_REFERENCED_FOR_WRITE) + if (pipe->is_resource_referenced(pipe, buf, 0, 0) & PIPE_REFERENCED_FOR_WRITE) st_flush(st, PIPE_FLUSH_RENDER_CACHE, NULL); - pipe_buffer_read(pipe->screen, buf, offset, size, data); + pipe_buffer_read(pipe, buf, offset, size, data); } static INLINE void st_no_flush_pipe_buffer_read(struct st_context *st, - struct pipe_buffer *buf, + struct pipe_resource *buf, unsigned int offset, unsigned int size, void * data) { - pipe_buffer_read(st->pipe->screen, buf, offset, size, data); + pipe_buffer_read(st->pipe, buf, offset, size, data); } #endif diff --git a/src/mesa/state_tracker/st_manager.c b/src/mesa/state_tracker/st_manager.c new file mode 100644 index 00000000000..44d59d44763 --- /dev/null +++ b/src/mesa/state_tracker/st_manager.c @@ -0,0 +1,811 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * 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, sublicense, + * 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 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 NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS 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: + * Chia-I Wu <[email protected]> + */ + +#include "state_tracker/st_gl_api.h" + +#include "pipe/p_context.h" +#include "pipe/p_screen.h" +#include "util/u_format.h" +#include "util/u_pointer.h" +#include "util/u_inlines.h" +#include "util/u_atomic.h" + +#include "main/mtypes.h" +#include "main/context.h" +#include "main/texobj.h" +#include "main/teximage.h" +#include "main/texstate.h" +#include "main/texfetch.h" +#include "main/framebuffer.h" +#include "main/renderbuffer.h" +#include "st_texture.h" + +#include "st_context.h" +#include "st_format.h" +#include "st_cb_fbo.h" +#include "st_manager.h" + +/* these functions are defined in st_context.c */ +struct st_context * +st_create_context(struct pipe_context *pipe, + const __GLcontextModes *visual, + struct st_context *share); +void st_destroy_context(struct st_context *st); +void st_flush(struct st_context *st, uint pipeFlushFlags, + struct pipe_fence_handle **fence); + +/** + * Cast wrapper to convert a GLframebuffer to an st_framebuffer. + * Return NULL if the GLframebuffer is a user-created framebuffer. + * We'll only return non-null for window system framebuffers. + * Note that this function may fail. + */ +static INLINE struct st_framebuffer * +st_ws_framebuffer(GLframebuffer *fb) +{ + /* FBO cannot be casted. See st_new_framebuffer */ + return (struct st_framebuffer *) ((fb && !fb->Name) ? fb : NULL); +} + +/** + * Map an attachment to a buffer index. + */ +static INLINE gl_buffer_index +attachment_to_buffer_index(enum st_attachment_type statt) +{ + gl_buffer_index index; + + switch (statt) { + case ST_ATTACHMENT_FRONT_LEFT: + index = BUFFER_FRONT_LEFT; + break; + case ST_ATTACHMENT_BACK_LEFT: + index = BUFFER_BACK_LEFT; + break; + case ST_ATTACHMENT_FRONT_RIGHT: + index = BUFFER_FRONT_RIGHT; + break; + case ST_ATTACHMENT_BACK_RIGHT: + index = BUFFER_BACK_RIGHT; + break; + case ST_ATTACHMENT_DEPTH_STENCIL: + index = BUFFER_DEPTH; + break; + case ST_ATTACHMENT_ACCUM: + index = BUFFER_ACCUM; + break; + case ST_ATTACHMENT_SAMPLE: + default: + index = BUFFER_COUNT; + break; + } + + return index; +} + +/** + * Map a buffer index to an attachment. + */ +static INLINE enum st_attachment_type +buffer_index_to_attachment(gl_buffer_index index) +{ + enum st_attachment_type statt; + + switch (index) { + case BUFFER_FRONT_LEFT: + statt = ST_ATTACHMENT_FRONT_LEFT; + break; + case BUFFER_BACK_LEFT: + statt = ST_ATTACHMENT_BACK_LEFT; + break; + case BUFFER_FRONT_RIGHT: + statt = ST_ATTACHMENT_FRONT_RIGHT; + break; + case BUFFER_BACK_RIGHT: + statt = ST_ATTACHMENT_BACK_RIGHT; + break; + case BUFFER_DEPTH: + statt = ST_ATTACHMENT_DEPTH_STENCIL; + break; + case BUFFER_ACCUM: + statt = ST_ATTACHMENT_ACCUM; + break; + default: + statt = ST_ATTACHMENT_INVALID; + break; + } + + return statt; +} + +/** + * Validate a framebuffer to make sure up-to-date pipe_textures are used. + */ +static void +st_framebuffer_validate(struct st_framebuffer *stfb, struct st_context *st) +{ + struct pipe_screen *screen = st->pipe->screen; + struct pipe_resource *textures[ST_ATTACHMENT_COUNT]; + uint width, height; + unsigned i; + boolean changed = FALSE; + + if (!p_atomic_read(&stfb->revalidate)) + return; + + /* validate the fb */ + if (!stfb->iface->validate(stfb->iface, stfb->statts, stfb->num_statts, textures)) + return; + + width = stfb->Base.Width; + height = stfb->Base.Height; + + for (i = 0; i < stfb->num_statts; i++) { + struct st_renderbuffer *strb; + struct pipe_surface *ps; + gl_buffer_index idx; + + if (!textures[i]) + continue; + + idx = attachment_to_buffer_index(stfb->statts[i]); + if (idx >= BUFFER_COUNT) { + pipe_resource_reference(&textures[i], NULL); + continue; + } + + strb = st_renderbuffer(stfb->Base.Attachment[idx].Renderbuffer); + assert(strb); + if (strb->texture == textures[i]) { + pipe_resource_reference(&textures[i], NULL); + continue; + } + + ps = screen->get_tex_surface(screen, textures[i], 0, 0, 0, + PIPE_BIND_RENDER_TARGET); + if (ps) { + pipe_surface_reference(&strb->surface, ps); + pipe_resource_reference(&strb->texture, ps->texture); + /* ownership transfered */ + pipe_surface_reference(&ps, NULL); + + changed = TRUE; + + strb->Base.Width = strb->surface->width; + strb->Base.Height = strb->surface->height; + + width = strb->Base.Width; + height = strb->Base.Height; + } + + pipe_resource_reference(&textures[i], NULL); + } + + if (changed) { + st->dirty.st |= ST_NEW_FRAMEBUFFER; + _mesa_resize_framebuffer(st->ctx, &stfb->Base, width, height); + + assert(stfb->Base.Width == width); + assert(stfb->Base.Height == height); + } + + p_atomic_set(&stfb->revalidate, FALSE); +} + +/** + * Update the attachments to validate by looping the existing renderbuffers. + */ +static void +st_framebuffer_update_attachments(struct st_framebuffer *stfb) +{ + gl_buffer_index idx; + + stfb->num_statts = 0; + for (idx = 0; idx < BUFFER_COUNT; idx++) { + struct st_renderbuffer *strb; + enum st_attachment_type statt; + + strb = st_renderbuffer(stfb->Base.Attachment[idx].Renderbuffer); + if (!strb || strb->software) + continue; + + statt = buffer_index_to_attachment(idx); + if (statt != ST_ATTACHMENT_INVALID && + st_visual_have_buffers(stfb->iface->visual, 1 << statt)) + stfb->statts[stfb->num_statts++] = statt; + } + + p_atomic_set(&stfb->revalidate, TRUE); +} + +/** + * Add a renderbuffer to the framebuffer. + */ +static boolean +st_framebuffer_add_renderbuffer(struct st_framebuffer *stfb, + gl_buffer_index idx) +{ + struct gl_renderbuffer *rb; + enum pipe_format format; + int samples; + boolean sw; + + /* do not distinguish depth/stencil buffers */ + if (idx == BUFFER_STENCIL) + idx = BUFFER_DEPTH; + + switch (idx) { + case BUFFER_DEPTH: + format = stfb->iface->visual->depth_stencil_format; + sw = FALSE; + break; + case BUFFER_ACCUM: + format = stfb->iface->visual->accum_format; + sw = TRUE; + break; + default: + format = stfb->iface->visual->color_format; + sw = FALSE; + break; + } + + if (format == PIPE_FORMAT_NONE) + return FALSE; + + samples = stfb->iface->visual->samples; + if (!samples) + samples = st_get_msaa(); + + rb = st_new_renderbuffer_fb(format, samples, sw); + if (!rb) + return FALSE; + + if (idx != BUFFER_DEPTH) { + _mesa_add_renderbuffer(&stfb->Base, idx, rb); + } + else { + if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_ZS, 0)) + _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, rb); + if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_ZS, 1)) + _mesa_add_renderbuffer(&stfb->Base, BUFFER_STENCIL, rb); + } + + return TRUE; +} + +/** + * Intialize a __GLcontextModes from a visual. + */ +static void +st_visual_to_context_mode(const struct st_visual *visual, + __GLcontextModes *mode) +{ + memset(mode, 0, sizeof(*mode)); + + if (st_visual_have_buffers(visual, ST_ATTACHMENT_BACK_LEFT_MASK)) + mode->doubleBufferMode = GL_TRUE; + if (st_visual_have_buffers(visual, + ST_ATTACHMENT_FRONT_RIGHT_MASK | ST_ATTACHMENT_BACK_RIGHT_MASK)) + mode->stereoMode = GL_TRUE; + + if (visual->color_format != PIPE_FORMAT_NONE) { + mode->rgbMode = GL_TRUE; + + mode->redBits = + util_format_get_component_bits(visual->color_format, + UTIL_FORMAT_COLORSPACE_RGB, 0); + mode->greenBits = + util_format_get_component_bits(visual->color_format, + UTIL_FORMAT_COLORSPACE_RGB, 1); + mode->blueBits = + util_format_get_component_bits(visual->color_format, + UTIL_FORMAT_COLORSPACE_RGB, 2); + mode->alphaBits = + util_format_get_component_bits(visual->color_format, + UTIL_FORMAT_COLORSPACE_RGB, 3); + + mode->rgbBits = mode->redBits + + mode->greenBits + mode->blueBits + mode->alphaBits; + } + + if (visual->depth_stencil_format != PIPE_FORMAT_NONE) { + mode->depthBits = + util_format_get_component_bits(visual->depth_stencil_format, + UTIL_FORMAT_COLORSPACE_ZS, 0); + mode->stencilBits = + util_format_get_component_bits(visual->depth_stencil_format, + UTIL_FORMAT_COLORSPACE_ZS, 1); + + mode->haveDepthBuffer = mode->depthBits > 0; + mode->haveStencilBuffer = mode->stencilBits > 0; + } + + if (visual->accum_format != PIPE_FORMAT_NONE) { + mode->haveAccumBuffer = GL_TRUE; + + mode->accumRedBits = + util_format_get_component_bits(visual->accum_format, + UTIL_FORMAT_COLORSPACE_RGB, 0); + mode->accumGreenBits = + util_format_get_component_bits(visual->accum_format, + UTIL_FORMAT_COLORSPACE_RGB, 1); + mode->accumBlueBits = + util_format_get_component_bits(visual->accum_format, + UTIL_FORMAT_COLORSPACE_RGB, 2); + mode->accumAlphaBits = + util_format_get_component_bits(visual->accum_format, + UTIL_FORMAT_COLORSPACE_RGB, 3); + } + + if (visual->samples) { + mode->sampleBuffers = 1; + mode->samples = visual->samples; + } +} + +/** + * Determine the default draw or read buffer from a visual. + */ +static void +st_visual_to_default_buffer(const struct st_visual *visual, + GLenum *buffer, GLint *index) +{ + enum st_attachment_type statt; + GLenum buf; + gl_buffer_index idx; + + statt = visual->render_buffer; + /* do nothing if an invalid render buffer is specified */ + if (statt == ST_ATTACHMENT_INVALID || + !st_visual_have_buffers(visual, 1 << statt)) + return; + + switch (statt) { + case ST_ATTACHMENT_FRONT_LEFT: + buf = GL_FRONT_LEFT; + idx = BUFFER_FRONT_LEFT; + break; + case ST_ATTACHMENT_BACK_LEFT: + buf = GL_BACK_LEFT; + idx = BUFFER_BACK_LEFT; + break; + case ST_ATTACHMENT_FRONT_RIGHT: + buf = GL_FRONT_RIGHT; + idx = BUFFER_FRONT_RIGHT; + break; + case ST_ATTACHMENT_BACK_RIGHT: + buf = GL_BACK_RIGHT; + idx = BUFFER_BACK_RIGHT; + break; + default: + buf = GL_NONE; + idx = BUFFER_COUNT; + break; + } + + if (buf != GL_NONE) { + if (buffer) + *buffer = buf; + if (index) + *index = idx; + } +} + +/** + * Create a framebuffer from a manager interface. + */ +static struct st_framebuffer * +st_framebuffer_create(struct st_framebuffer_iface *stfbi) +{ + struct st_framebuffer *stfb; + __GLcontextModes mode; + gl_buffer_index idx; + + stfb = CALLOC_STRUCT(st_framebuffer); + if (!stfb) + return NULL; + + st_visual_to_context_mode(stfbi->visual, &mode); + _mesa_initialize_window_framebuffer(&stfb->Base, &mode); + + /* modify the draw/read buffers of the fb */ + st_visual_to_default_buffer(stfbi->visual, &stfb->Base.ColorDrawBuffer[0], + &stfb->Base._ColorDrawBufferIndexes[0]); + st_visual_to_default_buffer(stfbi->visual, &stfb->Base.ColorReadBuffer, + &stfb->Base._ColorReadBufferIndex); + + stfb->iface = stfbi; + + /* add the color buffer */ + idx = stfb->Base._ColorDrawBufferIndexes[0]; + if (!st_framebuffer_add_renderbuffer(stfb, idx)) { + FREE(stfb); + return NULL; + } + + st_framebuffer_add_renderbuffer(stfb, BUFFER_DEPTH); + st_framebuffer_add_renderbuffer(stfb, BUFFER_ACCUM); + + st_framebuffer_update_attachments(stfb); + + stfb->Base.Initialized = GL_TRUE; + + return stfb; +} + +/** + * Reference a framebuffer. + */ +static void +st_framebuffer_reference(struct st_framebuffer **ptr, + struct st_framebuffer *stfb) +{ + GLframebuffer *fb = &stfb->Base; + _mesa_reference_framebuffer((GLframebuffer **) ptr, fb); +} + +static void +st_context_notify_invalid_framebuffer(struct st_context_iface *stctxi, + struct st_framebuffer_iface *stfbi) +{ + struct st_context *st = (struct st_context *) stctxi; + struct st_framebuffer *stfb; + + /* either draw or read winsys fb */ + stfb = st_ws_framebuffer(st->ctx->WinSysDrawBuffer); + if (!stfb || stfb->iface != stfbi) + stfb = st_ws_framebuffer(st->ctx->WinSysReadBuffer); + assert(stfb && stfb->iface == stfbi); + + p_atomic_set(&stfb->revalidate, TRUE); +} + +static void +st_context_flush(struct st_context_iface *stctxi, unsigned flags, + struct pipe_fence_handle **fence) +{ + struct st_context *st = (struct st_context *) stctxi; + st_flush(st, flags, fence); + if (flags & PIPE_FLUSH_RENDER_CACHE) + st_manager_flush_frontbuffer(st); +} + +static boolean +st_context_teximage(struct st_context_iface *stctxi, enum st_texture_type target, + int level, enum pipe_format internal_format, + struct pipe_resource *tex, boolean mipmap) +{ + struct st_context *st = (struct st_context *) stctxi; + GLcontext *ctx = st->ctx; + struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx); + struct gl_texture_object *texObj; + struct gl_texture_image *texImage; + struct st_texture_object *stObj; + struct st_texture_image *stImage; + GLenum internalFormat; + + switch (target) { + case ST_TEXTURE_1D: + target = GL_TEXTURE_1D; + break; + case ST_TEXTURE_2D: + target = GL_TEXTURE_2D; + break; + case ST_TEXTURE_3D: + target = GL_TEXTURE_3D; + break; + case ST_TEXTURE_RECT: + target = GL_TEXTURE_RECTANGLE_ARB; + break; + default: + return FALSE; + break; + } + + if (util_format_get_component_bits(internal_format, + UTIL_FORMAT_COLORSPACE_RGB, 3) > 0) + internalFormat = GL_RGBA; + else + internalFormat = GL_RGB; + + texObj = _mesa_select_tex_object(ctx, texUnit, target); + _mesa_lock_texture(ctx, texObj); + + stObj = st_texture_object(texObj); + /* switch to surface based */ + if (!stObj->surface_based) { + _mesa_clear_texture_object(ctx, texObj); + stObj->surface_based = GL_TRUE; + } + + texImage = _mesa_get_tex_image(ctx, texObj, target, level); + stImage = st_texture_image(texImage); + if (tex) { + _mesa_init_teximage_fields(ctx, target, texImage, + tex->width0, tex->height0, 1, 0, internalFormat); + texImage->TexFormat = st_ChooseTextureFormat(ctx, internalFormat, + GL_RGBA, GL_UNSIGNED_BYTE); + _mesa_set_fetch_functions(texImage, 2); + } + else { + _mesa_clear_texture_image(ctx, texImage); + } + + pipe_resource_reference(&stImage->pt, tex); + + _mesa_dirty_texobj(ctx, texObj, GL_TRUE); + _mesa_unlock_texture(ctx, texObj); + + return TRUE; +} + +static void +st_context_destroy(struct st_context_iface *stctxi) +{ + struct st_context *st = (struct st_context *) stctxi; + st_destroy_context(st); +} + +static struct st_context_iface * +st_api_create_context(struct st_api *stapi, struct st_manager *smapi, + const struct st_visual *visual, + struct st_context_iface *shared_stctxi) +{ + struct st_context *shared_ctx = (struct st_context *) shared_stctxi; + struct st_context *st; + struct pipe_context *pipe; + __GLcontextModes mode; + + pipe = smapi->screen->context_create(smapi->screen, NULL); + if (!pipe) + return NULL; + + st_visual_to_context_mode(visual, &mode); + st = st_create_context(pipe, &mode, shared_ctx); + if (!st) { + pipe->destroy(pipe); + return NULL; + } + + st->iface.destroy = st_context_destroy; + + st->iface.notify_invalid_framebuffer = + st_context_notify_invalid_framebuffer; + st->iface.flush = st_context_flush; + + st->iface.teximage = st_context_teximage; + st->iface.copy = NULL; + + st->iface.st_context_private = (void *) smapi; + + return &st->iface; +} + +static boolean +st_api_make_current(struct st_api *stapi, struct st_context_iface *stctxi, + struct st_framebuffer_iface *stdrawi, + struct st_framebuffer_iface *streadi) +{ + struct st_context *st = (struct st_context *) stctxi; + struct st_framebuffer *stdraw, *stread, *stfb; + boolean ret; + + _glapi_check_multithread(); + + if (st) { + /* reuse/create the draw fb */ + stfb = st_ws_framebuffer(st->ctx->WinSysDrawBuffer); + if (stfb && stfb->iface == stdrawi) { + stdraw = NULL; + st_framebuffer_reference(&stdraw, stfb); + } + else { + stdraw = st_framebuffer_create(stdrawi); + } + + /* reuse/create the read fb */ + stfb = st_ws_framebuffer(st->ctx->WinSysReadBuffer); + if (!stfb || stfb->iface != streadi) + stfb = stdraw; + if (stfb && stfb->iface == streadi) { + stread = NULL; + st_framebuffer_reference(&stread, stfb); + } + else { + stread = st_framebuffer_create(streadi); + } + + if (stdraw && stread) { + st_framebuffer_validate(stdraw, st); + if (stread != stdraw) + st_framebuffer_validate(stread, st); + + /* modify the draw/read buffers of the context */ + st_visual_to_default_buffer(stdraw->iface->visual, + &st->ctx->Color.DrawBuffer[0], NULL); + st_visual_to_default_buffer(stread->iface->visual, + &st->ctx->Pixel.ReadBuffer, NULL); + + ret = _mesa_make_current(st->ctx, &stdraw->Base, &stread->Base); + } + else { + ret = FALSE; + } + + st_framebuffer_reference(&stdraw, NULL); + st_framebuffer_reference(&stread, NULL); + } + else { + ret = _mesa_make_current(NULL, NULL, NULL); + } + + return ret; +} + +static struct st_context_iface * +st_api_get_current(struct st_api *stapi) +{ + GET_CURRENT_CONTEXT(ctx); + struct st_context *st = (ctx) ? ctx->st : NULL; + + return (st) ? &st->iface : NULL; +} + +static boolean +st_api_is_visual_supported(struct st_api *stapi, + const struct st_visual *visual) +{ + return TRUE; +} + +static st_proc_t +st_api_get_proc_address(struct st_api *stapi, const char *procname) +{ + return (st_proc_t) _glapi_get_proc_address(procname); +} + +static void +st_api_destroy(struct st_api *stapi) +{ +} + +/** + * Flush the front buffer if the current context renders to the front buffer. + */ +void +st_manager_flush_frontbuffer(struct st_context *st) +{ + struct st_framebuffer *stfb = st_ws_framebuffer(st->ctx->DrawBuffer); + struct st_renderbuffer *strb = NULL; + + if (stfb) + strb = st_renderbuffer(stfb->Base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer); + if (!strb) + return; + + stfb->iface->flush_front(stfb->iface, ST_ATTACHMENT_FRONT_LEFT); +} + +/** + * Return the surface of an EGLImage. + */ +struct pipe_surface * +st_manager_get_egl_image_surface(struct st_context *st, + void *eglimg, unsigned usage) +{ + struct st_manager *smapi = + (struct st_manager *) st->iface.st_context_private; + struct st_egl_image stimg; + struct pipe_surface *ps; + + if (!smapi || !smapi->get_egl_image) + return NULL; + + memset(&stimg, 0, sizeof(stimg)); + stimg.stctxi = &st->iface; + stimg.egl_image = eglimg; + if (!smapi->get_egl_image(smapi, &stimg)) + return NULL; + + ps = smapi->screen->get_tex_surface(smapi->screen, + stimg.texture, stimg.face, stimg.level, stimg.zslice, usage); + pipe_resource_reference(&stimg.texture, NULL); + + return ps; +} + +/** + * Re-validate the framebuffers. + */ +void +st_manager_validate_framebuffers(struct st_context *st) +{ + struct st_framebuffer *stdraw = st_ws_framebuffer(st->ctx->DrawBuffer); + struct st_framebuffer *stread = st_ws_framebuffer(st->ctx->ReadBuffer); + + if (stdraw) + st_framebuffer_validate(stdraw, st); + if (stread && stread != stdraw) + st_framebuffer_validate(stread, st); +} + +/** + * Add a color renderbuffer on demand. + */ +boolean +st_manager_add_color_renderbuffer(struct st_context *st, GLframebuffer *fb, + gl_buffer_index idx) +{ + struct st_framebuffer *stfb = st_ws_framebuffer(fb); + + /* FBO */ + if (!stfb) + return FALSE; + + if (stfb->Base.Attachment[idx].Renderbuffer) + return TRUE; + + switch (idx) { + case BUFFER_FRONT_LEFT: + case BUFFER_BACK_LEFT: + case BUFFER_FRONT_RIGHT: + case BUFFER_BACK_RIGHT: + break; + default: + return FALSE; + break; + } + + if (!st_framebuffer_add_renderbuffer(stfb, idx)) + return FALSE; + + st_framebuffer_update_attachments(stfb); + st_invalidate_state(st->ctx, _NEW_BUFFERS); + + return TRUE; +} + +struct st_api st_gl_api = { + st_api_destroy, + st_api_get_proc_address, + st_api_is_visual_supported, + st_api_create_context, + st_api_make_current, + st_api_get_current, +}; + +/** + * Return the st_api for this state tracker. This might either be GL, GLES1, + * GLES2 that mostly depends on the build and link options. But these + * functions remain the same either way. + */ +struct st_api * +st_gl_api_create(void) +{ + return &st_gl_api; +} diff --git a/src/mesa/state_tracker/st_manager.h b/src/mesa/state_tracker/st_manager.h new file mode 100644 index 00000000000..dabede4d64a --- /dev/null +++ b/src/mesa/state_tracker/st_manager.h @@ -0,0 +1,52 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * 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, sublicense, + * 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 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 NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS 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: + * Chia-I Wu <[email protected]> + */ + +#ifndef ST_MANAGER_H +#define ST_MANAGER_H + +#include "state_tracker/st_api.h" +#include "st_context.h" + +struct pipe_surface * +st_manager_get_egl_image_surface(struct st_context *st, + void *eglimg, unsigned usage); + +void +st_manager_flush_frontbuffer(struct st_context *st); + +void +st_manager_validate_framebuffers(struct st_context *st); + +boolean +st_manager_add_color_renderbuffer(struct st_context *st, GLframebuffer *fb, + gl_buffer_index idx); + +struct st_api * +st_manager_create_api(void); + +#endif /* ST_MANAGER_H */ diff --git a/src/mesa/state_tracker/st_mesa_to_tgsi.c b/src/mesa/state_tracker/st_mesa_to_tgsi.c index 807d21a7197..e8eb9ec3904 100644 --- a/src/mesa/state_tracker/st_mesa_to_tgsi.c +++ b/src/mesa/state_tracker/st_mesa_to_tgsi.c @@ -181,6 +181,7 @@ src_register( struct st_translate *t, ASSERT(index >= 0); if (ureg_dst_is_undef(t->temps[index])) t->temps[index] = ureg_DECL_temporary( t->ureg ); + assert(index < Elements(t->temps)); return ureg_src(t->temps[index]); case PROGRAM_NAMED_PARAM: @@ -197,9 +198,11 @@ src_register( struct st_translate *t, return t->constants[index]; case PROGRAM_INPUT: + assert(t->inputMapping[index] < Elements(t->inputs)); return t->inputs[t->inputMapping[index]]; case PROGRAM_OUTPUT: + assert(t->outputMapping[index] < Elements(t->outputs)); return ureg_src(t->outputs[t->outputMapping[index]]); /* not needed? */ case PROGRAM_ADDRESS: @@ -739,6 +742,65 @@ emit_inverted_wpos( struct st_translate *t, /** + * Emit fragment position/ooordinate code. + */ +static void +emit_wpos(struct st_context *st, + struct st_translate *t, + const struct gl_program *program, + struct ureg_program *ureg) +{ + const struct gl_fragment_program *fp = + (const struct gl_fragment_program *) program; + struct pipe_screen *pscreen = st->pipe->screen; + boolean invert = FALSE; + + if (fp->OriginUpperLeft) { + if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT)) { + } + else if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT)) { + ureg_property_fs_coord_origin(ureg, TGSI_FS_COORD_ORIGIN_LOWER_LEFT); + invert = TRUE; + } + else + assert(0); + } + else { + if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT)) + ureg_property_fs_coord_origin(ureg, TGSI_FS_COORD_ORIGIN_LOWER_LEFT); + else if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT)) + invert = TRUE; + else + assert(0); + } + + if (fp->PixelCenterInteger) { + if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER)) + ureg_property_fs_coord_pixel_center(ureg, TGSI_FS_COORD_PIXEL_CENTER_INTEGER); + else if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER)) + emit_adjusted_wpos(t, program, invert ? 0.5f : -0.5f); + else + assert(0); + } + else { + if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER)) { + } + else if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER)) { + ureg_property_fs_coord_pixel_center(ureg, TGSI_FS_COORD_PIXEL_CENTER_INTEGER); + emit_adjusted_wpos(t, program, invert ? -0.5f : 0.5f); + } + else + assert(0); + } + + /* we invert after adjustment so that we avoid the MOV to temporary, + * and reuse the adjustment ADD instead */ + if (invert) + emit_inverted_wpos(t, program); +} + + +/** * OpenGL's fragment gl_FrontFace input is 1 for front-facing, 0 for back. * TGSI uses +1 for front, -1 for back. * This function converts the TGSI value to the GL value. Simply clamping/ @@ -831,7 +893,6 @@ st_translate_mesa_program( * Declare input attributes. */ if (procType == TGSI_PROCESSOR_FRAGMENT) { - struct gl_fragment_program* fp = (struct gl_fragment_program*)program; for (i = 0; i < numInputs; i++) { if (program->InputFlags[0] & PROG_PARAM_BIT_CYL_WRAP) { t->inputs[i] = ureg_DECL_fs_input_cyl(ureg, @@ -852,51 +913,7 @@ st_translate_mesa_program( /* Must do this after setting up t->inputs, and before * emitting constant references, below: */ - struct pipe_screen* pscreen = st_context(ctx)->pipe->screen; - boolean invert = FALSE; - - if (fp->OriginUpperLeft) { - if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT)) { - } - else if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT)) { - ureg_property_fs_coord_origin(ureg, TGSI_FS_COORD_ORIGIN_LOWER_LEFT); - invert = TRUE; - } - else - assert(0); - } - else { - if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT)) - ureg_property_fs_coord_origin(ureg, TGSI_FS_COORD_ORIGIN_LOWER_LEFT); - else if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT)) - invert = TRUE; - else - assert(0); - } - - if (fp->PixelCenterInteger) { - if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER)) - ureg_property_fs_coord_pixel_center(ureg, TGSI_FS_COORD_PIXEL_CENTER_INTEGER); - else if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER)) - emit_adjusted_wpos(t, program, invert ? 0.5f : -0.5f); - else - assert(0); - } - else { - if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER)) { - } - else if (pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER)) { - ureg_property_fs_coord_pixel_center(ureg, TGSI_FS_COORD_PIXEL_CENTER_INTEGER); - emit_adjusted_wpos(t, program, invert ? -0.5f : 0.5f); - } - else - assert(0); - } - - /* we invert after adjustment so that we avoid the MOV to temporary, - * and reuse the adjustment ADD instead */ - if (invert) - emit_inverted_wpos(t, program); + emit_wpos(st_context(ctx), t, program, ureg); } if (program->InputsRead & FRAG_BIT_FACE) { @@ -943,8 +960,9 @@ st_translate_mesa_program( * do this before emitting the constant decls below, or this * will be missed: */ - unsigned pointSizeClampConst = _mesa_add_state_reference(program->Parameters, - pointSizeClampState); + unsigned pointSizeClampConst = + _mesa_add_state_reference(program->Parameters, + pointSizeClampState); struct ureg_dst psizregtemp = ureg_DECL_temporary( ureg ); t->pointSizeConst = ureg_DECL_constant( ureg, pointSizeClampConst ); t->psizregreal = t->outputs[i]; @@ -963,12 +981,10 @@ st_translate_mesa_program( t->address[0] = ureg_DECL_address( ureg ); } - /* Emit constants and immediates. Mesa uses a single index space * for these, so we put all the translated regs in t->constants. */ if (program->Parameters) { - t->constants = CALLOC( program->Parameters->NumParameters, sizeof t->constants[0] ); if (t->constants == NULL) { @@ -1023,7 +1039,8 @@ st_translate_mesa_program( possible early return */ if (t->prevInstWrotePsiz && program->Id) { set_insn_start( t, ureg_get_instruction_number( ureg )); - ureg_MAX( t->ureg, ureg_writemask(t->outputs[t->psizoutindex], WRITEMASK_X), + ureg_MAX( t->ureg, + ureg_writemask(t->outputs[t->psizoutindex], WRITEMASK_X), ureg_src(t->outputs[t->psizoutindex]), ureg_swizzle(t->pointSizeConst, 1,1,1,1)); ureg_MIN( t->ureg, ureg_writemask(t->psizregreal, WRITEMASK_X), diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index 7f8677d400c..772a2ee17c9 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -121,7 +121,7 @@ st_prepare_vertex_program(struct st_context *st, /* Compute mapping of vertex program outputs to slots. */ for (attr = 0; attr < VERT_RESULT_MAX; attr++) { - if ((stvp->Base.Base.OutputsWritten & (1 << attr)) == 0) { + if ((stvp->Base.Base.OutputsWritten & BITFIELD64_BIT(attr)) == 0) { stvp->result_to_output[attr] = ~0; } else { @@ -217,6 +217,12 @@ st_translate_vertex_program(struct st_context *st, num_outputs++; } + if (ST_DEBUG & DEBUG_MESA) { + _mesa_print_program(&stvp->Base.Base); + _mesa_print_program_parameters(st->ctx, &stvp->Base.Base); + debug_printf("\n"); + } + error = st_translate_mesa_program(st->ctx, TGSI_PROCESSOR_VERTEX, @@ -246,11 +252,6 @@ st_translate_vertex_program(struct st_context *st, vpv->driver_shader = pipe->create_vs_state(pipe, &vpv->tgsi); - if ((ST_DEBUG & DEBUG_TGSI) && (ST_DEBUG & DEBUG_MESA)) { - _mesa_print_program(&stvp->Base.Base); - debug_printf("\n"); - } - if (ST_DEBUG & DEBUG_TGSI) { tgsi_dump( vpv->tgsi.tokens, 0 ); debug_printf("\n"); @@ -388,7 +389,7 @@ st_translate_fragment_program(struct st_context *st, GLbitfield64 outputsWritten = stfp->Base.Base.OutputsWritten; /* if z is written, emit that first */ - if (outputsWritten & (1 << FRAG_RESULT_DEPTH)) { + if (outputsWritten & BITFIELD64_BIT(FRAG_RESULT_DEPTH)) { fs_output_semantic_name[fs_num_outputs] = TGSI_SEMANTIC_POSITION; fs_output_semantic_index[fs_num_outputs] = 0; outputMapping[FRAG_RESULT_DEPTH] = fs_num_outputs; @@ -398,7 +399,7 @@ st_translate_fragment_program(struct st_context *st, /* handle remaning outputs (color) */ for (attr = 0; attr < FRAG_RESULT_MAX; attr++) { - if (outputsWritten & (1 << attr)) { + if (outputsWritten & BITFIELD64_BIT(attr)) { switch (attr) { case FRAG_RESULT_DEPTH: /* handled above */ @@ -423,6 +424,11 @@ st_translate_fragment_program(struct st_context *st, if (ureg == NULL) return; + if (ST_DEBUG & DEBUG_MESA) { + _mesa_print_program(&stfp->Base.Base); + _mesa_print_program_parameters(st->ctx, &stfp->Base.Base); + debug_printf("\n"); + } error = st_translate_mesa_program(st->ctx, @@ -445,11 +451,6 @@ st_translate_fragment_program(struct st_context *st, ureg_destroy( ureg ); stfp->driver_shader = pipe->create_fs_state(pipe, &stfp->tgsi); - if ((ST_DEBUG & DEBUG_TGSI) && (ST_DEBUG & DEBUG_MESA)) { - _mesa_print_program(&stfp->Base.Base); - debug_printf("\n"); - } - if (ST_DEBUG & DEBUG_TGSI) { tgsi_dump( stfp->tgsi.tokens, 0/*TGSI_DUMP_VERBOSE*/ ); debug_printf("\n"); diff --git a/src/mesa/state_tracker/st_public.h b/src/mesa/state_tracker/st_public.h deleted file mode 100644 index 0824356cecc..00000000000 --- a/src/mesa/state_tracker/st_public.h +++ /dev/null @@ -1,151 +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_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" - -/** Renderbuffer surfaces (should match Mesa names) */ -#define ST_SURFACE_FRONT_LEFT 0 -#define ST_SURFACE_BACK_LEFT 1 -#define ST_SURFACE_FRONT_RIGHT 2 -#define ST_SURFACE_BACK_RIGHT 3 -#define ST_SURFACE_DEPTH 4 - -#define ST_TEXTURE_2D 0x2 -#define ST_TEXTURE_RECT 0x4 - -#define ST_TEXTURE_RGB 0x1 -#define ST_TEXTURE_RGBA 0x2 - - -struct st_context; -struct st_framebuffer; -struct pipe_context; -struct pipe_fence_handle; -struct pipe_surface; -struct pipe_texture; - - -PUBLIC -struct st_context *st_create_context(struct pipe_context *pipe, - const __GLcontextModes *visual, - struct st_context *share); - -PUBLIC -void st_destroy_context( struct st_context *st ); - -PUBLIC -void st_copy_context_state(struct st_context *dst, struct st_context *src, - uint mask); - -PUBLIC -struct st_framebuffer *st_create_framebuffer( const __GLcontextModes *visual, - enum pipe_format colorFormat, - enum pipe_format depthFormat, - enum pipe_format stencilFormat, - uint width, uint height, - void *privateData); - -PUBLIC -void st_resize_framebuffer( struct st_framebuffer *stfb, - uint width, uint height ); - -PUBLIC -void st_set_framebuffer_surface(struct st_framebuffer *stfb, - uint surfIndex, struct pipe_surface *surf); - -PUBLIC -void st_get_framebuffer_dimensions( struct st_framebuffer *stfb, - uint *width, uint *height); - -PUBLIC -int st_get_framebuffer_surface(struct st_framebuffer *stfb, - uint surfIndex, struct pipe_surface **surface); - -PUBLIC -int st_get_framebuffer_texture(struct st_framebuffer *stfb, - uint surfIndex, struct pipe_texture **texture); - -PUBLIC -void *st_framebuffer_private( struct st_framebuffer *stfb ); - -PUBLIC -void st_unreference_framebuffer( struct st_framebuffer *stfb ); - -PUBLIC -GLboolean st_make_current(struct st_context *st, - struct st_framebuffer *draw, - struct st_framebuffer *read); - -PUBLIC -struct st_context *st_get_current(void); - -PUBLIC -void st_flush( struct st_context *st, uint pipeFlushFlags, - struct pipe_fence_handle **fence ); -PUBLIC -void st_finish( struct st_context *st ); - -PUBLIC -void st_notify_swapbuffers(struct st_framebuffer *stfb); - -PUBLIC -void st_swapbuffers(struct st_framebuffer *stfb, - struct pipe_surface **front_left, - struct pipe_surface **front_right); - -PUBLIC -int st_bind_texture_surface(struct pipe_surface *ps, int target, int level, - enum pipe_format format); -PUBLIC -int st_unbind_texture_surface(struct pipe_surface *ps, int target, int level); - -/** Redirect rendering into stfb's surface to a texture image */ -PUBLIC -int st_bind_teximage(struct st_framebuffer *stfb, uint surfIndex, - int target, int format, int level); - -/** Undo surface-to-texture binding */ -PUBLIC -int st_release_teximage(struct st_framebuffer *stfb, uint surfIndex, - int target, int format, int level); - - -/** Generic function type */ -typedef void (*st_proc)(); - -PUBLIC -st_proc st_get_proc_address(const char *procname); - - -#endif diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c index 5a45c4358a9..70ba239d07b 100644 --- a/src/mesa/state_tracker/st_texture.c +++ b/src/mesa/state_tracker/st_texture.c @@ -27,14 +27,10 @@ #include "st_context.h" #include "st_format.h" -#include "st_public.h" #include "st_texture.h" #include "st_cb_fbo.h" #include "st_inlines.h" #include "main/enums.h" -#include "main/texfetch.h" -#include "main/teximage.h" -#include "main/texobj.h" #undef Elements /* fix re-defined macro warning */ @@ -69,12 +65,12 @@ target_to_target(GLenum target) /** - * Allocate a new pipe_texture object + * Allocate a new pipe_resource object * width0, height0, depth0 are the dimensions of the level 0 image * (the highest resolution). last_level indicates how many mipmap levels * to allocate storage for. For non-mipmapped textures, this will be zero. */ -struct pipe_texture * +struct pipe_resource * st_texture_create(struct st_context *st, enum pipe_texture_target target, enum pipe_format format, @@ -82,9 +78,9 @@ st_texture_create(struct st_context *st, GLuint width0, GLuint height0, GLuint depth0, - GLuint usage ) + GLuint bind ) { - struct pipe_texture pt, *newtex; + struct pipe_resource pt, *newtex; struct pipe_screen *screen = st->pipe->screen; assert(target <= PIPE_TEXTURE_CUBE); @@ -95,7 +91,7 @@ st_texture_create(struct st_context *st, assert(format); assert(screen->is_format_supported(screen, format, target, - PIPE_TEXTURE_USAGE_SAMPLER, 0)); + PIPE_BIND_SAMPLER_VIEW, 0)); memset(&pt, 0, sizeof(pt)); pt.target = target; @@ -104,9 +100,11 @@ st_texture_create(struct st_context *st, pt.width0 = width0; pt.height0 = height0; pt.depth0 = depth0; - pt.tex_usage = usage; + pt.usage = PIPE_USAGE_DEFAULT; + pt.bind = bind; + pt.flags = 0; - newtex = screen->texture_create(screen, &pt); + newtex = screen->resource_create(screen, &pt); assert(!newtex || pipe_is_referenced(&newtex->reference)); @@ -118,7 +116,7 @@ st_texture_create(struct st_context *st, * Check if a texture image can be pulled into a unified mipmap texture. */ GLboolean -st_texture_match_image(const struct pipe_texture *pt, +st_texture_match_image(const struct pipe_resource *pt, const struct gl_texture_image *image, GLuint face, GLuint level) { @@ -152,7 +150,7 @@ st_texture_match_image(const struct pipe_texture *pt, * These functions present that view to mesa: */ const GLuint * -st_texture_depth_offsets(struct pipe_texture *pt, GLuint level) +st_texture_depth_offsets(struct pipe_resource *pt, GLuint level) { static const GLuint zero = 0; @@ -168,7 +166,7 @@ st_texture_depth_offsets(struct pipe_texture *pt, GLuint level) * texture memory buffer, in bytes. */ GLuint -st_texture_image_offset(const struct pipe_texture * pt, +st_texture_image_offset(const struct pipe_resource * pt, GLuint face, GLuint level) { if (pt->target == PIPE_TEXTURE_CUBE) @@ -192,8 +190,7 @@ st_texture_image_map(struct st_context *st, struct st_texture_image *stImage, GLuint x, GLuint y, GLuint w, GLuint h) { struct pipe_context *pipe = st->pipe; - struct pipe_screen *screen = pipe->screen; - struct pipe_texture *pt = stImage->pt; + struct pipe_resource *pt = stImage->pt; DBG("%s \n", __FUNCTION__); @@ -202,7 +199,7 @@ st_texture_image_map(struct st_context *st, struct st_texture_image *stImage, usage, x, y, w, h); if (stImage->transfer) - return screen->transfer_map(screen, stImage->transfer); + return pipe_transfer_map(pipe, stImage->transfer); else return NULL; } @@ -212,13 +209,13 @@ void st_texture_image_unmap(struct st_context *st, struct st_texture_image *stImage) { - struct pipe_screen *screen = st->pipe->screen; + struct pipe_context *pipe = st->pipe; DBG("%s\n", __FUNCTION__); - screen->transfer_unmap(screen, stImage->transfer); + pipe_transfer_unmap(pipe, stImage->transfer); - screen->tex_transfer_destroy(stImage->transfer); + pipe->transfer_destroy(pipe, stImage->transfer); } @@ -238,19 +235,18 @@ st_surface_data(struct pipe_context *pipe, const void *src, unsigned src_stride, unsigned srcx, unsigned srcy, unsigned width, unsigned height) { - struct pipe_screen *screen = pipe->screen; - void *map = screen->transfer_map(screen, dst); + void *map = pipe_transfer_map(pipe, dst); - assert(dst->texture); + assert(dst->resource); util_copy_rect(map, - dst->texture->format, + dst->resource->format, dst->stride, dstx, dsty, width, height, src, src_stride, srcx, srcy); - screen->transfer_unmap(screen, dst); + pipe_transfer_unmap(pipe, dst); } @@ -258,14 +254,13 @@ st_surface_data(struct pipe_context *pipe, */ void st_texture_image_data(struct st_context *st, - struct pipe_texture *dst, + struct pipe_resource *dst, GLuint face, GLuint level, void *src, GLuint src_row_stride, GLuint src_image_stride) { struct pipe_context *pipe = st->pipe; - struct pipe_screen *screen = pipe->screen; GLuint depth = u_minify(dst->depth0, level); GLuint i; const GLubyte *srcUB = src; @@ -287,7 +282,7 @@ st_texture_image_data(struct st_context *st, u_minify(dst->width0, level), u_minify(dst->height0, level)); /* width, height */ - screen->tex_transfer_destroy(dst_transfer); + pipe->transfer_destroy(pipe, dst_transfer); srcUB += src_image_stride; } @@ -298,8 +293,8 @@ st_texture_image_data(struct st_context *st, */ void st_texture_image_copy(struct pipe_context *pipe, - struct pipe_texture *dst, GLuint dstLevel, - struct pipe_texture *src, + struct pipe_resource *dst, GLuint dstLevel, + struct pipe_resource *src, GLuint face) { struct pipe_screen *screen = pipe->screen; @@ -340,26 +335,17 @@ st_texture_image_copy(struct pipe_context *pipe, #endif dst_surface = screen->get_tex_surface(screen, dst, face, dstLevel, i, - PIPE_BUFFER_USAGE_GPU_WRITE); + PIPE_BIND_BLIT_DESTINATION); src_surface = screen->get_tex_surface(screen, src, face, srcLevel, i, - PIPE_BUFFER_USAGE_GPU_READ); - - if (pipe->surface_copy) { - pipe->surface_copy(pipe, - dst_surface, - 0, 0, /* destX, Y */ - src_surface, - 0, 0, /* srcX, Y */ - width, height); - } else { - util_surface_copy(pipe, FALSE, - dst_surface, - 0, 0, /* destX, Y */ - src_surface, - 0, 0, /* srcX, Y */ - width, height); - } + PIPE_BIND_BLIT_SOURCE); + + pipe->surface_copy(pipe, + dst_surface, + 0, 0, /* destX, Y */ + src_surface, + 0, 0, /* srcX, Y */ + width, height); pipe_surface_reference(&src_surface, NULL); pipe_surface_reference(&dst_surface, NULL); @@ -367,226 +353,16 @@ st_texture_image_copy(struct pipe_context *pipe, } -/** - * Bind a pipe surface to a texture object. After the call, - * the texture object is marked dirty and will be (re-)validated. - * - * If this is the first surface bound, the texture object is said to - * switch from normal to surface based. It will be cleared first in - * this case. - * - * \param ps pipe surface to be unbound - * \param target texture target - * \param level image level - * \param format internal format of the texture - */ -int -st_bind_texture_surface(struct pipe_surface *ps, int target, int level, - enum pipe_format format) -{ - GET_CURRENT_CONTEXT(ctx); - const GLuint unit = ctx->Texture.CurrentUnit; - struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; - struct gl_texture_object *texObj; - struct gl_texture_image *texImage; - struct st_texture_object *stObj; - struct st_texture_image *stImage; - GLenum internalFormat; - - switch (target) { - case ST_TEXTURE_2D: - target = GL_TEXTURE_2D; - break; - case ST_TEXTURE_RECT: - target = GL_TEXTURE_RECTANGLE_ARB; - break; - default: - return 0; - } - - /* map pipe format to base format for now */ - if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 3) > 0) - internalFormat = GL_RGBA; - else - internalFormat = GL_RGB; - - texObj = _mesa_select_tex_object(ctx, texUnit, target); - _mesa_lock_texture(ctx, texObj); - - stObj = st_texture_object(texObj); - /* switch to surface based */ - if (!stObj->surface_based) { - _mesa_clear_texture_object(ctx, texObj); - stObj->surface_based = GL_TRUE; - } - - texImage = _mesa_get_tex_image(ctx, texObj, target, level); - stImage = st_texture_image(texImage); - - _mesa_init_teximage_fields(ctx, target, texImage, - ps->width, ps->height, 1, 0, internalFormat); - texImage->TexFormat = st_ChooseTextureFormat(ctx, internalFormat, - GL_RGBA, GL_UNSIGNED_BYTE); - _mesa_set_fetch_functions(texImage, 2); - pipe_texture_reference(&stImage->pt, ps->texture); - - _mesa_dirty_texobj(ctx, texObj, GL_TRUE); - _mesa_unlock_texture(ctx, texObj); - - return 1; -} - - -/** - * Unbind a pipe surface from a texture object. After the call, - * the texture object is marked dirty and will be (re-)validated. - * - * \param ps pipe surface to be unbound - * \param target texture target - * \param level image level - */ -int -st_unbind_texture_surface(struct pipe_surface *ps, int target, int level) -{ - GET_CURRENT_CONTEXT(ctx); - const GLuint unit = ctx->Texture.CurrentUnit; - struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; - struct gl_texture_object *texObj; - struct gl_texture_image *texImage; - struct st_texture_object *stObj; - struct st_texture_image *stImage; - - switch (target) { - case ST_TEXTURE_2D: - target = GL_TEXTURE_2D; - break; - case ST_TEXTURE_RECT: - target = GL_TEXTURE_RECTANGLE_ARB; - break; - default: - return 0; - } - - texObj = _mesa_select_tex_object(ctx, texUnit, target); - - _mesa_lock_texture(ctx, texObj); - - texImage = _mesa_get_tex_image(ctx, texObj, target, level); - stObj = st_texture_object(texObj); - stImage = st_texture_image(texImage); - - /* Make sure the pipe surface is still bound. The texture object is still - * considered surface based even if this is the last bound surface. */ - if (stImage->pt == ps->texture) { - pipe_texture_reference(&stImage->pt, NULL); - _mesa_clear_texture_image(ctx, texImage); - - _mesa_dirty_texobj(ctx, texObj, GL_TRUE); - } - - _mesa_unlock_texture(ctx, texObj); - - return 1; -} - - -/** Redirect rendering into stfb's surface to a texture image */ -int -st_bind_teximage(struct st_framebuffer *stfb, uint surfIndex, - int target, int format, int level) -{ - GET_CURRENT_CONTEXT(ctx); - struct st_context *st = ctx->st; - struct pipe_context *pipe = st->pipe; - struct pipe_screen *screen = pipe->screen; - const GLuint unit = ctx->Texture.CurrentUnit; - struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; - struct gl_texture_object *texObj; - struct gl_texture_image *texImage; - struct st_texture_image *stImage; - struct st_renderbuffer *strb; - GLint face = 0, slice = 0; - - assert(surfIndex <= ST_SURFACE_DEPTH); - - strb = st_renderbuffer(stfb->Base.Attachment[surfIndex].Renderbuffer); - - if (strb->texture_save || strb->surface_save) { - /* Error! */ - return 0; - } - - if (target == ST_TEXTURE_2D) { - texObj = texUnit->CurrentTex[TEXTURE_2D_INDEX]; - texImage = _mesa_get_tex_image(ctx, texObj, GL_TEXTURE_2D, level); - stImage = st_texture_image(texImage); - } - else { - /* unsupported target */ - return 0; - } - - st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); - - /* save the renderbuffer's surface/texture info */ - pipe_texture_reference(&strb->texture_save, strb->texture); - pipe_surface_reference(&strb->surface_save, strb->surface); - - /* plug in new surface/texture info */ - pipe_texture_reference(&strb->texture, stImage->pt); - strb->surface = screen->get_tex_surface(screen, strb->texture, - face, level, slice, - (PIPE_BUFFER_USAGE_GPU_READ | - PIPE_BUFFER_USAGE_GPU_WRITE)); - - st->dirty.st |= ST_NEW_FRAMEBUFFER; - - return 1; -} - - -/** Undo surface-to-texture binding */ -int -st_release_teximage(struct st_framebuffer *stfb, uint surfIndex, - int target, int format, int level) -{ - GET_CURRENT_CONTEXT(ctx); - struct st_context *st = ctx->st; - struct st_renderbuffer *strb; - - assert(surfIndex <= ST_SURFACE_DEPTH); - - strb = st_renderbuffer(stfb->Base.Attachment[surfIndex].Renderbuffer); - - if (!strb->texture_save || !strb->surface_save) { - /* Error! */ - return 0; - } - - st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); - - /* free tex surface, restore original */ - pipe_surface_reference(&strb->surface, strb->surface_save); - pipe_texture_reference(&strb->texture, strb->texture_save); - - pipe_surface_reference(&strb->surface_save, NULL); - pipe_texture_reference(&strb->texture_save, NULL); - - st->dirty.st |= ST_NEW_FRAMEBUFFER; - - return 1; -} - void st_teximage_flush_before_map(struct st_context *st, - struct pipe_texture *pt, + struct pipe_resource *pt, unsigned int face, unsigned int level, enum pipe_transfer_usage usage) { struct pipe_context *pipe = st->pipe; unsigned referenced = - pipe->is_texture_referenced(pipe, pt, face, level); + pipe->is_resource_referenced(pipe, pt, face, level); if (referenced && ((referenced & PIPE_REFERENCED_FOR_WRITE) || (usage & PIPE_TRANSFER_WRITE))) diff --git a/src/mesa/state_tracker/st_texture.h b/src/mesa/state_tracker/st_texture.h index 60868ce0673..416468478b1 100644 --- a/src/mesa/state_tracker/st_texture.h +++ b/src/mesa/state_tracker/st_texture.h @@ -29,10 +29,13 @@ #define ST_TEXTURE_H +#include "pipe/p_context.h" +#include "util/u_sampler.h" + #include "main/mtypes.h" -struct pipe_context; -struct pipe_texture; + +struct pipe_resource; struct st_texture_image @@ -48,7 +51,7 @@ struct st_texture_image * Else if stImage->base.Data != NULL, image is stored there. * Else there is no image data. */ - struct pipe_texture *pt; + struct pipe_resource *pt; struct pipe_transfer *transfer; }; @@ -66,7 +69,12 @@ struct st_texture_object /* 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; + struct pipe_resource *pt; + + /* Default sampler view attached to this texture object. Created lazily + * on first binding. + */ + struct pipe_sampler_view *sampler_view; GLboolean teximage_realloc; @@ -90,22 +98,53 @@ st_texture_object(struct gl_texture_object *obj) } -static INLINE struct pipe_texture * -st_get_texobj_texture(struct gl_texture_object *texObj) +static INLINE struct pipe_resource * +st_get_texobj_resource(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) +static INLINE struct pipe_resource * +st_get_stobj_resource(struct st_texture_object *stObj) { return stObj ? stObj->pt : NULL; } -extern struct pipe_texture * +static INLINE struct pipe_sampler_view * +st_create_texture_sampler_view(struct pipe_context *pipe, + struct pipe_resource *texture) +{ + struct pipe_sampler_view templ; + + u_sampler_view_default_template(&templ, + texture, + texture->format); + + return pipe->create_sampler_view(pipe, texture, &templ); +} + + +static INLINE struct pipe_sampler_view * +st_get_texture_sampler_view(struct st_texture_object *stObj, + struct pipe_context *pipe) + +{ + if (!stObj || !stObj->pt) { + return NULL; + } + + if (!stObj->sampler_view) { + stObj->sampler_view = st_create_texture_sampler_view(pipe, stObj->pt); + } + + return stObj->sampler_view; +} + + +extern struct pipe_resource * st_texture_create(struct st_context *st, enum pipe_texture_target target, enum pipe_format format, @@ -119,7 +158,7 @@ st_texture_create(struct st_context *st, /* Check if an image fits into an existing texture object. */ extern GLboolean -st_texture_match_image(const struct pipe_texture *pt, +st_texture_match_image(const struct pipe_resource *pt, const struct gl_texture_image *image, GLuint face, GLuint level); @@ -143,17 +182,17 @@ st_texture_image_unmap(struct st_context *st, * value. */ extern const GLuint * -st_texture_depth_offsets(struct pipe_texture *pt, GLuint level); +st_texture_depth_offsets(struct pipe_resource *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, +st_texture_image_offset(const struct pipe_resource *pt, GLuint face, GLuint level); extern GLuint -st_texture_texel_offset(const struct pipe_texture * pt, +st_texture_texel_offset(const struct pipe_resource * pt, GLuint face, GLuint level, GLuint col, GLuint row, GLuint img); @@ -162,7 +201,7 @@ st_texture_texel_offset(const struct pipe_texture * pt, */ extern void st_texture_image_data(struct st_context *st, - struct pipe_texture *dst, + struct pipe_resource *dst, GLuint face, GLuint level, void *src, GLuint src_row_pitch, GLuint src_image_pitch); @@ -171,13 +210,13 @@ st_texture_image_data(struct st_context *st, */ extern void st_texture_image_copy(struct pipe_context *pipe, - struct pipe_texture *dst, GLuint dstLevel, - struct pipe_texture *src, + struct pipe_resource *dst, GLuint dstLevel, + struct pipe_resource *src, GLuint face); extern void st_teximage_flush_before_map(struct st_context *st, - struct pipe_texture *pt, + struct pipe_resource *pt, unsigned int face, unsigned int level, enum pipe_transfer_usage usage); |