On Fri, Jun 13, 2014 at 8:59 PM, Neil Roberts <n...@linux.intel.com> wrote: > Adds an implmentation of the ClearTexSubImage driver entry point that just > maps the texture and writes the values in. This should work as a reliable > fallback on any driver.
Will it? What about the MS case? I thought that for generic you had to do a shader-based approach. > --- > src/mesa/drivers/common/driverfuncs.c | 2 + > src/mesa/main/texstore.c | 70 > +++++++++++++++++++++++++++++++++++ > src/mesa/main/texstore.h | 7 ++++ > 3 files changed, 79 insertions(+) > > diff --git a/src/mesa/drivers/common/driverfuncs.c > b/src/mesa/drivers/common/driverfuncs.c > index ee8b390..34b6fef 100644 > --- a/src/mesa/drivers/common/driverfuncs.c > +++ b/src/mesa/drivers/common/driverfuncs.c > @@ -95,6 +95,7 @@ _mesa_init_driver_functions(struct dd_function_table > *driver) > driver->TexImage = _mesa_store_teximage; > driver->TexSubImage = _mesa_store_texsubimage; > driver->GetTexImage = _mesa_meta_GetTexImage; > + driver->ClearTexSubImage = _mesa_store_cleartexsubimage; > driver->CopyTexSubImage = _mesa_meta_CopyTexSubImage; > driver->GenerateMipmap = _mesa_meta_GenerateMipmap; > driver->TestProxyTexImage = _mesa_test_proxy_teximage; > @@ -333,4 +334,5 @@ _mesa_init_driver_state(struct gl_context *ctx) > void > _mesa_init_driver_extensions(struct gl_context *ctx) > { > + ctx->Extensions.ARB_clear_texture = GL_TRUE; > } > diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c > index cb81f3f..9c90492 100644 > --- a/src/mesa/main/texstore.c > +++ b/src/mesa/main/texstore.c > @@ -4157,6 +4157,76 @@ _mesa_store_texsubimage(struct gl_context *ctx, GLuint > dims, > format, type, pixels, packing, "glTexSubImage"); > } > > +static void > +clear_image_to_zero(GLubyte *dstMap, GLint dstRowStride, > + GLsizei width, GLsizei height, > + GLsizei clearValueSize) > +{ > + while (height-- > 0) { While I'm sure we all love the while (height --> 0) { // as height goes to 0 construct... it's not immediately obvious (to me) that it's correct when just glancing at it. After a few seconds of thought, it is clearly right, but I think the more common thing is to use a for loop where it's obvious there isn't some silly off-by-one error. I don't think this is really used anywhere else in mesa. Here and below. > + memset(dstMap, 0, clearValueSize * width); > + dstMap += dstRowStride; > + } > +} > + > +static void > +clear_image_to_value(GLubyte *dstMap, GLint dstRowStride, > + GLsizei width, GLsizei height, > + const GLvoid *clearValue, > + GLsizei clearValueSize) > +{ > + GLsizei x; > + > + while (height-- > 0) { > + for (x = 0; x < width; x++) { > + memcpy(dstMap, clearValue, clearValueSize); > + dstMap += clearValueSize; > + } > + dstMap += dstRowStride - clearValueSize * width; > + } > +} > + > +/* > + * Fallback for Driver.ClearTexSubImage(). > + */ > +void > +_mesa_store_cleartexsubimage(struct gl_context *ctx, > + struct gl_texture_image *texImage, > + GLint xoffset, GLint yoffset, GLint zoffset, > + GLsizei width, GLsizei height, GLsizei depth, > + const GLvoid *clearValue) > +{ > + GLubyte *dstMap; > + GLint dstRowStride; > + GLsizeiptr clearValueSize; > + GLsizei z; > + > + clearValueSize = _mesa_get_format_bytes(texImage->TexFormat); > + > + for (z = 0; z < depth; z++) { > + ctx->Driver.MapTextureImage(ctx, texImage, > + z + zoffset, xoffset, yoffset, > + width, height, > + GL_MAP_WRITE_BIT, > + &dstMap, &dstRowStride); > + if (dstMap == NULL) { > + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glClearTex*Image"); > + return; > + } > + > + if (clearValue) { > + clear_image_to_value(dstMap, dstRowStride, > + width, height, > + clearValue, > + clearValueSize); > + } else { > + clear_image_to_zero(dstMap, dstRowStride, > + width, height, > + clearValueSize); > + } > + > + ctx->Driver.UnmapTextureImage(ctx, texImage, z + zoffset); > + } > +} > > /** > * Fallback for Driver.CompressedTexImage() > diff --git a/src/mesa/main/texstore.h b/src/mesa/main/texstore.h > index c4cfffd..dd1e1d0 100644 > --- a/src/mesa/main/texstore.h > +++ b/src/mesa/main/texstore.h > @@ -118,6 +118,13 @@ _mesa_store_texsubimage(struct gl_context *ctx, GLuint > dims, > > > extern void > +_mesa_store_cleartexsubimage(struct gl_context *ctx, > + struct gl_texture_image *texImage, > + GLint xoffset, GLint yoffset, GLint zoffset, > + GLsizei width, GLsizei height, GLsizei depth, > + const GLvoid *clearValue); > + > +extern void > _mesa_store_compressed_teximage(struct gl_context *ctx, GLuint dims, > struct gl_texture_image *texImage, > GLsizei imageSize, const GLvoid *data); > -- > 1.9.3 > > _______________________________________________ > mesa-dev mailing list > mesa-dev@lists.freedesktop.org > http://lists.freedesktop.org/mailman/listinfo/mesa-dev _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev