diff options
Diffstat (limited to 'mesalib/src/mesa/state_tracker')
-rw-r--r-- | mesalib/src/mesa/state_tracker/st_cb_bufferobjects.c | 12 | ||||
-rw-r--r-- | mesalib/src/mesa/state_tracker/st_cb_clear.c | 5 | ||||
-rw-r--r-- | mesalib/src/mesa/state_tracker/st_cb_drawpixels.c | 10 | ||||
-rw-r--r-- | mesalib/src/mesa/state_tracker/st_cb_fbo.c | 59 | ||||
-rw-r--r-- | mesalib/src/mesa/state_tracker/st_cb_fbo.h | 2 | ||||
-rw-r--r-- | mesalib/src/mesa/state_tracker/st_draw.c | 65 | ||||
-rw-r--r-- | mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 14 | ||||
-rw-r--r-- | mesalib/src/mesa/state_tracker/st_program.c | 14 |
8 files changed, 154 insertions, 27 deletions
diff --git a/mesalib/src/mesa/state_tracker/st_cb_bufferobjects.c b/mesalib/src/mesa/state_tracker/st_cb_bufferobjects.c index aab7444e2..adac92f2c 100644 --- a/mesalib/src/mesa/state_tracker/st_cb_bufferobjects.c +++ b/mesalib/src/mesa/state_tracker/st_cb_bufferobjects.c @@ -115,6 +115,11 @@ st_bufferobj_subdata(struct gl_context *ctx, if (!data) return; + if (!st_obj->buffer) { + /* we probably ran out of memory during buffer allocation */ + return; + } + /* 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 @@ -146,6 +151,11 @@ st_bufferobj_get_subdata(struct gl_context *ctx, if (!size) return; + if (!st_obj->buffer) { + /* we probably ran out of memory during buffer allocation */ + return; + } + pipe_buffer_read(st_context(ctx)->pipe, st_obj->buffer, offset, size, data); } @@ -216,6 +226,8 @@ st_bufferobj_data(struct gl_context *ctx, pipe_usage, size); if (!st_obj->buffer) { + /* out of memory */ + st_obj->Base.Size = 0; return GL_FALSE; } diff --git a/mesalib/src/mesa/state_tracker/st_cb_clear.c b/mesalib/src/mesa/state_tracker/st_cb_clear.c index 19a87aae2..89273e28e 100644 --- a/mesalib/src/mesa/state_tracker/st_cb_clear.c +++ b/mesalib/src/mesa/state_tracker/st_cb_clear.c @@ -165,6 +165,11 @@ draw_quad(struct st_context *st, max_slots * sizeof(st->clear.vertices)); } + if (!st->clear.vbuf) { + /* ran out of memory */ + return; + } + /* positions */ st->clear.vertices[0][0][0] = x0; st->clear.vertices[0][0][1] = y0; diff --git a/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c b/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c index 1c44d0d87..5714d343d 100644 --- a/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/mesalib/src/mesa/state_tracker/st_cb_drawpixels.c @@ -1135,10 +1135,10 @@ st_DrawPixels(struct gl_context *ctx, GLint x, GLint y, assert(0); } - sv[1] = st_create_texture_sampler_view_format(st->pipe, pt, + sv[1] = st_create_texture_sampler_view_format(st->pipe, pt, stencil_format); - num_sampler_view++; - } + num_sampler_view++; + } draw_textured_quad(ctx, x, y, ctx->Current.RasterPos[2], width, height, @@ -1638,9 +1638,9 @@ st_destroy_drawpix(struct st_context *st) st_reference_fragprog(st, &st->pixel_xfer.combined_prog, NULL); if (st->drawpix.vert_shaders[0]) - ureg_free_tokens(st->drawpix.vert_shaders[0]); + cso_delete_vertex_shader(st->cso_context, st->drawpix.vert_shaders[0]); if (st->drawpix.vert_shaders[1]) - ureg_free_tokens(st->drawpix.vert_shaders[1]); + cso_delete_vertex_shader(st->cso_context, st->drawpix.vert_shaders[1]); } #endif /* FEATURE_drawpix */ diff --git a/mesalib/src/mesa/state_tracker/st_cb_fbo.c b/mesalib/src/mesa/state_tracker/st_cb_fbo.c index 6da65d7b9..e04cb4406 100644 --- a/mesalib/src/mesa/state_tracker/st_cb_fbo.c +++ b/mesalib/src/mesa/state_tracker/st_cb_fbo.c @@ -630,6 +630,62 @@ st_ReadBuffer(struct gl_context *ctx, GLenum buffer) } + +/** + * Called via ctx->Driver.MapRenderbuffer. + */ +static void +st_MapRenderbuffer(struct gl_context *ctx, + struct gl_renderbuffer *rb, + GLuint x, GLuint y, GLuint w, GLuint h, + GLbitfield mode, + GLubyte **mapOut, GLint *rowStrideOut) +{ + struct st_context *st = st_context(ctx); + struct st_renderbuffer *strb = st_renderbuffer(rb); + struct pipe_context *pipe = st->pipe; + unsigned usage; + + usage = 0x0; + if (mode & GL_MAP_READ_BIT) + usage |= PIPE_TRANSFER_READ; + if (mode & GL_MAP_WRITE_BIT) + usage |= PIPE_TRANSFER_WRITE; + + strb->transfer = pipe_get_transfer(pipe, + strb->texture, + strb->rtt_level, + strb->rtt_face + strb->rtt_slice, + usage, x, y, w, h); + if (strb->transfer) { + *mapOut = pipe_transfer_map(pipe, strb->transfer); + *rowStrideOut = strb->transfer->stride; + } + else { + *mapOut = NULL; + *rowStrideOut = 0; + } +} + + +/** + * Called via ctx->Driver.UnmapRenderbuffer. + */ +static void +st_UnmapRenderbuffer(struct gl_context *ctx, + struct gl_renderbuffer *rb) +{ + struct st_context *st = st_context(ctx); + struct st_renderbuffer *strb = st_renderbuffer(rb); + struct pipe_context *pipe = st->pipe; + + pipe_transfer_unmap(pipe, strb->transfer); + pipe->transfer_destroy(pipe, strb->transfer); + strb->transfer = NULL; +} + + + void st_init_fbo_functions(struct dd_function_table *functions) { #if FEATURE_EXT_framebuffer_object @@ -647,6 +703,9 @@ void st_init_fbo_functions(struct dd_function_table *functions) functions->DrawBuffers = st_DrawBuffers; functions->ReadBuffer = st_ReadBuffer; + + functions->MapRenderbuffer = st_MapRenderbuffer; + functions->UnmapRenderbuffer = st_UnmapRenderbuffer; } diff --git a/mesalib/src/mesa/state_tracker/st_cb_fbo.h b/mesalib/src/mesa/state_tracker/st_cb_fbo.h index 1afa3fe6e..1be017314 100644 --- a/mesalib/src/mesa/state_tracker/st_cb_fbo.h +++ b/mesalib/src/mesa/state_tracker/st_cb_fbo.h @@ -51,6 +51,8 @@ struct st_renderbuffer enum pipe_format format; /** preferred format, or PIPE_FORMAT_NONE */ GLboolean defined; /**< defined contents? */ + struct pipe_transfer *transfer; /**< only used when mapping the resource */ + /** * Used only when hardware accumulation buffers are not supported. */ diff --git a/mesalib/src/mesa/state_tracker/st_draw.c b/mesalib/src/mesa/state_tracker/st_draw.c index ff3008a5f..f2fbf4836 100644 --- a/mesalib/src/mesa/state_tracker/st_draw.c +++ b/mesalib/src/mesa/state_tracker/st_draw.c @@ -45,7 +45,6 @@ #include "main/bufferobj.h" #include "main/macros.h" #include "main/mfeatures.h" -#include "program/prog_uniform.h" #include "vbo/vbo.h" @@ -64,6 +63,8 @@ #include "draw/draw_context.h" #include "cso_cache/cso_context.h" +#include "../glsl/ir_uniform.h" + static GLuint double_types[4] = { PIPE_FORMAT_R64_FLOAT, @@ -338,8 +339,9 @@ is_interleaved_arrays(const struct st_vertex_program *vp, * or all live in user space. * \param vbuffer returns vertex buffer info * \param velements returns vertex element info + * \return GL_TRUE for success, GL_FALSE otherwise (probably out of memory) */ -static void +static GLboolean setup_interleaved_attribs(struct gl_context *ctx, const struct st_vertex_program *vp, const struct st_vp_variant *vpv, @@ -434,6 +436,11 @@ setup_interleaved_attribs(struct gl_context *ctx, /* all interleaved arrays in a VBO */ struct st_buffer_object *stobj = st_buffer_object(bufobj); + if (!stobj) { + /* probably out of memory */ + return GL_FALSE; + } + vbuffer->buffer = NULL; pipe_resource_reference(&vbuffer->buffer, stobj->buffer); vbuffer->buffer_offset = pointer_to_offset(low_addr); @@ -455,6 +462,8 @@ setup_interleaved_attribs(struct gl_context *ctx, st->user_attrib[0].stride = stride; st->num_user_attribs = 1; } + + return GL_TRUE; } @@ -463,8 +472,9 @@ setup_interleaved_attribs(struct gl_context *ctx, * vertex attribute. * \param vbuffer returns vertex buffer info * \param velements returns vertex element info + * \return GL_TRUE for success, GL_FALSE otherwise (probably out of memory) */ -static void +static GLboolean setup_non_interleaved_attribs(struct gl_context *ctx, const struct st_vertex_program *vp, const struct st_vp_variant *vpv, @@ -493,7 +503,11 @@ setup_non_interleaved_attribs(struct gl_context *ctx, * really an offset from the start of the VBO, not a pointer. */ struct st_buffer_object *stobj = st_buffer_object(bufobj); - assert(stobj->buffer); + + if (!stobj || !stobj->buffer) { + /* probably ran out of memory */ + return GL_FALSE; + } vbuffer[attr].buffer = NULL; pipe_resource_reference(&vbuffer[attr].buffer, stobj->buffer); @@ -533,6 +547,11 @@ setup_non_interleaved_attribs(struct gl_context *ctx, st->user_attrib[attr].element_size = element_size; st->user_attrib[attr].stride = stride; st->num_user_attribs = MAX2(st->num_user_attribs, attr + 1); + + if (!vbuffer[attr].buffer) { + /* probably ran out of memory */ + return GL_FALSE; + } } /* common-case setup */ @@ -547,6 +566,8 @@ setup_non_interleaved_attribs(struct gl_context *ctx, array->Normalized); assert(velements[attr].src_format); } + + return GL_TRUE; } @@ -616,12 +637,12 @@ check_uniforms(struct gl_context *ctx) if (shProg[j] == NULL || !shProg[j]->LinkStatus) continue; - for (i = 0; i < shProg[j]->Uniforms->NumUniforms; i++) { - const struct gl_uniform *u = &shProg[j]->Uniforms->Uniforms[i]; - if (!u->Initialized) { + for (i = 0; i < shProg[j]->NumUserUniformStorage; i++) { + const struct gl_uniform_storage *u = &shProg[j]->UniformStorage[i]; + if (!u->initialized) { _mesa_warning(ctx, "Using shader with uninitialized uniform: %s", - u->Name); + u->name); } } } @@ -775,7 +796,11 @@ translate_prim(const struct gl_context *ctx, unsigned prim) } -static void +/** + * Setup vertex arrays and buffers prior to drawing. + * \return GL_TRUE for success, GL_FALSE otherwise (probably out of memory) + */ +static GLboolean st_validate_varrays(struct gl_context *ctx, const struct gl_client_array **arrays, unsigned max_index, @@ -806,8 +831,10 @@ st_validate_varrays(struct gl_context *ctx, * Setup the vbuffer[] and velements[] arrays. */ if (is_interleaved_arrays(vp, vpv, arrays)) { - setup_interleaved_attribs(ctx, vp, vpv, arrays, vbuffer, velements, - max_index, num_instances); + if (!setup_interleaved_attribs(ctx, vp, vpv, arrays, vbuffer, velements, + max_index, num_instances)) { + return GL_FALSE; + } num_vbuffers = 1; num_velements = vpv->num_inputs; @@ -815,9 +842,12 @@ st_validate_varrays(struct gl_context *ctx, num_vbuffers = 0; } else { - setup_non_interleaved_attribs(ctx, vp, vpv, arrays, - vbuffer, velements, max_index, - num_instances); + if (!setup_non_interleaved_attribs(ctx, vp, vpv, arrays, + vbuffer, velements, max_index, + num_instances)) { + return GL_FALSE; + } + num_vbuffers = vpv->num_inputs; num_velements = vpv->num_inputs; } @@ -832,6 +862,8 @@ st_validate_varrays(struct gl_context *ctx, pipe_resource_reference(&vbuffer[attr].buffer, NULL); assert(!vbuffer[attr].buffer); } + + return GL_TRUE; } @@ -901,7 +933,10 @@ st_draw_vbo(struct gl_context *ctx, st_validate_state(st); if (new_array) { - st_validate_varrays(ctx, arrays, max_index, num_instances); + if (!st_validate_varrays(ctx, arrays, max_index, num_instances)) { + /* probably out of memory, no-op the draw call */ + return; + } } #if 0 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 529f5f64a..b133164c3 100644 --- a/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp +++ b/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp @@ -53,7 +53,6 @@ extern "C" { #include "program/prog_optimize.h" #include "program/prog_print.h" #include "program/program.h" -#include "program/prog_uniform.h" #include "program/prog_parameter.h" #include "program/sampler.h" @@ -2984,12 +2983,12 @@ set_uniform_initializer(struct gl_context *ctx, void *mem_ctx, element_type->matrix_columns, element_type->vector_elements, loc, 1, GL_FALSE, (GLfloat *)values); - loc += element_type->matrix_columns; } else { _mesa_uniform(ctx, shader_program, loc, element_type->matrix_columns, values, element_type->gl_type); - loc += type_size(element_type); } + + loc++; } } @@ -5004,6 +5003,15 @@ get_mesa_program(struct gl_context *ctx, _mesa_reference_program(ctx, &shader->Program, prog); + /* This has to be done last. Any operation the can cause + * prog->ParameterValues to get reallocated (e.g., anything that adds a + * program constant) has to happen before creating this linkage. + */ + _mesa_associate_uniform_storage(ctx, shader_program, prog->Parameters); + if (!shader_program->LinkStatus) { + return NULL; + } + struct st_vertex_program *stvp; struct st_fragment_program *stfp; struct st_geometry_program *stgp; diff --git a/mesalib/src/mesa/state_tracker/st_program.c b/mesalib/src/mesa/state_tracker/st_program.c index 146e77f9d..e03157940 100644 --- a/mesalib/src/mesa/state_tracker/st_program.c +++ b/mesalib/src/mesa/state_tracker/st_program.c @@ -416,7 +416,9 @@ st_get_vp_variant(struct st_context *st, return vpv; } -static int st_translate_interp(enum glsl_interp_qualifier glsl_qual) + +static unsigned +st_translate_interp(enum glsl_interp_qualifier glsl_qual) { switch (glsl_qual) { case INTERP_QUALIFIER_NONE: @@ -426,11 +428,13 @@ static int st_translate_interp(enum glsl_interp_qualifier glsl_qual) return TGSI_INTERPOLATE_CONSTANT; case INTERP_QUALIFIER_NOPERSPECTIVE: return TGSI_INTERPOLATE_LINEAR; + default: + assert(0 && "unexpected interp mode in st_translate_interp()"); + return TGSI_INTERPOLATE_PERSPECTIVE; } - assert(0); - return TGSI_INTERPOLATE_PERSPECTIVE; } + /** * Translate a Mesa fragment shader into a TGSI shader using extra info in * the key. @@ -632,8 +636,10 @@ st_translate_fragment_program(struct st_context *st, } ureg = ureg_create( TGSI_PROCESSOR_FRAGMENT ); - if (ureg == NULL) + if (ureg == NULL) { + FREE(variant); return NULL; + } if (ST_DEBUG & DEBUG_MESA) { _mesa_print_program(&stfp->Base.Base); |