diff options
Diffstat (limited to 'mesalib/src/mesa')
-rw-r--r-- | mesalib/src/mesa/main/fbobject.c | 10 | ||||
-rw-r--r-- | mesalib/src/mesa/main/mtypes.h | 3 | ||||
-rw-r--r-- | mesalib/src/mesa/main/readpix.c | 49 | ||||
-rw-r--r-- | mesalib/src/mesa/main/texgetimage.c | 9 | ||||
-rw-r--r-- | mesalib/src/mesa/main/teximage.c | 9 | ||||
-rw-r--r-- | mesalib/src/mesa/main/teximage.h | 10 | ||||
-rw-r--r-- | mesalib/src/mesa/program/ir_to_mesa.cpp | 29 | ||||
-rw-r--r-- | mesalib/src/mesa/state_tracker/st_draw.c | 246 | ||||
-rw-r--r-- | mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 23 |
9 files changed, 218 insertions, 170 deletions
diff --git a/mesalib/src/mesa/main/fbobject.c b/mesalib/src/mesa/main/fbobject.c index f8b148cee..5b329f5c3 100644 --- a/mesalib/src/mesa/main/fbobject.c +++ b/mesalib/src/mesa/main/fbobject.c @@ -78,14 +78,6 @@ static struct gl_renderbuffer DummyRenderbuffer; static struct gl_framebuffer IncompleteFramebuffer; -static inline GLboolean -is_cube_face(GLenum target) -{ - return (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && - target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z); -} - - /** * Is the given FBO a user-created FBO? */ @@ -2008,7 +2000,7 @@ framebuffer_texture(struct gl_context *ctx, const char *caller, GLenum target, } else { err = (texObj->Target == GL_TEXTURE_CUBE_MAP) - ? !is_cube_face(textarget) + ? !_mesa_is_cube_face(textarget) : (texObj->Target != textarget); } } diff --git a/mesalib/src/mesa/main/mtypes.h b/mesalib/src/mesa/main/mtypes.h index 285ec0783..b3427dac1 100644 --- a/mesalib/src/mesa/main/mtypes.h +++ b/mesalib/src/mesa/main/mtypes.h @@ -2218,6 +2218,9 @@ struct gl_shader_program /** Post-link transform feedback info. */ struct gl_transform_feedback_info LinkedTransformFeedback; + /** Post-link gl_FragDepth layout for ARB_conservative_depth. */ + enum gl_frag_depth_layout FragDepthLayout; + /** Geometry shader state - copied into gl_geometry_program at link time */ struct { GLint VerticesOut; diff --git a/mesalib/src/mesa/main/readpix.c b/mesalib/src/mesa/main/readpix.c index 86b87534d..8048a7286 100644 --- a/mesalib/src/mesa/main/readpix.c +++ b/mesalib/src/mesa/main/readpix.c @@ -70,6 +70,11 @@ fast_read_depth_pixels( struct gl_context *ctx, ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT, &map, &stride); + if (!map) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels"); + return GL_TRUE; /* don't bother trying the slow path */ + } + dstStride = _mesa_image_row_stride(packing, width, GL_DEPTH_COMPONENT, type); dst = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height, GL_DEPTH_COMPONENT, type, 0, 0); @@ -126,6 +131,10 @@ read_depth_pixels( struct gl_context *ctx, ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT, &map, &stride); + if (!map) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels"); + return; + } /* General case (slower) */ for (j = 0; j < height; j++, y++) { @@ -165,6 +174,10 @@ read_stencil_pixels( struct gl_context *ctx, ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT, &map, &stride); + if (!map) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels"); + return; + } /* process image row by row */ for (j = 0; j < height; j++) { @@ -211,6 +224,10 @@ fast_read_rgba_pixels_memcpy( struct gl_context *ctx, ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT, &map, &stride); + if (!map) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels"); + return GL_TRUE; /* don't bother trying the slow path */ + } texelBytes = _mesa_get_format_bytes(rb->Format); for (j = 0; j < height; j++) { @@ -224,7 +241,7 @@ fast_read_rgba_pixels_memcpy( struct gl_context *ctx, return GL_TRUE; } -static GLboolean +static void slow_read_rgba_pixels( struct gl_context *ctx, GLint x, GLint y, GLsizei width, GLsizei height, @@ -248,6 +265,10 @@ slow_read_rgba_pixels( struct gl_context *ctx, ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT, &map, &stride); + if (!map) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels"); + return; + } for (j = 0; j < height; j++) { if (_mesa_is_integer_format(format)) { @@ -263,8 +284,6 @@ slow_read_rgba_pixels( struct gl_context *ctx, } ctx->Driver.UnmapRenderbuffer(ctx, rb); - - return GL_TRUE; } /* @@ -327,6 +346,10 @@ fast_read_depth_stencil_pixels(struct gl_context *ctx, ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT, &map, &stride); + if (!map) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels"); + return GL_TRUE; /* don't bother trying the slow path */ + } for (i = 0; i < height; i++) { _mesa_unpack_uint_24_8_depth_stencil_row(rb->Format, width, @@ -363,8 +386,18 @@ fast_read_depth_stencil_pixels_separate(struct gl_context *ctx, ctx->Driver.MapRenderbuffer(ctx, depthRb, x, y, width, height, GL_MAP_READ_BIT, &depthMap, &depthStride); + if (!depthMap) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels"); + return GL_TRUE; /* don't bother trying the slow path */ + } + ctx->Driver.MapRenderbuffer(ctx, stencilRb, x, y, width, height, GL_MAP_READ_BIT, &stencilMap, &stencilStride); + if (!stencilMap) { + ctx->Driver.UnmapRenderbuffer(ctx, depthRb); + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels"); + return GL_TRUE; /* don't bother trying the slow path */ + } for (j = 0; j < height; j++) { GLubyte stencilVals[MAX_WIDTH]; @@ -407,10 +440,20 @@ slow_read_depth_stencil_pixels_separate(struct gl_context *ctx, */ ctx->Driver.MapRenderbuffer(ctx, depthRb, x, y, width, height, GL_MAP_READ_BIT, &depthMap, &depthStride); + if (!depthMap) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels"); + return; + } + if (stencilRb != depthRb) { ctx->Driver.MapRenderbuffer(ctx, stencilRb, x, y, width, height, GL_MAP_READ_BIT, &stencilMap, &stencilStride); + if (!stencilMap) { + ctx->Driver.UnmapRenderbuffer(ctx, depthRb); + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels"); + return; + } } else { stencilMap = depthMap; diff --git a/mesalib/src/mesa/main/texgetimage.c b/mesalib/src/mesa/main/texgetimage.c index 31d49f2d8..06506594d 100644 --- a/mesalib/src/mesa/main/texgetimage.c +++ b/mesalib/src/mesa/main/texgetimage.c @@ -386,11 +386,10 @@ get_tex_memcpy(struct gl_context *ctx, GLenum format, GLenum type, * so we don't have to worry about those. * XXX more format combinations could be supported here. */ - if ((target == GL_TEXTURE_1D || - target == GL_TEXTURE_2D || - target == GL_TEXTURE_RECTANGLE || - (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && - target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z))) { + if (target == GL_TEXTURE_1D || + target == GL_TEXTURE_2D || + target == GL_TEXTURE_RECTANGLE || + _mesa_is_cube_face(target)) { if ((texImage->TexFormat == MESA_FORMAT_ARGB8888 || texImage->TexFormat == MESA_FORMAT_SARGB8) && format == GL_BGRA && diff --git a/mesalib/src/mesa/main/teximage.c b/mesalib/src/mesa/main/teximage.c index a84d6873d..c8ea4329f 100644 --- a/mesalib/src/mesa/main/teximage.c +++ b/mesalib/src/mesa/main/teximage.c @@ -522,8 +522,7 @@ _mesa_base_tex_format( struct gl_context *ctx, GLint internalFormat ) GLuint _mesa_tex_target_to_face(GLenum target) { - if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && - target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) + if (_mesa_is_cube_face(target)) return (GLuint) target - (GLuint) GL_TEXTURE_CUBE_MAP_POSITIVE_X; else return 0; @@ -3094,8 +3093,7 @@ compressed_texture_error_check(struct gl_context *ctx, GLint dimensions, } /* For cube map, width must equal height */ - if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && - target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB && width != height) { + if (_mesa_is_cube_face(target) && width != height) { *reason = "width != height"; return GL_INVALID_VALUE; } @@ -3183,8 +3181,7 @@ compressed_subtexture_error_check(struct gl_context *ctx, GLint dimensions, return GL_INVALID_ENUM; /*target*/ maxLevels = ctx->Const.MaxCubeTextureLevels; } - else if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && - target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) { + else if (_mesa_is_cube_face(target)) { if (!ctx->Extensions.ARB_texture_cube_map) return GL_INVALID_ENUM; /*target*/ maxLevels = ctx->Const.MaxCubeTextureLevels; diff --git a/mesalib/src/mesa/main/teximage.h b/mesalib/src/mesa/main/teximage.h index fd315bea3..9cc7d5a54 100644 --- a/mesalib/src/mesa/main/teximage.h +++ b/mesalib/src/mesa/main/teximage.h @@ -36,6 +36,16 @@ #include "formats.h" +/** Is the given value one of the 6 cube faces? */ +static inline GLboolean +_mesa_is_cube_face(GLenum target) +{ + return (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB && + target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB); +} + + + /** \name Internal functions */ /*@{*/ diff --git a/mesalib/src/mesa/program/ir_to_mesa.cpp b/mesalib/src/mesa/program/ir_to_mesa.cpp index 5cee83778..5a68fc51d 100644 --- a/mesalib/src/mesa/program/ir_to_mesa.cpp +++ b/mesalib/src/mesa/program/ir_to_mesa.cpp @@ -685,29 +685,6 @@ ir_to_mesa_visitor::visit(ir_variable *ir) fp->OriginUpperLeft = ir->origin_upper_left; fp->PixelCenterInteger = ir->pixel_center_integer; - - } else if (strcmp(ir->name, "gl_FragDepth") == 0) { - struct gl_fragment_program *fp = (struct gl_fragment_program *)this->prog; - switch (ir->depth_layout) { - case ir_depth_layout_none: - fp->FragDepthLayout = FRAG_DEPTH_LAYOUT_NONE; - break; - case ir_depth_layout_any: - fp->FragDepthLayout = FRAG_DEPTH_LAYOUT_ANY; - break; - case ir_depth_layout_greater: - fp->FragDepthLayout = FRAG_DEPTH_LAYOUT_GREATER; - break; - case ir_depth_layout_less: - fp->FragDepthLayout = FRAG_DEPTH_LAYOUT_LESS; - break; - case ir_depth_layout_unchanged: - fp->FragDepthLayout = FRAG_DEPTH_LAYOUT_UNCHANGED; - break; - default: - assert(0); - break; - } } if (ir->mode == ir_var_uniform && strncmp(ir->name, "gl_", 3) == 0) { @@ -3222,6 +3199,12 @@ get_mesa_program(struct gl_context *ctx, do_set_program_inouts(shader->ir, prog, shader->Type == GL_FRAGMENT_SHADER); count_resources(prog); + /* Set the gl_FragDepth layout. */ + if (target == GL_FRAGMENT_PROGRAM_ARB) { + struct gl_fragment_program *fp = (struct gl_fragment_program *)prog; + fp->FragDepthLayout = shader_program->FragDepthLayout; + } + _mesa_reference_program(ctx, &shader->Program, prog); if ((ctx->Shader.Flags & GLSL_NO_OPT) == 0) { diff --git a/mesalib/src/mesa/state_tracker/st_draw.c b/mesalib/src/mesa/state_tracker/st_draw.c index cb518e1af..05a71d35c 100644 --- a/mesalib/src/mesa/state_tracker/st_draw.c +++ b/mesalib/src/mesa/state_tracker/st_draw.c @@ -648,45 +648,108 @@ check_uniforms(struct gl_context *ctx) } } -/** Helper code for primitive restart fallback */ -#define DO_DRAW(pipe, cur_start, cur_count) \ - do { \ - info.start = cur_start; \ - info.count = cur_count; \ - if (u_trim_pipe_prim(info.mode, &info.count)) { \ - if (transfer) \ - pipe_buffer_unmap(pipe, transfer); \ - pipe->draw_vbo(pipe, &info); \ - if (transfer) { \ - ptr = pipe_buffer_map(pipe, ibuffer->buffer, PIPE_TRANSFER_READ, &transfer); \ - assert(ptr != NULL); \ - ptr = ADD_POINTERS(ptr, ibuffer->offset); \ - } \ - } \ - } while(0) - -/** More helper code for primitive restart fallback */ -#define PRIM_RESTART_LOOP(elements) \ - do { \ - for (i = start; i < end; i++) { \ - if (elements[i] == info.restart_index) { \ - if (cur_count > 0) { \ - /* draw elts up to prev pos */ \ - DO_DRAW(pipe, cur_start, cur_count); \ - } \ - /* begin new prim at next elt */ \ - cur_start = i + 1; \ - cur_count = 0; \ - } \ - else { \ - cur_count++; \ + +/* + * Notes on primitive restart: + * The code below is used when the gallium driver does not support primitive + * restart itself. We map the index buffer, find the restart indexes, unmap + * the index buffer then draw the sub-primitives delineated by the restarts. + * A couple possible optimizations: + * 1. Save the list of sub-primitive (start, count) values in a list attached + * to the index buffer for re-use in subsequent draws. The list would be + * invalidated when the contents of the buffer changed. + * 2. If drawing triangle strips or quad strips, create a new index buffer + * that uses duplicated vertices to render the disjoint strips as one + * long strip. We'd have to be careful to avoid using too much memory + * for this. + * Finally, some apps might perform better if they don't use primitive restart + * at all rather than this fallback path. Set MESA_EXTENSION_OVERRIDE to + * "-GL_NV_primitive_restart" to test that. + */ + + +struct sub_primitive +{ + unsigned start, count; +}; + + +/** + * Scan the elements array to find restart indexes. Return a list + * of primitive (start,count) pairs to indicate how to draw the sub- + * primitives delineated by the restart index. + */ +static struct sub_primitive * +find_sub_primitives(const void *elements, unsigned element_size, + unsigned start, unsigned end, unsigned restart_index, + unsigned *num_sub_prims) +{ + const unsigned max_prims = end - start; + struct sub_primitive *sub_prims; + unsigned i, cur_start, cur_count, num; + + sub_prims = (struct sub_primitive *) + malloc(max_prims * sizeof(struct sub_primitive)); + + if (!sub_prims) { + *num_sub_prims = 0; + return NULL; + } + + cur_start = start; + cur_count = 0; + num = 0; + +#define SCAN_ELEMENTS(TYPE) \ + for (i = start; i < end; i++) { \ + if (((const TYPE *) elements)[i] == restart_index) { \ + if (cur_count > 0) { \ + assert(num < max_prims); \ + sub_prims[num].start = cur_start; \ + sub_prims[num].count = cur_count; \ + num++; \ } \ + cur_start = i + 1; \ + cur_count = 0; \ } \ - if (cur_count > 0) { \ - DO_DRAW(pipe, cur_start, cur_count); \ + else { \ + cur_count++; \ } \ - } while (0) + } \ + if (cur_count > 0) { \ + assert(num < max_prims); \ + sub_prims[num].start = cur_start; \ + sub_prims[num].count = cur_count; \ + num++; \ + } + + switch (element_size) { + case 1: + SCAN_ELEMENTS(ubyte); + break; + case 2: + SCAN_ELEMENTS(ushort); + break; + case 4: + SCAN_ELEMENTS(uint); + break; + default: + assert(0 && "bad index_size in find_sub_primitives()"); + } + +#undef SCAN_ELEMENTS + + *num_sub_prims = num; + + return sub_prims; +} + +/** + * For gallium drivers that don't support the primitive restart + * feature, handle it here by breaking up the indexed primitive into + * sub-primitives. + */ static void handle_fallback_primitive_restart(struct pipe_context *pipe, const struct _mesa_index_buffer *ib, @@ -695,78 +758,61 @@ handle_fallback_primitive_restart(struct pipe_context *pipe, { const unsigned start = orig_info->start; const unsigned count = orig_info->count; - const unsigned end = start + count; struct pipe_draw_info info = *orig_info; struct pipe_transfer *transfer = NULL; - unsigned instance, i, cur_start, cur_count; - const void *ptr; + unsigned instance, i; + const void *ptr = NULL; + struct sub_primitive *sub_prims; + unsigned num_sub_prims; - info.primitive_restart = FALSE; - - if (!info.indexed) { - /* Splitting the draw arrays call is handled by the VBO module */ - if (u_trim_pipe_prim(info.mode, &info.count)) - pipe->draw_vbo(pipe, &info); + assert(info.indexed); + assert(ibuffer->buffer); + assert(ib); + if (!ibuffer->buffer || !ib) return; - } - /* info.indexed == TRUE */ - assert(ibuffer); - assert(ibuffer->buffer); + info.primitive_restart = FALSE; + info.instance_count = 1; - if (ib) { - struct gl_buffer_object *bufobj = ib->obj; - if (bufobj && bufobj->Name) { - ptr = NULL; - } - else { - ptr = ib->ptr; - } - } else { - ptr = NULL; + if (ib->obj && _mesa_is_bufferobj(ib->obj)) { + ptr = pipe_buffer_map_range(pipe, ibuffer->buffer, + start * ibuffer->index_size, /* start */ + count * ibuffer->index_size, /* length */ + PIPE_TRANSFER_READ, &transfer); + } + else { + ptr = ib->ptr; } if (!ptr) - ptr = pipe_buffer_map(pipe, ibuffer->buffer, PIPE_TRANSFER_READ, &transfer); + return; - if (!ptr) - return; ptr = ADD_POINTERS(ptr, ibuffer->offset); - /* Need to loop over instances as well to preserve draw order */ + sub_prims = find_sub_primitives(ptr, ibuffer->index_size, + 0, count, orig_info->restart_index, + &num_sub_prims); + + if (transfer) + pipe_buffer_unmap(pipe, transfer); + + /* Now draw the sub primitives. + * Need to loop over instances as well to preserve draw order. + */ for (instance = 0; instance < orig_info->instance_count; instance++) { info.start_instance = instance + orig_info->start_instance; - info.instance_count = 1; - cur_start = start; - cur_count = 0; - - switch (ibuffer->index_size) { - case 1: - { - const ubyte *elt_ub = (const ubyte *)ptr; - PRIM_RESTART_LOOP(elt_ub); - } - break; - case 2: - { - const ushort *elt_us = (const ushort *)ptr; - PRIM_RESTART_LOOP(elt_us); - } - break; - case 4: - { - const uint *elt_ui = (const uint *)ptr; - PRIM_RESTART_LOOP(elt_ui); + for (i = 0; i < num_sub_prims; i++) { + info.start = sub_prims[i].start; + info.count = sub_prims[i].count; + if (u_trim_pipe_prim(info.mode, &info.count)) { + pipe->draw_vbo(pipe, &info); } - break; - default: - assert(0 && "bad index_size in handle_fallback_primitive_restart()"); } } - if (transfer) - pipe_buffer_unmap(pipe, transfer); + if (sub_prims) + free(sub_prims); } @@ -978,10 +1024,13 @@ st_draw_vbo(struct gl_context *ctx, info.min_index = min_index; info.max_index = max_index; } - } - info.primitive_restart = ctx->Array.PrimitiveRestart; - info.restart_index = ctx->Array.RestartIndex; + /* The VBO module handles restart for the non-indexed GLDrawArrays + * so we only set these fields for indexed drawing: + */ + info.primitive_restart = ctx->Array.PrimitiveRestart; + info.restart_index = ctx->Array.RestartIndex; + } /* do actual drawing */ for (i = 0; i < nr_prims; i++) { @@ -996,19 +1045,14 @@ st_draw_vbo(struct gl_context *ctx, } if (info.primitive_restart) { - /* - * Handle primitive restart for drivers that doesn't support it. - * - * The VBO module handles restart inside of draw_arrays for us, - * but we should still remove the primitive_restart flag on the - * info struct, the fallback function does this for us. Just - * remove the flag for all drivers in this case as well. - */ - if (st->sw_primitive_restart || !info.indexed) + if (st->sw_primitive_restart) { + /* Handle primitive restart for drivers that doesn't support it */ handle_fallback_primitive_restart(pipe, ib, &ibuffer, &info); - else + } + else { /* don't trim, restarts might be inside index list */ pipe->draw_vbo(pipe, &info); + } } else if (u_trim_pipe_prim(info.mode, &info.count)) pipe->draw_vbo(pipe, &info); diff --git a/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp index 0bf6766f7..929c7af01 100644 --- a/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp +++ b/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp @@ -1017,29 +1017,6 @@ glsl_to_tgsi_visitor::visit(ir_variable *ir) fp->OriginUpperLeft = ir->origin_upper_left; fp->PixelCenterInteger = ir->pixel_center_integer; - - } else if (strcmp(ir->name, "gl_FragDepth") == 0) { - struct gl_fragment_program *fp = (struct gl_fragment_program *)this->prog; - switch (ir->depth_layout) { - case ir_depth_layout_none: - fp->FragDepthLayout = FRAG_DEPTH_LAYOUT_NONE; - break; - case ir_depth_layout_any: - fp->FragDepthLayout = FRAG_DEPTH_LAYOUT_ANY; - break; - case ir_depth_layout_greater: - fp->FragDepthLayout = FRAG_DEPTH_LAYOUT_GREATER; - break; - case ir_depth_layout_less: - fp->FragDepthLayout = FRAG_DEPTH_LAYOUT_LESS; - break; - case ir_depth_layout_unchanged: - fp->FragDepthLayout = FRAG_DEPTH_LAYOUT_UNCHANGED; - break; - default: - assert(0); - break; - } } if (ir->mode == ir_var_uniform && strncmp(ir->name, "gl_", 3) == 0) { |