diff options
Diffstat (limited to 'src/mesa')
39 files changed, 750 insertions, 524 deletions
diff --git a/src/mesa/drivers/dri/i915/i915_reg.h b/src/mesa/drivers/dri/i915/i915_reg.h index b02e2c7628..84db58ea95 100644 --- a/src/mesa/drivers/dri/i915/i915_reg.h +++ b/src/mesa/drivers/dri/i915/i915_reg.h @@ -141,6 +141,7 @@ /* p161 */ #define _3DSTATE_DST_BUF_VARS_CMD (CMD_3D | (0x1d<<24) | (0x85<<16)) /* Dword 1 */ +#define CLASSIC_EARLY_DEPTH (1<<31) #define TEX_DEFAULT_COLOR_OGL (0<<30) #define TEX_DEFAULT_COLOR_D3D (1<<30) #define ZR_EARLY_DEPTH (1<<29) diff --git a/src/mesa/drivers/dri/i915/i915_vtbl.c b/src/mesa/drivers/dri/i915/i915_vtbl.c index 6ecbc4709b..2fca247af1 100644 --- a/src/mesa/drivers/dri/i915/i915_vtbl.c +++ b/src/mesa/drivers/dri/i915/i915_vtbl.c @@ -42,6 +42,7 @@ #include "intel_regions.h" #include "intel_tris.h" #include "intel_fbo.h" +#include "intel_chipset.h" #include "i915_reg.h" #include "i915_context.h" @@ -611,6 +612,14 @@ i915_state_draw_region(struct intel_context *intel, } } + /* This isn't quite safe, thus being hidden behind an option. When changing + * the value of this bit, the pipeline needs to be MI_FLUSHed. And it + * can only be set when a depth buffer is already defined. + */ + if (IS_945(intel->intelScreen->deviceID) && intel->use_early_z && + depth_region->tiling != I915_TILING_NONE) + value |= CLASSIC_EARLY_DEPTH; + if (depth_region && depth_region->cpp == 4) { value |= DEPTH_FRMT_24_FIXED_8_OTHER; } diff --git a/src/mesa/drivers/dri/intel/intel_clear.c b/src/mesa/drivers/dri/intel/intel_clear.c index 4dfaee8a4a..309ac1923b 100644 --- a/src/mesa/drivers/dri/intel/intel_clear.c +++ b/src/mesa/drivers/dri/intel/intel_clear.c @@ -53,6 +53,7 @@ #include "intel_clear.h" #include "intel_fbo.h" #include "intel_pixel.h" +#include "intel_regions.h" #define FILE_DEBUG_FLAG DEBUG_BLIT @@ -312,7 +313,6 @@ static const char *buffer_names[] = { static void intelClear(GLcontext *ctx, GLbitfield mask) { - struct intel_context *intel = intel_context(ctx); const GLuint colorMask = *((GLuint *) & ctx->Color.ColorMask); GLbitfield tri_mask = 0; GLbitfield blit_mask = 0; @@ -340,7 +340,7 @@ intelClear(GLcontext *ctx, GLbitfield mask) = intel_get_rb_region(fb, BUFFER_STENCIL); if (stencilRegion) { /* have hw stencil */ - if (IS_965(intel->intelScreen->deviceID) || + if (stencilRegion->tiling == I915_TILING_Y || (ctx->Stencil.WriteMask[0] & 0xff) != 0xff) { /* We have to use the 3D engine if we're clearing a partial mask * of the stencil buffer, or if we're on a 965 which has a tiled @@ -357,9 +357,10 @@ intelClear(GLcontext *ctx, GLbitfield mask) /* HW depth */ if (mask & BUFFER_BIT_DEPTH) { + const struct intel_region *irb = intel_get_rb_region(fb, BUFFER_DEPTH); + /* clear depth with whatever method is used for stencil (see above) */ - if (IS_965(intel->intelScreen->deviceID) || - tri_mask & BUFFER_BIT_STENCIL) + if (irb->tiling == I915_TILING_Y || tri_mask & BUFFER_BIT_STENCIL) tri_mask |= BUFFER_BIT_DEPTH; else blit_mask |= BUFFER_BIT_DEPTH; diff --git a/src/mesa/drivers/dri/intel/intel_context.c b/src/mesa/drivers/dri/intel/intel_context.c index fa931d7f62..f88b37d0f3 100644 --- a/src/mesa/drivers/dri/intel/intel_context.c +++ b/src/mesa/drivers/dri/intel/intel_context.c @@ -550,6 +550,9 @@ intelInitDriverFunctions(struct dd_function_table *functions) functions->CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D; intelInitTextureFuncs(functions); + intelInitTextureImageFuncs(functions); + intelInitTextureSubImageFuncs(functions); + intelInitTextureCopyImageFuncs(functions); intelInitStateFuncs(functions); intelInitClearFuncs(functions); intelInitBufferFuncs(functions); @@ -726,6 +729,7 @@ intelInitContext(struct intel_context *intel, } intel->use_texture_tiling = driQueryOptionb(&intel->optionCache, "texture_tiling"); + intel->use_early_z = driQueryOptionb(&intel->optionCache, "early_z"); intel->prim.primitive = ~0; diff --git a/src/mesa/drivers/dri/intel/intel_context.h b/src/mesa/drivers/dri/intel/intel_context.h index 4e45f1a91f..7d3c80bb21 100644 --- a/src/mesa/drivers/dri/intel/intel_context.h +++ b/src/mesa/drivers/dri/intel/intel_context.h @@ -306,6 +306,7 @@ struct intel_context GLboolean is_front_buffer_rendering; GLboolean use_texture_tiling; + GLboolean use_early_z; drm_clip_rect_t fboRect; /**< cliprect for FBO rendering */ diff --git a/src/mesa/drivers/dri/intel/intel_pixel_draw.c b/src/mesa/drivers/dri/intel/intel_pixel_draw.c index 7cda6adb32..46d27f1a93 100644 --- a/src/mesa/drivers/dri/intel/intel_pixel_draw.c +++ b/src/mesa/drivers/dri/intel/intel_pixel_draw.c @@ -96,7 +96,7 @@ intel_texture_drawpixels(GLcontext * ctx, /* We don't have a way to generate fragments with stencil values which * will set the resulting stencil value. */ - if (format == GL_STENCIL_INDEX) + if (format == GL_STENCIL_INDEX || format == GL_DEPTH_STENCIL) return GL_FALSE; /* Check that we can load in a texture this big. */ diff --git a/src/mesa/drivers/dri/intel/intel_regions.c b/src/mesa/drivers/dri/intel/intel_regions.c index fd9bf7b174..49bcb3c1dd 100644 --- a/src/mesa/drivers/dri/intel/intel_regions.c +++ b/src/mesa/drivers/dri/intel/intel_regions.c @@ -132,7 +132,7 @@ intel_region_unmap(struct intel_context *intel, struct intel_region *region) _DBG("%s %p\n", __FUNCTION__, region); if (!--region->map_refcount) { if (intel->intelScreen->kernel_exec_fencing) - drm_intel_gem_bo_map_gtt(region->buffer); + drm_intel_gem_bo_unmap_gtt(region->buffer); else dri_bo_unmap(region->buffer); region->map = NULL; diff --git a/src/mesa/drivers/dri/intel/intel_screen.c b/src/mesa/drivers/dri/intel/intel_screen.c index 6521b4ef31..8da96ede64 100644 --- a/src/mesa/drivers/dri/intel/intel_screen.c +++ b/src/mesa/drivers/dri/intel/intel_screen.c @@ -75,6 +75,10 @@ PUBLIC const char __driConfigOptions[] = DRI_CONF_TEXTURE_TILING(true) #endif + DRI_CONF_OPT_BEGIN(early_z, bool, false) + DRI_CONF_DESC(en, "Enable early Z in classic mode (unstable, 945-only).") + DRI_CONF_OPT_END + DRI_CONF_SECTION_END DRI_CONF_SECTION_QUALITY DRI_CONF_FORCE_S3TC_ENABLE(false) @@ -87,7 +91,7 @@ PUBLIC const char __driConfigOptions[] = DRI_CONF_SECTION_END DRI_CONF_END; -const GLuint __driNConfigOptions = 9; +const GLuint __driNConfigOptions = 10; #ifdef USE_NEW_INTERFACE static PFNGLXCREATECONTEXTMODES create_context_modes = NULL; @@ -247,7 +251,7 @@ intel_get_param(__DRIscreenPrivate *psp, int param, int *value) ret = drmCommandWriteRead(psp->fd, DRM_I915_GETPARAM, &gp, sizeof(gp)); if (ret) { - _mesa_warning(NULL, "drm_i915_getparam: %d\n", ret); + _mesa_warning(NULL, "drm_i915_getparam: %d", ret); return GL_FALSE; } diff --git a/src/mesa/drivers/dri/intel/intel_tex.c b/src/mesa/drivers/dri/intel/intel_tex.c index fbd6e1d0c3..df63f29a42 100644 --- a/src/mesa/drivers/dri/intel/intel_tex.c +++ b/src/mesa/drivers/dri/intel/intel_tex.c @@ -162,24 +162,8 @@ void intelInitTextureFuncs(struct dd_function_table *functions) { functions->ChooseTextureFormat = intelChooseTextureFormat; - functions->TexImage1D = intelTexImage1D; - functions->TexImage2D = intelTexImage2D; - functions->TexImage3D = intelTexImage3D; - functions->TexSubImage1D = intelTexSubImage1D; - functions->TexSubImage2D = intelTexSubImage2D; - functions->TexSubImage3D = intelTexSubImage3D; - functions->CopyTexImage1D = intelCopyTexImage1D; - functions->CopyTexImage2D = intelCopyTexImage2D; - functions->CopyTexSubImage1D = intelCopyTexSubImage1D; - functions->CopyTexSubImage2D = intelCopyTexSubImage2D; - functions->GetTexImage = intelGetTexImage; functions->GenerateMipmap = intel_generate_mipmap; - /* compressed texture functions */ - functions->CompressedTexImage2D = intelCompressedTexImage2D; - functions->CompressedTexSubImage2D = intelCompressedTexSubImage2D; - functions->GetCompressedTexImage = intelGetCompressedTexImage; - functions->NewTextureObject = intelNewTextureObject; functions->NewTextureImage = intelNewTextureImage; functions->DeleteTexture = intelDeleteTextureObject; diff --git a/src/mesa/drivers/dri/intel/intel_tex.h b/src/mesa/drivers/dri/intel/intel_tex.h index f5372d82fb..471aa2a240 100644 --- a/src/mesa/drivers/dri/intel/intel_tex.h +++ b/src/mesa/drivers/dri/intel/intel_tex.h @@ -35,116 +35,17 @@ void intelInitTextureFuncs(struct dd_function_table *functions); +void intelInitTextureImageFuncs(struct dd_function_table *functions); + +void intelInitTextureSubImageFuncs(struct dd_function_table *functions); + +void intelInitTextureCopyImageFuncs(struct dd_function_table *functions); + const struct gl_texture_format *intelChooseTextureFormat(GLcontext * ctx, GLint internalFormat, GLenum format, GLenum type); - -void intelTexImage3D(GLcontext * ctx, - GLenum target, GLint level, - GLint internalFormat, - GLint width, GLint height, GLint depth, - GLint border, - GLenum format, GLenum type, const void *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage); - -void intelTexSubImage3D(GLcontext * ctx, - GLenum target, - GLint level, - GLint xoffset, GLint yoffset, GLint zoffset, - GLsizei width, GLsizei height, GLsizei depth, - GLenum format, GLenum type, - const GLvoid * pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage); - -void intelTexImage2D(GLcontext * ctx, - GLenum target, GLint level, - GLint internalFormat, - GLint width, GLint height, GLint border, - GLenum format, GLenum type, const void *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage); - -void intelTexSubImage2D(GLcontext * ctx, - GLenum target, - GLint level, - GLint xoffset, GLint yoffset, - GLsizei width, GLsizei height, - GLenum format, GLenum type, - const GLvoid * pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage); - -void intelTexImage1D(GLcontext * ctx, - GLenum target, GLint level, - GLint internalFormat, - GLint width, GLint border, - GLenum format, GLenum type, const void *pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage); - -void intelTexSubImage1D(GLcontext * ctx, - GLenum target, - GLint level, - GLint xoffset, - GLsizei width, - GLenum format, GLenum type, - const GLvoid * pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage); - -void intelCopyTexImage1D(GLcontext * ctx, GLenum target, GLint level, - GLenum internalFormat, - GLint x, GLint y, GLsizei width, GLint border); - -void intelCopyTexImage2D(GLcontext * ctx, GLenum target, GLint level, - GLenum internalFormat, - GLint x, GLint y, GLsizei width, GLsizei height, - GLint border); - -void intelCopyTexSubImage1D(GLcontext * ctx, GLenum target, GLint level, - GLint xoffset, GLint x, GLint y, GLsizei width); - -void intelCopyTexSubImage2D(GLcontext * ctx, GLenum target, GLint level, - GLint xoffset, GLint yoffset, - GLint x, GLint y, GLsizei width, GLsizei height); - -void intelGetTexImage(GLcontext * ctx, GLenum target, GLint level, - GLenum format, GLenum type, GLvoid * pixels, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage); - -void intelCompressedTexImage2D( GLcontext *ctx, GLenum target, GLint level, - GLint internalFormat, - GLint width, GLint height, GLint border, - GLsizei imageSize, const GLvoid *data, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage ); - -void intelCompressedTexSubImage2D(GLcontext * ctx, - GLenum target, - GLint level, - GLint xoffset, GLint yoffset, - GLsizei width, GLsizei height, - GLenum format, GLsizei imageSize, - const GLvoid * pixels, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage); - -void intelGetCompressedTexImage(GLcontext *ctx, GLenum target, GLint level, - GLvoid *pixels, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage); - void intelSetTexOffset(__DRIcontext *pDRICtx, GLint texname, unsigned long long offset, GLint depth, GLuint pitch); void intelSetTexBuffer(__DRIcontext *pDRICtx, diff --git a/src/mesa/drivers/dri/intel/intel_tex_copy.c b/src/mesa/drivers/dri/intel/intel_tex_copy.c index 673b8fa6a1..260235b1eb 100644 --- a/src/mesa/drivers/dri/intel/intel_tex_copy.c +++ b/src/mesa/drivers/dri/intel/intel_tex_copy.c @@ -169,10 +169,7 @@ do_copy_texsubimage(struct intel_context *intel, } - - - -void +static void intelCopyTexImage1D(GLcontext * ctx, GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLint border) @@ -218,7 +215,8 @@ intelCopyTexImage1D(GLcontext * ctx, GLenum target, GLint level, width, border); } -void + +static void intelCopyTexImage2D(GLcontext * ctx, GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, @@ -266,7 +264,7 @@ intelCopyTexImage2D(GLcontext * ctx, GLenum target, GLint level, } -void +static void intelCopyTexSubImage1D(GLcontext * ctx, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width) { @@ -291,8 +289,7 @@ intelCopyTexSubImage1D(GLcontext * ctx, GLenum target, GLint level, } - -void +static void intelCopyTexSubImage2D(GLcontext * ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) @@ -305,7 +302,6 @@ intelCopyTexSubImage2D(GLcontext * ctx, GLenum target, GLint level, _mesa_select_tex_image(ctx, texObj, target, level); GLenum internalFormat = texImage->InternalFormat; - /* Need to check texture is compatible with source format. */ @@ -320,3 +316,13 @@ intelCopyTexSubImage2D(GLcontext * ctx, GLenum target, GLint level, xoffset, yoffset, x, y, width, height); } } + + +void +intelInitTextureCopyImageFuncs(struct dd_function_table *functions) +{ + functions->CopyTexImage1D = intelCopyTexImage1D; + functions->CopyTexImage2D = intelCopyTexImage2D; + functions->CopyTexSubImage1D = intelCopyTexSubImage1D; + functions->CopyTexSubImage2D = intelCopyTexSubImage2D; +} diff --git a/src/mesa/drivers/dri/intel/intel_tex_image.c b/src/mesa/drivers/dri/intel/intel_tex_image.c index ddbb13e74a..e9a3823078 100644 --- a/src/mesa/drivers/dri/intel/intel_tex_image.c +++ b/src/mesa/drivers/dri/intel/intel_tex_image.c @@ -248,7 +248,6 @@ try_pbo_upload(struct intel_context *intel, } - static GLboolean try_pbo_zcopy(struct intel_context *intel, struct intel_texture_image *intelImage, @@ -293,10 +292,6 @@ try_pbo_zcopy(struct intel_context *intel, } - - - - static void intelTexImage(GLcontext * ctx, GLint dims, @@ -307,7 +302,8 @@ intelTexImage(GLcontext * ctx, GLenum format, GLenum type, const void *pixels, const struct gl_pixelstore_attrib *unpack, struct gl_texture_object *texObj, - struct gl_texture_image *texImage, GLsizei imageSize, int compressed) + struct gl_texture_image *texImage, GLsizei imageSize, + GLboolean compressed) { struct intel_context *intel = intel_context(ctx); struct intel_texture_object *intelObj = intel_texture_object(texObj); @@ -463,8 +459,6 @@ intelTexImage(GLcontext * ctx, DBG("pbo upload failed\n"); } - - /* intelCopyTexImage calls this function with pixels == NULL, with * the expectation that the mipmap tree will be set up but nothing * more will be done. This is where those calls return: @@ -557,7 +551,8 @@ intelTexImage(GLcontext * ctx, } } -void + +static void intelTexImage3D(GLcontext * ctx, GLenum target, GLint level, GLint internalFormat, @@ -570,11 +565,11 @@ intelTexImage3D(GLcontext * ctx, { intelTexImage(ctx, 3, target, level, internalFormat, width, height, depth, border, - format, type, pixels, unpack, texObj, texImage, 0, 0); + format, type, pixels, unpack, texObj, texImage, 0, GL_FALSE); } -void +static void intelTexImage2D(GLcontext * ctx, GLenum target, GLint level, GLint internalFormat, @@ -586,10 +581,11 @@ intelTexImage2D(GLcontext * ctx, { intelTexImage(ctx, 2, target, level, internalFormat, width, height, 1, border, - format, type, pixels, unpack, texObj, texImage, 0, 0); + format, type, pixels, unpack, texObj, texImage, 0, GL_FALSE); } -void + +static void intelTexImage1D(GLcontext * ctx, GLenum target, GLint level, GLint internalFormat, @@ -601,21 +597,24 @@ intelTexImage1D(GLcontext * ctx, { intelTexImage(ctx, 1, target, level, internalFormat, width, 1, 1, border, - format, type, pixels, unpack, texObj, texImage, 0, 0); + format, type, pixels, unpack, texObj, texImage, 0, GL_FALSE); } -void intelCompressedTexImage2D( GLcontext *ctx, GLenum target, GLint level, - GLint internalFormat, - GLint width, GLint height, GLint border, - GLsizei imageSize, const GLvoid *data, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage ) + +static void +intelCompressedTexImage2D( GLcontext *ctx, GLenum target, GLint level, + GLint internalFormat, + GLint width, GLint height, GLint border, + GLsizei imageSize, const GLvoid *data, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage ) { intelTexImage(ctx, 2, target, level, internalFormat, width, height, 1, border, - 0, 0, data, &ctx->Unpack, texObj, texImage, imageSize, 1); + 0, 0, data, &ctx->Unpack, texObj, texImage, imageSize, GL_TRUE); } + /** * Need to map texture image into memory before copying image data, * then unmap it. @@ -624,11 +623,17 @@ static void intel_get_tex_image(GLcontext * ctx, GLenum target, GLint level, GLenum format, GLenum type, GLvoid * pixels, struct gl_texture_object *texObj, - struct gl_texture_image *texImage, int compressed) + struct gl_texture_image *texImage, GLboolean compressed) { struct intel_context *intel = intel_context(ctx); struct intel_texture_image *intelImage = intel_texture_image(texImage); + /* If we're reading from a texture that has been rendered to, need to + * make sure rendering is complete. + * We could probably predicate this on texObj->_RenderToTexture + */ + intelFlush(ctx); + /* Map */ if (intelImage->mt) { /* Image is stored in hardware format in a buffer managed by the @@ -672,28 +677,29 @@ intel_get_tex_image(GLcontext * ctx, GLenum target, GLint level, } } -void + +static void intelGetTexImage(GLcontext * ctx, GLenum target, GLint level, GLenum format, GLenum type, GLvoid * pixels, struct gl_texture_object *texObj, struct gl_texture_image *texImage) { intel_get_tex_image(ctx, target, level, format, type, pixels, - texObj, texImage, 0); - - + texObj, texImage, GL_FALSE); } -void + +static void intelGetCompressedTexImage(GLcontext *ctx, GLenum target, GLint level, GLvoid *pixels, struct gl_texture_object *texObj, struct gl_texture_image *texImage) { intel_get_tex_image(ctx, target, level, 0, 0, pixels, - texObj, texImage, 1); + texObj, texImage, GL_TRUE); } + void intelSetTexOffset(__DRIcontext *pDRICtx, GLint texname, unsigned long long offset, GLint depth, GLuint pitch) @@ -802,3 +808,16 @@ intelSetTexBuffer(__DRIcontext *pDRICtx, GLint target, __DRIdrawable *dPriv) */ intelSetTexBuffer2(pDRICtx, target, GLX_TEXTURE_FORMAT_RGBA_EXT, dPriv); } + + +void +intelInitTextureImageFuncs(struct dd_function_table *functions) +{ + functions->TexImage1D = intelTexImage1D; + functions->TexImage2D = intelTexImage2D; + functions->TexImage3D = intelTexImage3D; + functions->GetTexImage = intelGetTexImage; + + functions->CompressedTexImage2D = intelCompressedTexImage2D; + functions->GetCompressedTexImage = intelGetCompressedTexImage; +} diff --git a/src/mesa/drivers/dri/intel/intel_tex_layout.c b/src/mesa/drivers/dri/intel/intel_tex_layout.c index b8be7ef41a..2c1b722b7f 100644 --- a/src/mesa/drivers/dri/intel/intel_tex_layout.c +++ b/src/mesa/drivers/dri/intel/intel_tex_layout.c @@ -88,11 +88,6 @@ void i945_miptree_layout_2d( struct intel_context *intel, if (mip1_width > mt->pitch) { mt->pitch = mip1_width; - - if (tiling == I915_TILING_X) - mt->pitch = ALIGN(mt->pitch * mt->cpp, 512) / mt->cpp; - if (tiling == I915_TILING_Y) - mt->pitch = ALIGN(mt->pitch * mt->cpp, 128) / mt->cpp; } } diff --git a/src/mesa/drivers/dri/intel/intel_tex_subimage.c b/src/mesa/drivers/dri/intel/intel_tex_subimage.c index 48104de2a9..1f27131dac 100644 --- a/src/mesa/drivers/dri/intel/intel_tex_subimage.c +++ b/src/mesa/drivers/dri/intel/intel_tex_subimage.c @@ -117,10 +117,7 @@ intelTexSubimage(GLcontext * ctx, } - - - -void +static void intelTexSubImage3D(GLcontext * ctx, GLenum target, GLint level, @@ -132,18 +129,15 @@ intelTexSubImage3D(GLcontext * ctx, struct gl_texture_object *texObj, struct gl_texture_image *texImage) { - intelTexSubimage(ctx, 3, target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels, packing, texObj, texImage); - } - -void +static void intelTexSubImage2D(GLcontext * ctx, GLenum target, GLint level, @@ -155,17 +149,15 @@ intelTexSubImage2D(GLcontext * ctx, struct gl_texture_object *texObj, struct gl_texture_image *texImage) { - intelTexSubimage(ctx, 2, target, level, xoffset, yoffset, 0, width, height, 1, format, type, pixels, packing, texObj, texImage); - } -void +static void intelTexSubImage1D(GLcontext * ctx, GLenum target, GLint level, @@ -182,10 +174,9 @@ intelTexSubImage1D(GLcontext * ctx, xoffset, 0, 0, width, 1, 1, format, type, pixels, packing, texObj, texImage); - } -void +static void intelCompressedTexSubImage2D(GLcontext * ctx, GLenum target, GLint level, @@ -199,3 +190,14 @@ intelCompressedTexSubImage2D(GLcontext * ctx, fprintf(stderr, "stubbed CompressedTexSubImage2D: %dx%d@%dx%d\n", width, height, xoffset, yoffset); } + + + +void +intelInitTextureSubImageFuncs(struct dd_function_table *functions) +{ + functions->TexSubImage1D = intelTexSubImage1D; + functions->TexSubImage2D = intelTexSubImage2D; + functions->TexSubImage3D = intelTexSubImage3D; + functions->CompressedTexSubImage2D = intelCompressedTexSubImage2D; +} diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c index 3e011ef5b2..a49da3d3b5 100644 --- a/src/mesa/main/bufferobj.c +++ b/src/mesa/main/bufferobj.c @@ -39,6 +39,11 @@ #include "bufferobj.h" +/* Debug flags */ +/*#define VBO_DEBUG*/ +/*#define BOUNDS_CHECK*/ + + #ifdef FEATURE_OES_mapbuffer #define DEFAULT_ACCESS GL_WRITE_ONLY; #else @@ -1019,6 +1024,9 @@ _mesa_BufferDataARB(GLenum target, GLsizeiptrARB size, bufObj->Name, size, data, usage); #endif +#ifdef BOUNDS_CHECK + size += 100; +#endif /* Give the buffer object to the driver! <data> may be null! */ ctx->Driver.BufferData( ctx, target, size, data, usage, bufObj ); } @@ -1119,6 +1127,17 @@ _mesa_MapBufferARB(GLenum target, GLenum access) } #endif +#ifdef BOUNDS_CHECK + { + GLubyte *buf = (GLubyte *) bufObj->Pointer; + GLuint i; + /* buffer is 100 bytes larger than requested, fill with magic value */ + for (i = 0; i < 100; i++) { + buf[bufObj->Size - i - 1] = 123; + } + } +#endif + return bufObj->Pointer; } @@ -1145,6 +1164,22 @@ _mesa_UnmapBufferARB(GLenum target) return GL_FALSE; } +#ifdef BOUNDS_CHECK + if (bufObj->Access != GL_READ_ONLY_ARB) { + GLubyte *buf = (GLubyte *) bufObj->Pointer; + GLuint i; + /* check that last 100 bytes are still = magic value */ + for (i = 0; i < 100; i++) { + GLuint pos = bufObj->Size - i - 1; + if (buf[pos] != 123) { + _mesa_warning(ctx, "Out of bounds buffer object write detected" + " at position %d (value = %u)\n", + pos, buf[pos]); + } + } + } +#endif + #ifdef VBO_DEBUG if (bufObj->Access == GL_WRITE_ONLY_ARB) { GLuint i, unchanged = 0; diff --git a/src/mesa/main/config.h b/src/mesa/main/config.h index 5a05a65396..f77a29a43e 100644 --- a/src/mesa/main/config.h +++ b/src/mesa/main/config.h @@ -179,7 +179,7 @@ /*@{*/ #define MAX_PROGRAM_INSTRUCTIONS (16 * 1024) #define MAX_PROGRAM_LOCAL_PARAMS 256 /**< per-program constants (power of two) */ -#define MAX_PROGRAM_ENV_PARAMS 128 +#define MAX_PROGRAM_ENV_PARAMS 256 /**< per-context constants (power of two) */ #define MAX_PROGRAM_MATRICES 8 #define MAX_PROGRAM_MATRIX_STACK_DEPTH 4 #define MAX_PROGRAM_CALL_DEPTH 8 @@ -196,7 +196,7 @@ /*@{*/ #define MAX_NV_VERTEX_PROGRAM_INSTRUCTIONS 128 #define MAX_NV_VERTEX_PROGRAM_TEMPS 12 -#define MAX_NV_VERTEX_PROGRAM_PARAMS MAX_PROGRAM_ENV_PARAMS +#define MAX_NV_VERTEX_PROGRAM_PARAMS 96 #define MAX_NV_VERTEX_PROGRAM_INPUTS 16 #define MAX_NV_VERTEX_PROGRAM_OUTPUTS 15 /*@}*/ diff --git a/src/mesa/main/debug.c b/src/mesa/main/debug.c index 7276c22742..1c8c44fcb9 100644 --- a/src/mesa/main/debug.c +++ b/src/mesa/main/debug.c @@ -285,7 +285,7 @@ write_texture_image(struct gl_texture_object *texObj) case MESA_FORMAT_RGB565: { GLubyte *buf2 = (GLubyte *) _mesa_malloc(img->Width * img->Height * 3); - GLint i; + GLuint i; for (i = 0; i < img->Width * img->Height; i++) { GLint r, g, b; GLushort s = ((GLushort *) img->Data)[i]; diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c index aa9513a550..490110a6d2 100644 --- a/src/mesa/main/extensions.c +++ b/src/mesa/main/extensions.c @@ -442,8 +442,9 @@ _mesa_enable_2_1_extensions(GLcontext *ctx) /** * Either enable or disable the named extension. + * \return GL_TRUE for success, GL_FALSE if invalid extension name */ -static void +static GLboolean set_extension( GLcontext *ctx, const char *name, GLboolean state ) { GLboolean *base = (GLboolean *) &ctx->Extensions; @@ -452,7 +453,7 @@ set_extension( GLcontext *ctx, const char *name, GLboolean state ) if (ctx->Extensions.String) { /* The string was already queried - can't change it now! */ _mesa_problem(ctx, "Trying to enable/disable extension after glGetString(GL_EXTENSIONS): %s", name); - return; + return GL_FALSE; } for (i = 0 ; i < Elements(default_extensions) ; i++) { @@ -461,10 +462,10 @@ set_extension( GLcontext *ctx, const char *name, GLboolean state ) GLboolean *enabled = base + default_extensions[i].flag_offset; *enabled = state; } - return; + return GL_TRUE; } } - _mesa_problem(ctx, "Trying to enable unknown extension: %s", name); + return GL_FALSE; } @@ -475,7 +476,8 @@ set_extension( GLcontext *ctx, const char *name, GLboolean state ) void _mesa_enable_extension( GLcontext *ctx, const char *name ) { - set_extension(ctx, name, GL_TRUE); + if (!set_extension(ctx, name, GL_TRUE)) + _mesa_problem(ctx, "Trying to enable unknown extension: %s", name); } @@ -486,7 +488,8 @@ _mesa_enable_extension( GLcontext *ctx, const char *name ) void _mesa_disable_extension( GLcontext *ctx, const char *name ) { - set_extension(ctx, name, GL_FALSE); + if (!set_extension(ctx, name, GL_FALSE)) + _mesa_problem(ctx, "Trying to disable unknown extension: %s", name); } @@ -511,6 +514,80 @@ _mesa_extension_is_enabled( GLcontext *ctx, const char *name ) /** + * Append string 'b' onto string 'a'. Free 'a' and return new string. + */ +static char * +append(const char *a, const char *b) +{ + const GLuint aLen = a ? _mesa_strlen(a) : 0; + const GLuint bLen = b ? _mesa_strlen(b) : 0; + char *s = _mesa_calloc(aLen + bLen + 1); + if (s) { + if (a) + _mesa_memcpy(s, a, aLen); + if (b) + _mesa_memcpy(s + aLen, b, bLen); + s[aLen + bLen] = '\0'; + } + if (a) + _mesa_free((void *) a); + return s; +} + + +/** + * Check the MESA_EXTENSION_OVERRIDE env var. + * For extension names that are recognized, turn them on. For extension + * names that are recognized and prefixed with '-', turn them off. + * Return a string of the unknown/leftover names. + */ +static const char * +get_extension_override( GLcontext *ctx ) +{ + const char *envExt = _mesa_getenv("MESA_EXTENSION_OVERRIDE"); + char *extraExt = NULL; + char ext[1000]; + GLuint extLen = 0; + GLuint i; + GLboolean disableExt = GL_FALSE; + + if (!envExt) + return NULL; + + for (i = 0; ; i++) { + if (envExt[i] == '\0' || envExt[i] == ' ') { + /* terminate/process 'ext' if extLen > 0 */ + if (extLen > 0) { + assert(extLen < sizeof(ext)); + /* enable extension named by 'ext' */ + ext[extLen] = 0; + if (!set_extension(ctx, ext, !disableExt)) { + /* unknown extension name, append it to extraExt */ + if (extraExt) { + extraExt = append(extraExt, " "); + } + extraExt = append(extraExt, ext); + } + extLen = 0; + disableExt = GL_FALSE; + } + if (envExt[i] == '\0') + break; + } + else if (envExt[i] == '-') { + disableExt = GL_TRUE; + } + else { + /* accumulate this non-space character */ + ext[extLen++] = envExt[i]; + } + } + + return extraExt; +} + + +/** * Run through the default_extensions array above and set the * ctx->Extensions.ARB/EXT_* flags accordingly. * To be called during context initialization. @@ -538,8 +615,9 @@ GLubyte * _mesa_make_extension_string( GLcontext *ctx ) { const GLboolean *base = (const GLboolean *) &ctx->Extensions; + const char *extraExt = get_extension_override(ctx); GLuint extStrLen = 0; - GLubyte *s; + char *s; GLuint i; /* first, compute length of the extension string */ @@ -549,7 +627,14 @@ _mesa_make_extension_string( GLcontext *ctx ) extStrLen += (GLuint)_mesa_strlen(default_extensions[i].name) + 1; } } - s = (GLubyte *) _mesa_malloc(extStrLen); + + if (extraExt) + extStrLen += _mesa_strlen(extraExt) + 1; /* +1 for space */ + + /* allocate the extension string */ + s = (char *) _mesa_malloc(extStrLen); + if (!s) + return NULL; /* second, build the extension string */ extStrLen = 0; @@ -559,13 +644,18 @@ _mesa_make_extension_string( GLcontext *ctx ) GLuint len = (GLuint)_mesa_strlen(default_extensions[i].name); _mesa_memcpy(s + extStrLen, default_extensions[i].name, len); extStrLen += len; - s[extStrLen] = (GLubyte) ' '; + s[extStrLen] = ' '; extStrLen++; } } ASSERT(extStrLen > 0); - s[extStrLen - 1] = 0; + s[extStrLen - 1] = 0; /* -1 to overwrite trailing the ' ' */ - return s; + if (extraExt) { + s = append(s, " "); + s = append(s, extraExt); + } + + return (GLubyte *) s; } diff --git a/src/mesa/main/image.c b/src/mesa/main/image.c index c06031e6cb..090e5eb330 100644 --- a/src/mesa/main/image.c +++ b/src/mesa/main/image.c @@ -2874,7 +2874,7 @@ extract_uint_indexes(GLuint n, GLuint indexes[], } else { for (i = 0; i < n; i++) - indexes[i] = s[i] & 0xfff; /* lower 8 bits */ + indexes[i] = s[i] & 0xff; /* lower 8 bits */ } } break; diff --git a/src/mesa/main/matrix.c b/src/mesa/main/matrix.c index 39b4967a58..ebc3cbd59c 100644 --- a/src/mesa/main/matrix.c +++ b/src/mesa/main/matrix.c @@ -160,11 +160,21 @@ _mesa_MatrixMode( GLenum mode ) ctx->CurrentStack = &ctx->ProjectionMatrixStack; break; case GL_TEXTURE: + /* This error check is disabled because if we're called from + * glPopAttrib() when the active texture unit is >= MaxTextureCoordUnits + * we'll generate an unexpected error. + * From the GL_ARB_vertex_shader spec it sounds like we should instead + * do error checking in other places when we actually try to access + * texture matrices beyond MaxTextureCoordUnits. + */ +#if 0 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) { _mesa_error(ctx, GL_INVALID_OPERATION, "glMatrixMode(invalid tex unit %d)", ctx->Texture.CurrentUnit); return; } +#endif + ASSERT(ctx->Texture.CurrentUnit < Elements(ctx->TextureMatrixStack)); ctx->CurrentStack = &ctx->TextureMatrixStack[ctx->Texture.CurrentUnit]; break; case GL_COLOR: diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 26ec8d5595..46020eb210 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -1498,14 +1498,17 @@ struct gl_buffer_object { GLint RefCount; GLuint Name; - GLenum Usage; - GLenum Access; - GLvoid *Pointer; /**< Only valid while buffer is mapped */ - GLintptr Offset; /**< mapped offset */ - GLsizeiptr Length; /**< mapped length */ - GLsizeiptrARB Size; /**< Size of storage in bytes */ - GLubyte *Data; /**< Location of storage either in RAM or VRAM. */ - GLboolean Written; /**< Ever written to? (for debugging) */ + GLenum Usage; /**< GL_STREAM_DRAW_ARB, GL_STREAM_READ_ARB, etc. */ + GLsizeiptrARB Size; /**< Size of buffer storage in bytes */ + GLubyte *Data; /**< Location of storage either in RAM or VRAM. */ + /** Fields describing a mapped buffer */ + /*@{*/ + GLenum Access; /**< GL_READ_ONLY_ARB, GL_WRITE_ONLY_ARB, etc. */ + GLvoid *Pointer; /**< User-space address of mapping */ + GLintptr Offset; /**< Mapped offset */ + GLsizeiptr Length; /**< Mapped length */ + /*@}*/ + GLboolean Written; /**< Ever written to? (for debugging) */ }; diff --git a/src/mesa/main/varray.c b/src/mesa/main/varray.c index ff3128b8be..f04c137c6d 100644 --- a/src/mesa/main/varray.c +++ b/src/mesa/main/varray.c @@ -529,6 +529,7 @@ _mesa_VertexAttribPointerNV(GLuint index, GLint size, GLenum type, { GLboolean normalized = GL_FALSE; GLsizei elementSize; + GLenum format; GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END(ctx); @@ -552,6 +553,21 @@ _mesa_VertexAttribPointerNV(GLuint index, GLint size, GLenum type, return; } + if (size == GL_BGRA) { + if (type != GL_UNSIGNED_BYTE) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glVertexAttribPointerNV(GL_BGRA/type)"); + return; + } + + format = GL_BGRA; + size = 4; + normalized = GL_TRUE; + } + else { + format = GL_RGBA; + } + /* check for valid 'type' and compute StrideB right away */ switch (type) { case GL_UNSIGNED_BYTE: @@ -574,7 +590,7 @@ _mesa_VertexAttribPointerNV(GLuint index, GLint size, GLenum type, update_array(ctx, &ctx->Array.ArrayObj->VertexAttrib[index], _NEW_ARRAY_ATTRIB(index), - elementSize, size, type, GL_RGBA, stride, normalized, ptr); + elementSize, size, type, format, stride, normalized, ptr); if (ctx->Driver.VertexAttribPointer) ctx->Driver.VertexAttribPointer( ctx, index, size, type, stride, ptr ); @@ -621,9 +637,14 @@ _mesa_VertexAttribPointerARB(GLuint index, GLint size, GLenum type, "glVertexAttribPointerARB(GL_BGRA/type)"); return; } + if (normalized != GL_TRUE) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glVertexAttribPointerARB(GL_BGRA/normalized)"); + return; + } + format = GL_BGRA; size = 4; - normalized = GL_TRUE; } else { format = GL_RGBA; @@ -668,7 +689,7 @@ _mesa_VertexAttribPointerARB(GLuint index, GLint size, GLenum type, update_array(ctx, &ctx->Array.ArrayObj->VertexAttrib[index], _NEW_ARRAY_ATTRIB(index), - elementSize, size, type, GL_RGBA, stride, normalized, ptr); + elementSize, size, type, format, stride, normalized, ptr); if (ctx->Driver.VertexAttribPointer) ctx->Driver.VertexAttribPointer(ctx, index, size, type, stride, ptr); diff --git a/src/mesa/shader/arbprogparse.c b/src/mesa/shader/arbprogparse.c index a90ce95a63..7e166830fd 100644 --- a/src/mesa/shader/arbprogparse.c +++ b/src/mesa/shader/arbprogparse.c @@ -1022,7 +1022,10 @@ parse_teximage_num (GLcontext * ctx, const GLubyte ** inst, GLint i = parse_integer (inst, Program); if ((i < 0) || (i >= (int)ctx->Const.MaxTextureImageUnits)) { - program_error(ctx, Program->Position, "Invalid texture image index"); + char s[100]; + _mesa_snprintf(s, sizeof(s), "Invalid texture image index %d (%u is max)", + i, ctx->Const.MaxTextureImageUnits); + program_error(ctx, Program->Position, s); return 1; } diff --git a/src/mesa/shader/slang/slang_preprocess.c b/src/mesa/shader/slang/slang_preprocess.c index ff913ad883..e9a24cc009 100644 --- a/src/mesa/shader/slang/slang_preprocess.c +++ b/src/mesa/shader/slang/slang_preprocess.c @@ -1035,11 +1035,11 @@ preprocess_source (slang_string *output, const char *source, /* Parse optional macro parameters. */ while (prod[i++] != PARAM_END) { - if (state.cond.top->effective) { - pp_symbol *param; + pp_symbol *param; - id = (const char *) (&prod[i]); - idlen = _mesa_strlen (id); + id = (const char *) (&prod[i]); + idlen = _mesa_strlen (id); + if (state.cond.top->effective) { pp_annotate (output, "%s, ", id); param = pp_symbols_push (&symbol->parameters); if (param == NULL) @@ -1053,8 +1053,23 @@ preprocess_source (slang_string *output, const char *source, id = (const char *) (&prod[i]); idlen = _mesa_strlen (id); if (state.cond.top->effective) { + slang_string replacement; + expand_state es; + pp_annotate (output, ") %s", id); - slang_string_pushs (&symbol->replacement, id, idlen); + + slang_string_init(&replacement); + slang_string_pushs(&replacement, id, idlen); + + /* Expand macro replacement. */ + es.output = &symbol->replacement; + es.input = slang_string_cstr(&replacement); + es.state = &state; + if (!expand(&es, &state.symbols)) { + slang_string_free(&replacement); + goto error; + } + slang_string_free(&replacement); } i += idlen + 1; } @@ -1286,6 +1301,45 @@ error: /** + * Remove the continuation characters from the input string. + * This is the very first step in preprocessing and is effective + * even inside comment blocks. + * If there is a whitespace between a backslash and a newline, + * this is not considered as a line continuation. + * \return GL_TRUE for success, GL_FALSE otherwise. + */ +static GLboolean +_slang_preprocess_backslashes(slang_string *output, + const char *input) +{ + while (*input) { + if (input[0] == '\\') { + /* If a newline follows, eat the backslash and the newline. */ + if (input[1] == '\r') { + if (input[2] == '\n') { + input += 3; + } else { + input += 2; + } + } else if (input[1] == '\n') { + if (input[2] == '\r') { + input += 3; + } else { + input += 2; + } + } else { + /* Leave the backslash alone. */ + slang_string_pushc(output, *input++); + } + } else { + slang_string_pushc(output, *input++); + } + } + return GL_TRUE; +} + + +/** * Run preprocessor on source code. * \param extensions indicates which GL extensions are enabled * \param output the post-process results @@ -1304,6 +1358,7 @@ _slang_preprocess_directives(slang_string *output, { grammar pid, eid; GLboolean success; + slang_string without_backslashes; pid = grammar_load_from_text ((const byte *) (slang_pp_directives_syn)); if (pid == 0) { @@ -1316,9 +1371,36 @@ _slang_preprocess_directives(slang_string *output, grammar_destroy (pid); return GL_FALSE; } - success = preprocess_source (output, input, pid, eid, elog, extensions, pragmas); + + slang_string_init(&without_backslashes); + success = _slang_preprocess_backslashes(&without_backslashes, input); + + if (0) { + _mesa_printf("Pre-processed shader:\n"); + _mesa_printf("%s", slang_string_cstr(&without_backslashes)); + _mesa_printf("----------------------\n"); + } + + if (success) { + success = preprocess_source(output, + slang_string_cstr(&without_backslashes), + pid, + eid, + elog, + extensions, + pragmas); + } + + slang_string_free(&without_backslashes); grammar_destroy (eid); grammar_destroy (pid); + + if (0) { + _mesa_printf("Post-processed shader:\n"); + _mesa_printf("%s", slang_string_cstr(output)); + _mesa_printf("----------------------\n"); + } + return success; } diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c index fc1ff5be04..cb869c98a3 100644 --- a/src/mesa/state_tracker/st_atom_shader.c +++ b/src/mesa/state_tracker/st_atom_shader.c @@ -237,8 +237,8 @@ find_translated_vp(struct st_context *st, } if (emitBFC1) { xvp->output_to_slot[VERT_RESULT_BFC1] = numVpOuts++; - xvp->output_to_semantic_name[VERT_RESULT_BFC0] = TGSI_SEMANTIC_COLOR; - xvp->output_to_semantic_index[VERT_RESULT_BFC0] = 1; + xvp->output_to_semantic_name[VERT_RESULT_BFC1] = TGSI_SEMANTIC_COLOR; + xvp->output_to_semantic_index[VERT_RESULT_BFC1] = 1; } /* Unneeded vertex program outputs will go to this slot. diff --git a/src/mesa/state_tracker/st_cb_accum.c b/src/mesa/state_tracker/st_cb_accum.c index 7f793cf08d..95181578f6 100644 --- a/src/mesa/state_tracker/st_cb_accum.c +++ b/src/mesa/state_tracker/st_cb_accum.c @@ -48,10 +48,6 @@ #include "util/u_tile.h" -#define UNCLAMPED_FLOAT_TO_SHORT(us, f) \ - us = ( (short) ( CLAMP((f), -1.0, 1.0) * 32767.0F) ) - - /** * For hardware that supports deep color buffers, we could accelerate * most/all the accum operations with blending/texturing. @@ -59,74 +55,20 @@ */ -/** - * Wrapper for pipe_get_tile_rgba(). Do format/cpp override to make the - * tile util function think the surface is 16bit/channel, even if it's not. - * See also: st_renderbuffer_alloc_storage() - */ -static void -acc_get_tile_rgba(struct pipe_context *pipe, struct pipe_transfer *acc_pt, - uint x, uint y, uint w, uint h, float *p) -{ - const enum pipe_format f = acc_pt->format; - const struct pipe_format_block b = acc_pt->block; - - acc_pt->format = DEFAULT_ACCUM_PIPE_FORMAT; - acc_pt->block.size = 8; - acc_pt->block.width = 1; - acc_pt->block.height = 1; - - pipe_get_tile_rgba(acc_pt, x, y, w, h, p); - - acc_pt->format = f; - acc_pt->block = b; -} - - -/** - * Wrapper for pipe_put_tile_rgba(). Do format/cpp override to make the - * tile util function think the surface is 16bit/channel, even if it's not. - * See also: st_renderbuffer_alloc_storage() - */ -static void -acc_put_tile_rgba(struct pipe_context *pipe, struct pipe_transfer *acc_pt, - uint x, uint y, uint w, uint h, const float *p) -{ - enum pipe_format f = acc_pt->format; - const struct pipe_format_block b = acc_pt->block; - - acc_pt->format = DEFAULT_ACCUM_PIPE_FORMAT; - acc_pt->block.size = 8; - acc_pt->block.width = 1; - acc_pt->block.height = 1; - - pipe_put_tile_rgba(acc_pt, x, y, w, h, p); - - acc_pt->format = f; - acc_pt->block = b; -} - - - void st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { struct st_renderbuffer *acc_strb = st_renderbuffer(rb); - struct pipe_transfer *acc_pt; - struct pipe_screen *screen = ctx->st->pipe->screen; const GLint xpos = ctx->DrawBuffer->_Xmin; const GLint ypos = ctx->DrawBuffer->_Ymin; const GLint width = ctx->DrawBuffer->_Xmax - xpos; const GLint height = ctx->DrawBuffer->_Ymax - ypos; - GLubyte *map; - - acc_pt = st_cond_flush_get_tex_transfer(st_context(ctx), acc_strb->texture, - 0, 0, 0, - PIPE_TRANSFER_WRITE, xpos, ypos, - width, height); - map = screen->transfer_map(screen, acc_pt); + size_t stride = acc_strb->stride; + GLubyte *data = acc_strb->data; - /* note acc_strb->format might not equal acc_pt->format */ + if(!data) + return; + switch (acc_strb->format) { case PIPE_FORMAT_R16G16B16A16_SNORM: { @@ -136,7 +78,7 @@ st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) GLshort a = FLOAT_TO_SHORT(ctx->Accum.ClearColor[3]); int i, j; for (i = 0; i < height; i++) { - GLshort *dst = (GLshort *) (map + i * acc_pt->stride + xpos * 8); + GLshort *dst = (GLshort *) (data + (ypos + i) * stride + xpos * 8); for (j = 0; j < width; j++) { dst[0] = r; dst[1] = g; @@ -150,9 +92,6 @@ st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) default: _mesa_problem(ctx, "unexpected format in st_clear_accum_buffer()"); } - - screen->transfer_unmap(screen, acc_pt); - screen->tex_transfer_destroy(acc_pt); } @@ -162,27 +101,18 @@ accum_mad(GLcontext *ctx, GLfloat scale, GLfloat bias, GLint xpos, GLint ypos, GLint width, GLint height, struct st_renderbuffer *acc_strb) { - struct pipe_screen *screen = ctx->st->pipe->screen; - struct pipe_transfer *acc_pt; - GLubyte *map; - - acc_pt = st_cond_flush_get_tex_transfer(st_context(ctx), acc_strb->texture, - 0, 0, 0, - PIPE_TRANSFER_READ_WRITE, - xpos, ypos, - width, height); - map = screen->transfer_map(screen, acc_pt); - - /* note acc_strb->format might not equal acc_pt->format */ + size_t stride = acc_strb->stride; + GLubyte *data = acc_strb->data; + switch (acc_strb->format) { case PIPE_FORMAT_R16G16B16A16_SNORM: { int i, j; for (i = 0; i < height; i++) { - GLshort *acc = (GLshort *) (map + (ypos + i) * acc_pt->stride + xpos * 8); + GLshort *acc = (GLshort *) (data + (ypos + i) * stride + xpos * 8); for (j = 0; j < width * 4; j++) { - float val = SHORT_TO_FLOAT(acc[j]) * scale + bias; - acc[j] = FLOAT_TO_SHORT(val); + float val = SHORT_TO_FLOAT(*acc) * scale + bias; + *acc++ = FLOAT_TO_SHORT(val); } } } @@ -190,9 +120,6 @@ accum_mad(GLcontext *ctx, GLfloat scale, GLfloat bias, default: _mesa_problem(NULL, "unexpected format in st_clear_accum_buffer()"); } - - screen->transfer_unmap(screen, acc_pt); - screen->tex_transfer_destroy(acc_pt); } @@ -204,39 +131,39 @@ accum_accum(struct st_context *st, GLfloat value, { struct pipe_context *pipe = st->pipe; struct pipe_screen *screen = pipe->screen; - struct pipe_transfer *acc_trans, *color_trans; - GLfloat *colorBuf, *accBuf; - GLint i; - - acc_trans = st_cond_flush_get_tex_transfer(st, acc_strb->texture, 0, 0, 0, - PIPE_TRANSFER_READ, xpos, ypos, - width, height); + struct pipe_transfer *color_trans; + size_t stride = acc_strb->stride; + GLubyte *data = acc_strb->data; + GLfloat *buf; color_trans = st_cond_flush_get_tex_transfer(st, color_strb->texture, 0, 0, 0, PIPE_TRANSFER_READ, xpos, ypos, width, height); - colorBuf = (GLfloat *) _mesa_malloc(width * height * 4 * sizeof(GLfloat)); - accBuf = (GLfloat *) _mesa_malloc(width * height * 4 * sizeof(GLfloat)); + buf = (GLfloat *) _mesa_malloc(width * height * 4 * sizeof(GLfloat)); - pipe_get_tile_rgba(color_trans, 0, 0, width, height, colorBuf); - acc_get_tile_rgba(pipe, acc_trans, 0, 0, width, height, accBuf); + pipe_get_tile_rgba(color_trans, 0, 0, width, height, buf); - for (i = 0; i < 4 * width * height; i++) { - accBuf[i] = accBuf[i] + colorBuf[i] * value; + switch (acc_strb->format) { + case PIPE_FORMAT_R16G16B16A16_SNORM: + { + const GLfloat *color = buf; + int i, j; + for (i = 0; i < height; i++) { + GLshort *acc = (GLshort *) (data + (ypos + i) * stride + xpos * 8); + for (j = 0; j < width * 4; j++) { + float val = *color++ * value; + *acc++ += FLOAT_TO_SHORT(val); + } + } + } + break; + default: + _mesa_problem(NULL, "unexpected format in st_clear_accum_buffer()"); } - screen->tex_transfer_destroy(acc_trans); - acc_trans = st_no_flush_get_tex_transfer(st, acc_strb->texture, 0, 0, 0, - PIPE_TRANSFER_WRITE, xpos, ypos, - width, height); - - acc_put_tile_rgba(pipe, acc_trans, 0, 0, width, height, accBuf); - - _mesa_free(colorBuf); - _mesa_free(accBuf); - screen->tex_transfer_destroy(acc_trans); + _mesa_free(buf); screen->tex_transfer_destroy(color_trans); } @@ -249,13 +176,10 @@ accum_load(struct st_context *st, GLfloat value, { struct pipe_context *pipe = st->pipe; struct pipe_screen *screen = pipe->screen; - struct pipe_transfer *acc_trans, *color_trans; + struct pipe_transfer *color_trans; + size_t stride = acc_strb->stride; + GLubyte *data = acc_strb->data; GLfloat *buf; - GLint i; - - acc_trans = st_cond_flush_get_tex_transfer(st, acc_strb->texture, 0, 0, 0, - PIPE_TRANSFER_WRITE, xpos, ypos, - width, height); color_trans = st_cond_flush_get_tex_transfer(st, color_strb->texture, 0, 0, 0, @@ -266,14 +190,25 @@ accum_load(struct st_context *st, GLfloat value, pipe_get_tile_rgba(color_trans, 0, 0, width, height, buf); - for (i = 0; i < 4 * width * height; i++) { - buf[i] = buf[i] * value; + switch (acc_strb->format) { + case PIPE_FORMAT_R16G16B16A16_SNORM: + { + const GLfloat *color = buf; + int i, j; + for (i = 0; i < height; i++) { + GLshort *acc = (GLshort *) (data + (ypos + i) * stride + xpos * 8); + for (j = 0; j < width * 4; j++) { + float val = *color++ * value; + *acc++ = FLOAT_TO_SHORT(val); + } + } + } + break; + default: + _mesa_problem(NULL, "unexpected format in st_clear_accum_buffer()"); } - acc_put_tile_rgba(pipe, acc_trans, 0, 0, width, height, buf); - _mesa_free(buf); - screen->tex_transfer_destroy(acc_trans); screen->tex_transfer_destroy(color_trans); } @@ -287,48 +222,58 @@ accum_return(GLcontext *ctx, GLfloat value, struct pipe_context *pipe = ctx->st->pipe; struct pipe_screen *screen = pipe->screen; const GLubyte *colormask = ctx->Color.ColorMask; - struct pipe_transfer *acc_trans, *color_trans; - GLfloat *abuf, *cbuf = NULL; - GLint i, ch; - - abuf = (GLfloat *) _mesa_malloc(width * height * 4 * sizeof(GLfloat)); + enum pipe_transfer_usage usage; + struct pipe_transfer *color_trans; + size_t stride = acc_strb->stride; + const GLubyte *data = acc_strb->data; + GLfloat *buf; - acc_trans = st_cond_flush_get_tex_transfer(st_context(ctx), - acc_strb->texture, 0, 0, 0, - PIPE_TRANSFER_READ, xpos, ypos, - width, height); + buf = (GLfloat *) _mesa_malloc(width * height * 4 * sizeof(GLfloat)); + if (!colormask[0] || !colormask[1] || !colormask[2] || !colormask[3]) + usage = PIPE_TRANSFER_READ_WRITE; + else + usage = PIPE_TRANSFER_WRITE; + color_trans = st_cond_flush_get_tex_transfer(st_context(ctx), color_strb->texture, 0, 0, 0, - PIPE_TRANSFER_READ_WRITE, + usage, xpos, ypos, width, height); - acc_get_tile_rgba(pipe, acc_trans, 0, 0, width, height, abuf); - - if (!colormask[0] || !colormask[1] || !colormask[2] || !colormask[3]) { - cbuf = (GLfloat *) _mesa_malloc(width * height * 4 * sizeof(GLfloat)); - pipe_get_tile_rgba(color_trans, 0, 0, width, height, cbuf); - } + if (usage != PIPE_TRANSFER_WRITE) + pipe_get_tile_rgba(color_trans, 0, 0, width, height, buf); - for (i = 0; i < width * height; i++) { - for (ch = 0; ch < 4; ch++) { - if (colormask[ch]) { - GLfloat val = abuf[i * 4 + ch] * value; - abuf[i * 4 + ch] = CLAMP(val, 0.0f, 1.0f); - } - else { - abuf[i * 4 + ch] = cbuf[i * 4 + ch]; + switch (acc_strb->format) { + case PIPE_FORMAT_R16G16B16A16_SNORM: + { + GLfloat *color = buf; + int i, j, ch; + for (i = 0; i < height; i++) { + const GLshort *acc = (const GLshort *) (data + (ypos + i) * stride + xpos * 8); + for (j = 0; j < width; j++) { + for (ch = 0; ch < 4; ch++) { + if (colormask[ch]) { + GLfloat val = SHORT_TO_FLOAT(*acc * value); + *color = CLAMP(val, 0.0f, 1.0f); + } + else { + /* No change */ + } + ++acc; + ++color; + } + } } } + break; + default: + _mesa_problem(NULL, "unexpected format in st_clear_accum_buffer()"); } - pipe_put_tile_rgba(color_trans, 0, 0, width, height, abuf); + pipe_put_tile_rgba(color_trans, 0, 0, width, height, buf); - _mesa_free(abuf); - if (cbuf) - _mesa_free(cbuf); - screen->tex_transfer_destroy(acc_trans); + _mesa_free(buf); screen->tex_transfer_destroy(color_trans); } @@ -347,6 +292,9 @@ st_Accum(GLcontext *ctx, GLenum op, GLfloat value) const GLint width = ctx->DrawBuffer->_Xmax - xpos; const GLint height = ctx->DrawBuffer->_Ymax - ypos; + if(!acc_strb->data) + return; + /* make sure color bufs aren't cached */ st_flush( st, PIPE_FLUSH_RENDER_CACHE, NULL ); diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c index f140641d7e..7021d73208 100644 --- a/src/mesa/state_tracker/st_cb_bufferobjects.c +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c @@ -245,11 +245,10 @@ st_bufferobj_map_range(GLcontext *ctx, GLenum target, assert(offset < obj->Size); assert(offset + length <= obj->Size); - map = obj->Pointer = pipe_buffer_map_range(pipe->screen, st_obj->buffer, - offset, length, flags); - if (obj->Pointer) { - obj->Offset = 0; - obj->Length = obj->Size; + map = obj->Pointer = pipe_buffer_map_range(pipe->screen, st_obj->buffer, offset, length, flags); + if(obj->Pointer) { + obj->Offset = offset; + obj->Length = length; map += offset; } @@ -268,7 +267,6 @@ st_bufferobj_flush_mapped_range(GLcontext *ctx, GLenum target, /* Subrange is relative to mapped range */ assert(offset >= 0); assert(length >= 0); - assert(offset < obj->Length); assert(offset + length <= obj->Length); pipe_buffer_flush_mapped_range(pipe->screen, st_obj->buffer, diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 880e83108c..668acbccb8 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -103,20 +103,6 @@ st_destroy_clear(struct st_context *st) } -static GLboolean -is_depth_stencil_format(enum pipe_format pipeFormat) -{ - switch (pipeFormat) { - case PIPE_FORMAT_S8Z24_UNORM: - case PIPE_FORMAT_Z24S8_UNORM: - return GL_TRUE; - default: - return GL_FALSE; - } -} - - - /** * Draw a screen-aligned quadrilateral. * Coords are window coords with y=0=bottom. These will be passed @@ -331,7 +317,7 @@ static INLINE GLboolean check_clear_depth_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb) { const struct st_renderbuffer *strb = st_renderbuffer(rb); - const GLboolean isDS = is_depth_stencil_format(strb->surface->format); + const GLboolean isDS = pf_is_depth_and_stencil(strb->surface->format); if (ctx->Scissor.Enabled) return TRUE; @@ -351,7 +337,7 @@ static INLINE GLboolean check_clear_stencil_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb) { const struct st_renderbuffer *strb = st_renderbuffer(rb); - const GLboolean isDS = is_depth_stencil_format(strb->surface->format); + const GLboolean isDS = pf_is_depth_and_stencil(strb->surface->format); const GLuint stencilMax = (1 << rb->StencilBits) - 1; const GLboolean maskStencil = (ctx->Stencil.WriteMask[0] & stencilMax) != stencilMax; diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 89725cfe8d..2027b713ce 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -630,6 +630,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, 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; const GLboolean zoom = ctx->Pixel.ZoomX != 1.0 || ctx->Pixel.ZoomY != 1.0; GLint skipPixels; @@ -642,8 +643,14 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, y = ctx->DrawBuffer->Height - y - height; } + if(format != GL_DEPTH_STENCIL && + pf_get_component_bits( strb->format, PIPE_FORMAT_COMP_Z ) != 0) + usage = PIPE_TRANSFER_READ_WRITE; + else + usage = PIPE_TRANSFER_WRITE; + pt = st_cond_flush_get_tex_transfer(st_context(ctx), strb->texture, 0, 0, 0, - PIPE_TRANSFER_WRITE, x, y, + usage, x, y, width, height); stmap = screen->transfer_map(screen, pt); @@ -694,6 +701,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, case PIPE_FORMAT_S8_UNORM: { ubyte *dest = stmap + spanY * pt->stride + spanX; + assert(usage == PIPE_TRANSFER_WRITE); memcpy(dest, sValues, spanWidth); } break; @@ -701,6 +709,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, if (format == GL_DEPTH_STENCIL) { uint *dest = (uint *) (stmap + spanY * pt->stride + spanX*4); GLint k; + assert(usage == PIPE_TRANSFER_WRITE); for (k = 0; k < spanWidth; k++) { dest[k] = zValues[k] | (sValues[k] << 24); } @@ -708,6 +717,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, else { uint *dest = (uint *) (stmap + spanY * pt->stride + spanX*4); GLint k; + assert(usage == PIPE_TRANSFER_READ_WRITE); for (k = 0; k < spanWidth; k++) { dest[k] = (dest[k] & 0xffffff) | (sValues[k] << 24); } @@ -717,13 +727,15 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, if (format == GL_DEPTH_STENCIL) { uint *dest = (uint *) (stmap + spanY * pt->stride + spanX*4); GLint k; + assert(usage == PIPE_TRANSFER_WRITE); for (k = 0; k < spanWidth; k++) { - dest[k] = zValues[k] | (sValues[k] << 24); + dest[k] = (zValues[k] << 8) | (sValues[k] & 0xff); } } else { uint *dest = (uint *) (stmap + spanY * pt->stride + spanX*4); GLint k; + assert(usage == PIPE_TRANSFER_READ_WRITE); for (k = 0; k < spanWidth; k++) { dest[k] = (dest[k] & 0xffffff00) | (sValues[k] & 0xff); } @@ -757,7 +769,6 @@ st_DrawPixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, struct st_vertex_program *stvp; struct st_context *st = ctx->st; struct pipe_surface *ps; - GLuint bufferFormat; const GLfloat *color; if (format == GL_STENCIL_INDEX || @@ -785,8 +796,6 @@ st_DrawPixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, color = NULL; } - bufferFormat = ps->format; - /* draw with textured quad */ { struct pipe_texture *pt @@ -811,6 +820,7 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, { struct st_renderbuffer *rbDraw = st_renderbuffer(ctx->DrawBuffer->_StencilBuffer); struct pipe_screen *screen = ctx->st->pipe->screen; + enum pipe_transfer_usage usage; struct pipe_transfer *ptDraw; ubyte *drawMap; ubyte *buffer; @@ -827,9 +837,14 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, &ctx->DefaultPacking, buffer); + if(pf_get_component_bits( rbDraw->format, PIPE_FORMAT_COMP_Z ) != 0) + usage = PIPE_TRANSFER_READ_WRITE; + else + usage = PIPE_TRANSFER_WRITE; + ptDraw = st_cond_flush_get_tex_transfer(st_context(ctx), rbDraw->texture, 0, 0, 0, - PIPE_TRANSFER_WRITE, dstx, dsty, + usage, dstx, dsty, width, height); assert(ptDraw->block.width == 1); @@ -859,6 +874,7 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, { uint *dst4 = (uint *) dst; int j; + assert(usage == PIPE_TRANSFER_READ_WRITE); for (j = 0; j < width; j++) { *dst4 = (*dst4 & 0xffffff) | (src[j] << 24); dst4++; @@ -869,6 +885,7 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, { uint *dst4 = (uint *) dst; int j; + assert(usage == PIPE_TRANSFER_READ_WRITE); for (j = 0; j < width; j++) { *dst4 = (*dst4 & 0xffffff00) | (src[j] & 0xff); dst4++; @@ -876,6 +893,7 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, } break; case PIPE_FORMAT_S8_UNORM: + assert(usage == PIPE_TRANSFER_WRITE); memcpy(dst, src, width); break; default: diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index c249f3b357..ecdb988033 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -88,93 +88,92 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, { struct pipe_context *pipe = ctx->st->pipe; struct st_renderbuffer *strb = st_renderbuffer(rb); - struct pipe_texture template; - unsigned surface_usage; - - /* Free the old surface and texture - */ - pipe_surface_reference( &strb->surface, NULL ); - pipe_texture_reference( &strb->texture, NULL ); - - /* Setup new texture template. - */ - memset(&template, 0, sizeof(template)); - template.target = PIPE_TEXTURE_2D; - if (strb->format != PIPE_FORMAT_NONE) { - template.format = strb->format; - } - else { - template.format = st_choose_renderbuffer_format(pipe, internalFormat); - } - pf_get_block(template.format, &template.block); - template.width[0] = width; - template.height[0] = height; - template.depth[0] = 1; - template.last_level = 0; - template.nr_samples = rb->NumSamples; - if (pf_is_depth_stencil(template.format)) { - template.tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL; - } - else { - template.tex_usage = (PIPE_TEXTURE_USAGE_DISPLAY_TARGET | - PIPE_TEXTURE_USAGE_RENDER_TARGET); - } + enum pipe_format format; + if (strb->format != PIPE_FORMAT_NONE) + format = strb->format; + else + format = st_choose_renderbuffer_format(pipe, internalFormat); + /* init renderbuffer fields */ strb->Base.Width = width; strb->Base.Height = height; - init_renderbuffer_bits(strb, template.format); + init_renderbuffer_bits(strb, format); strb->defined = GL_FALSE; /* undefined contents now */ - /* 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 + if(strb->software) { + struct pipe_format_block block; + size_t size; + + _mesa_free(strb->data); + + assert(strb->format != PIPE_FORMAT_NONE); + pf_get_block(strb->format, &block); + + strb->stride = pf_get_stride(&block, width); + size = pf_get_2d_size(&block, strb->stride, height); + + strb->data = _mesa_malloc(size); + + return strb->data != NULL; + } + else { + struct pipe_texture template; + unsigned surface_usage; + + /* Free the old surface and texture + */ + pipe_surface_reference( &strb->surface, NULL ); + pipe_texture_reference( &strb->texture, NULL ); - strb->texture = pipe->screen->texture_create( pipe->screen, - &template ); + /* Setup new texture template. + */ + memset(&template, 0, sizeof(template)); + template.target = PIPE_TEXTURE_2D; + template.format = format; + pf_get_block(format, &template.block); + template.width[0] = width; + template.height[0] = height; + template.depth[0] = 1; + template.last_level = 0; + template.nr_samples = rb->NumSamples; + if (pf_is_depth_stencil(format)) { + template.tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL; + } + else { + template.tex_usage = (PIPE_TEXTURE_USAGE_DISPLAY_TARGET | + PIPE_TEXTURE_USAGE_RENDER_TARGET); + } - /* Special path for accum buffers. - * - * Try a different surface format. Since accum buffers are s/w - * only for now, the surface pixel format doesn't really matter, - * only that the buffer is large enough. - */ - if (!strb->texture && template.format == DEFAULT_ACCUM_PIPE_FORMAT) - { - /* Actually, just setting this usage value should be sufficient - * to tell the driver to go ahead and allocate the buffer, even - * if HW doesn't support the format. + /* Probably need dedicated flags for surface usage too: */ - template.tex_usage = 0; - surface_usage = (PIPE_BUFFER_USAGE_CPU_READ | + 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 = pipe->screen->texture_create( pipe->screen, &template ); - } + if (!strb->texture) + return FALSE; - if (!strb->texture) - return FALSE; + strb->surface = pipe->screen->get_tex_surface( pipe->screen, + strb->texture, + 0, 0, 0, + surface_usage ); - strb->surface = pipe->screen->get_tex_surface( pipe->screen, - strb->texture, - 0, 0, 0, - surface_usage ); + assert(strb->surface->texture); + assert(strb->surface->format); + assert(strb->surface->width == width); + assert(strb->surface->height == height); - assert(strb->surface->texture); - assert(strb->surface->format); - assert(strb->surface->width == width); - assert(strb->surface->height == height); - - return strb->surface != NULL; + return strb->surface != NULL; + } } @@ -188,6 +187,7 @@ st_renderbuffer_delete(struct gl_renderbuffer *rb) ASSERT(strb); pipe_surface_reference(&strb->surface, NULL); pipe_texture_reference(&strb->texture, NULL); + _mesa_free(strb->data); _mesa_free(strb); } @@ -244,7 +244,7 @@ st_new_renderbuffer(GLcontext *ctx, GLuint name) * renderbuffer). The window system code determines the format. */ struct gl_renderbuffer * -st_new_renderbuffer_fb(enum pipe_format format, int samples) +st_new_renderbuffer_fb(enum pipe_format format, int samples, boolean sw) { struct st_renderbuffer *strb; @@ -258,7 +258,8 @@ st_new_renderbuffer_fb(enum pipe_format format, int samples) strb->Base.ClassID = 0x4242; /* just a unique value */ strb->Base.NumSamples = samples; strb->format = format; - + strb->software = sw; + switch (format) { case PIPE_FORMAT_A8R8G8B8_UNORM: case PIPE_FORMAT_B8G8R8A8_UNORM: @@ -289,7 +290,7 @@ st_new_renderbuffer_fb(enum pipe_format format, int samples) strb->Base.InternalFormat = GL_STENCIL_INDEX8_EXT; strb->Base._BaseFormat = GL_STENCIL_INDEX; break; - case DEFAULT_ACCUM_PIPE_FORMAT: /*PIPE_FORMAT_R16G16B16A16_SNORM*/ + case PIPE_FORMAT_R16G16B16A16_SNORM: strb->Base.InternalFormat = GL_RGBA16; strb->Base._BaseFormat = GL_RGBA; break; @@ -536,7 +537,7 @@ check_create_front_buffer(GLcontext *ctx, struct gl_framebuffer *fb, samples = back->Base.NumSamples; /* create front renderbuffer */ - front = st_new_renderbuffer_fb(colorFormat, samples); + front = st_new_renderbuffer_fb(colorFormat, samples, FALSE); _mesa_add_renderbuffer(fb, frontIndex, front); /* alloc texture/surface for new front buffer */ diff --git a/src/mesa/state_tracker/st_cb_fbo.h b/src/mesa/state_tracker/st_cb_fbo.h index fd77d0a95b..bea6eb89c3 100644 --- a/src/mesa/state_tracker/st_cb_fbo.h +++ b/src/mesa/state_tracker/st_cb_fbo.h @@ -30,10 +30,6 @@ #define ST_CB_FBO_H -#define DEFAULT_ACCUM_PIPE_FORMAT PIPE_FORMAT_R16G16B16A16_SNORM - - - /** * Derived renderbuffer class. Just need to add a pointer to the * pipe surface. @@ -46,6 +42,13 @@ struct st_renderbuffer enum pipe_format format; /** preferred format, or PIPE_FORMAT_NONE */ GLboolean defined; /**< defined contents? */ + /** + * Used only when hardware accumulation buffers are not supported. + */ + boolean software; + size_t stride; + void *data; + struct st_texture_object *rtt; /**< GL render to texture's texture */ int rtt_level, rtt_face, rtt_slice; @@ -63,7 +66,7 @@ st_renderbuffer(struct gl_renderbuffer *rb) extern struct gl_renderbuffer * -st_new_renderbuffer_fb(enum pipe_format format, int samples); +st_new_renderbuffer_fb(enum pipe_format format, int samples, boolean sw); extern void st_init_fbo_functions(struct dd_function_table *functions); diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c index 7a4bbf5ce3..ccf1a0b563 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -112,7 +112,7 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, case PIPE_FORMAT_S8Z24_UNORM: if (format == GL_DEPTH_STENCIL) { const uint *src = (uint *) (stmap + srcY * pt->stride); - const GLfloat scale = 1.0 / (0xffffff); + const GLfloat scale = 1.0f / (0xffffff); GLint k; for (k = 0; k < width; k++) { sValues[k] = src[k] >> 24; @@ -130,7 +130,7 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, case PIPE_FORMAT_Z24S8_UNORM: if (format == GL_DEPTH_STENCIL) { const uint *src = (uint *) (stmap + srcY * pt->stride); - const GLfloat scale = 1.0 / (0xffffff); + const GLfloat scale = 1.0f / (0xffffff); GLint k; for (k = 0; k < width; k++) { sValues[k] = src[k] & 0xff; @@ -445,11 +445,16 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, } } else { - /* untested, but simple: */ + /* XXX: unreachable code -- should be before st_read_stencil_pixels */ 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); y += yStep; + /* Reverse into 24/8 */ + for (j = 0; j < width; j++) { + zshort[j] = (zshort[j] << 8) | (zshort[j] >> 24); + } dst += dstStride; } } @@ -472,7 +477,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, } } else { - /* untested, but simple: */ + /* 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); diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c index d507e3e58d..b243c249e3 100644 --- a/src/mesa/state_tracker/st_format.c +++ b/src/mesa/state_tracker/st_format.c @@ -392,7 +392,7 @@ default_depth_format(struct pipe_screen *screen, * or PIPE_TEXTURE_USAGE_SAMPLER */ enum pipe_format -st_choose_format(struct pipe_context *pipe, GLint internalFormat, +st_choose_format(struct pipe_context *pipe, GLenum internalFormat, enum pipe_texture_target target, unsigned tex_usage) { struct pipe_screen *screen = pipe->screen; @@ -594,9 +594,13 @@ st_choose_format(struct pipe_context *pipe, GLint internalFormat, static GLboolean -is_stencil_format(GLenum format) +is_depth_or_stencil_format(GLenum internalFormat) { - switch (format) { + 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: @@ -614,10 +618,10 @@ is_stencil_format(GLenum format) * Called by FBO code to choose a PIPE_FORMAT_ for drawing surfaces. */ enum pipe_format -st_choose_renderbuffer_format(struct pipe_context *pipe, GLint internalFormat) +st_choose_renderbuffer_format(struct pipe_context *pipe, GLenum internalFormat) { uint usage; - if (is_stencil_format(internalFormat)) + if (is_depth_or_stencil_format(internalFormat)) usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL; else usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; diff --git a/src/mesa/state_tracker/st_format.h b/src/mesa/state_tracker/st_format.h index 7bbbe2d570..9d9e02fe9b 100644 --- a/src/mesa/state_tracker/st_format.h +++ b/src/mesa/state_tracker/st_format.h @@ -64,11 +64,11 @@ st_mesa_format_to_pipe_format(GLuint mesaFormat); extern enum pipe_format -st_choose_format(struct pipe_context *pipe, GLint internalFormat, +st_choose_format(struct pipe_context *pipe, GLenum internalFormat, enum pipe_texture_target target, unsigned tex_usage); extern enum pipe_format -st_choose_renderbuffer_format(struct pipe_context *pipe, GLint internalFormat); +st_choose_renderbuffer_format(struct pipe_context *pipe, GLenum internalFormat); extern const struct gl_texture_format * diff --git a/src/mesa/state_tracker/st_framebuffer.c b/src/mesa/state_tracker/st_framebuffer.c index ef800291cc..7072cbe62c 100644 --- a/src/mesa/state_tracker/st_framebuffer.c +++ b/src/mesa/state_tracker/st_framebuffer.c @@ -60,7 +60,7 @@ st_create_framebuffer( const __GLcontextModes *visual, if (visual->doubleBufferMode) { struct gl_renderbuffer *rb - = st_new_renderbuffer_fb(colorFormat, samples); + = st_new_renderbuffer_fb(colorFormat, samples, FALSE); _mesa_add_renderbuffer(&stfb->Base, BUFFER_BACK_LEFT, rb); } else { @@ -69,14 +69,14 @@ st_create_framebuffer( const __GLcontextModes *visual, * See check_create_front_buffers(). */ struct gl_renderbuffer *rb - = st_new_renderbuffer_fb(colorFormat, samples); + = 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); + = 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); @@ -87,34 +87,35 @@ st_create_framebuffer( const __GLcontextModes *visual, if (visual->depthBits == 32) { /* 32-bit depth buffer */ struct gl_renderbuffer *depthRb - = st_new_renderbuffer_fb(depthFormat, samples); + = 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); + = 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); + = 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); + = 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(DEFAULT_ACCUM_PIPE_FORMAT, 0); /* XXX accum isn't multisampled right? */ + = st_new_renderbuffer_fb(PIPE_FORMAT_R16G16B16A16_SNORM, 0, TRUE); _mesa_add_renderbuffer(&stfb->Base, BUFFER_ACCUM, accumRb); } diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index 34926101ed..72ca852458 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -55,20 +55,6 @@ #define TGSI_DEBUG 0 -/** XXX we should use the version of this from u_memory.h but including - * that header causes symbol collisions. - */ -static INLINE void * -mem_dup(const void *src, uint size) -{ - void *dup = _mesa_malloc(size); - if (dup) - _mesa_memcpy(dup, src, size); - return dup; -} - - - /** * Translate a Mesa vertex shader into a TGSI shader. * \param outputMapping to map vertex program output registers (VERT_RESULT_x) @@ -84,7 +70,7 @@ st_translate_vertex_program(struct st_context *st, const ubyte *outputSemanticIndex) { struct pipe_context *pipe = st->pipe; - struct tgsi_token tokens[ST_MAX_SHADER_TOKENS]; + struct tgsi_token *tokens; GLuint defaultOutputMapping[VERT_RESULT_MAX]; struct pipe_shader_state vs; GLuint attr, i; @@ -102,6 +88,13 @@ st_translate_vertex_program(struct st_context *st, GLbitfield input_flags[MAX_PROGRAM_INPUTS]; GLbitfield output_flags[MAX_PROGRAM_OUTPUTS]; + tokens = (struct tgsi_token *)MALLOC(ST_MAX_SHADER_TOKENS * sizeof *tokens); + if(!tokens) { + /* FIXME: propagate error to the caller */ + assert(0); + return; + } + memset(&vs, 0, sizeof(vs)); memset(input_flags, 0, sizeof(input_flags)); memset(output_flags, 0, sizeof(output_flags)); @@ -297,9 +290,6 @@ st_translate_vertex_program(struct st_context *st, } } - assert(vs_output_semantic_name[0] == TGSI_SEMANTIC_POSITION); - - if (outputMapping) { /* find max output slot referenced to compute vs_num_outputs */ GLuint maxSlot = 0; @@ -347,7 +337,9 @@ st_translate_vertex_program(struct st_context *st, assert(num_tokens < ST_MAX_SHADER_TOKENS); vs.tokens = (struct tgsi_token *) - mem_dup(tokens, num_tokens * sizeof(tokens[0])); + _mesa_realloc(tokens, + ST_MAX_SHADER_TOKENS * sizeof *tokens, + num_tokens * sizeof *tokens); stvp->num_inputs = vs_num_inputs; stvp->state = vs; /* struct copy */ @@ -375,7 +367,7 @@ st_translate_fragment_program(struct st_context *st, const GLuint inputMapping[]) { struct pipe_context *pipe = st->pipe; - struct tgsi_token tokens[ST_MAX_SHADER_TOKENS]; + struct tgsi_token *tokens; GLuint outputMapping[FRAG_RESULT_MAX]; GLuint defaultInputMapping[FRAG_ATTRIB_MAX]; struct pipe_shader_state fs; @@ -395,6 +387,13 @@ st_translate_fragment_program(struct st_context *st, GLbitfield input_flags[MAX_PROGRAM_INPUTS]; GLbitfield output_flags[MAX_PROGRAM_OUTPUTS]; + tokens = (struct tgsi_token *)MALLOC(ST_MAX_SHADER_TOKENS * sizeof *tokens); + if(!tokens) { + /* FIXME: propagate error to the caller */ + assert(0); + return; + } + memset(&fs, 0, sizeof(fs)); memset(input_flags, 0, sizeof(input_flags)); memset(output_flags, 0, sizeof(output_flags)); @@ -536,7 +535,9 @@ st_translate_fragment_program(struct st_context *st, assert(num_tokens < ST_MAX_SHADER_TOKENS); fs.tokens = (struct tgsi_token *) - mem_dup(tokens, num_tokens * sizeof(tokens[0])); + _mesa_realloc(tokens, + ST_MAX_SHADER_TOKENS * sizeof *tokens, + num_tokens * sizeof *tokens); stfp->state = fs; /* struct copy */ stfp->driver_shader = pipe->create_fs_state(pipe, &fs); diff --git a/src/mesa/swrast/s_context.c b/src/mesa/swrast/s_context.c index f24f4fc59b..e7c2ace32c 100644 --- a/src/mesa/swrast/s_context.c +++ b/src/mesa/swrast/s_context.c @@ -289,6 +289,7 @@ _swrast_update_specular_vertex_add(GLcontext *ctx) #define _SWRAST_NEW_DERIVED (_SWRAST_NEW_RASTERMASK | \ + _NEW_PROGRAM_CONSTANTS | \ _NEW_TEXTURE | \ _NEW_HINT | \ _NEW_POLYGON ) diff --git a/src/mesa/vbo/vbo_exec_api.c b/src/mesa/vbo/vbo_exec_api.c index 6871ee5cab..b746a77bc1 100644 --- a/src/mesa/vbo/vbo_exec_api.c +++ b/src/mesa/vbo/vbo_exec_api.c @@ -51,6 +51,10 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. #endif +/** ID/name for immediate-mode VBO */ +#define IMM_BUFFER_NAME 0xaabbccdd + + static void reset_attrfv( struct vbo_exec_context *exec ); @@ -665,7 +669,7 @@ void vbo_use_buffer_objects(GLcontext *ctx) /* Any buffer name but 0 can be used here since this bufferobj won't * go into the bufferobj hashtable. */ - GLuint bufName = 0xaabbccdd; + GLuint bufName = IMM_BUFFER_NAME; GLenum target = GL_ARRAY_BUFFER_ARB; GLenum usage = GL_STREAM_DRAW_ARB; GLsizei size = VBO_VERT_BUFFER_SIZE; @@ -727,19 +731,33 @@ void vbo_exec_vtx_init( struct vbo_exec_context *exec ) void vbo_exec_vtx_destroy( struct vbo_exec_context *exec ) { - if (exec->vtx.bufferobj->Name) { - /* using a real VBO for vertex data */ - GLcontext *ctx = exec->ctx; - _mesa_reference_buffer_object(ctx, &exec->vtx.bufferobj, NULL); - } - else { - /* just using malloc'd space for vertex data */ - if (exec->vtx.buffer_map) { + /* using a real VBO for vertex data */ + GLcontext *ctx = exec->ctx; + unsigned i; + + /* True VBOs should already be unmapped + */ + if (exec->vtx.buffer_map) { + ASSERT(exec->vtx.bufferobj->Name == 0 || + exec->vtx.bufferobj->Name == IMM_BUFFER_NAME); + if (exec->vtx.bufferobj->Name == 0) { ALIGN_FREE(exec->vtx.buffer_map); exec->vtx.buffer_map = NULL; exec->vtx.buffer_ptr = NULL; } } + + /* Drop any outstanding reference to the vertex buffer + */ + for (i = 0; i < Elements(exec->vtx.arrays); i++) { + _mesa_reference_buffer_object(ctx, + &exec->vtx.arrays[i].BufferObj, + NULL); + } + + /* Free the vertex buffer: + */ + _mesa_reference_buffer_object(ctx, &exec->vtx.bufferobj, NULL); } void vbo_exec_BeginVertices( GLcontext *ctx ) diff --git a/src/mesa/vbo/vbo_exec_array.c b/src/mesa/vbo/vbo_exec_array.c index 4109fbbb3c..f4b9b2f744 100644 --- a/src/mesa/vbo/vbo_exec_array.c +++ b/src/mesa/vbo/vbo_exec_array.c @@ -510,6 +510,63 @@ vbo_exec_DrawArrays(GLenum mode, GLint start, GLsizei count) } +/** + * Map GL_ELEMENT_ARRAY_BUFFER and print contents. + */ +static void +dump_element_buffer(GLcontext *ctx, GLenum type) +{ + const GLvoid *map = ctx->Driver.MapBuffer(ctx, + GL_ELEMENT_ARRAY_BUFFER_ARB, + GL_READ_ONLY, + ctx->Array.ElementArrayBufferObj); + switch (type) { + case GL_UNSIGNED_BYTE: + { + const GLubyte *us = (const GLubyte *) map; + GLuint i; + for (i = 0; i < ctx->Array.ElementArrayBufferObj->Size; i++) { + _mesa_printf("%02x ", us[i]); + if (i % 32 == 31) + _mesa_printf("\n"); + } + _mesa_printf("\n"); + } + break; + case GL_UNSIGNED_SHORT: + { + const GLushort *us = (const GLushort *) map; + GLuint i; + for (i = 0; i < ctx->Array.ElementArrayBufferObj->Size / 2; i++) { + _mesa_printf("%04x ", us[i]); + if (i % 16 == 15) + _mesa_printf("\n"); + } + _mesa_printf("\n"); + } + break; + case GL_UNSIGNED_INT: + { + const GLuint *us = (const GLuint *) map; + GLuint i; + for (i = 0; i < ctx->Array.ElementArrayBufferObj->Size / 4; i++) { + _mesa_printf("%08x ", us[i]); + if (i % 8 == 7) + _mesa_printf("\n"); + } + _mesa_printf("\n"); + } + break; + default: + ; + } + + ctx->Driver.UnmapBuffer(ctx, + GL_ELEMENT_ARRAY_BUFFER_ARB, + ctx->Array.ElementArrayBufferObj); +} + + static void GLAPIENTRY vbo_exec_DrawRangeElements(GLenum mode, GLuint start, GLuint end, @@ -528,13 +585,27 @@ vbo_exec_DrawRangeElements(GLenum mode, if (end >= ctx->Array.ArrayObj->_MaxElement) { /* the max element is out of bounds of one or more enabled arrays */ _mesa_warning(ctx, "glDraw[Range]Elements(start %u, end %u, count %d, " - "type 0x%x) index=%u is out of bounds (max=%u)", - start, end, count, type, end, - ctx->Array.ArrayObj->_MaxElement - 1); + "type 0x%x, indices=%p)\n" + "\tindex=%u is out of bounds (max=%u) " + "Element Buffer %u (size %d)", + start, end, count, type, indices, end, + ctx->Array.ArrayObj->_MaxElement - 1, + ctx->Array.ElementArrayBufferObj->Name, + ctx->Array.ElementArrayBufferObj->Size); + + if (0) + dump_element_buffer(ctx, type); + if (0) _mesa_print_arrays(ctx); return; } + else if (0) { + _mesa_printf("glDraw[Range]Elements" + "(start %u, end %u, type 0x%x, count %d) ElemBuf %u\n", + start, end, type, count, + ctx->Array.ElementArrayBufferObj->Name); + } #if 0 check_draw_elements_data(ctx, count, type, indices); |