From a4d952358d8fd0f9d135c91c37969acdcf394f0a Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Mon, 6 Jul 2009 21:33:56 -0400 Subject: gallium: more fog extraction fixes fix the cases when fog coord/front face/point coord are used in the same shader. --- src/mesa/state_tracker/st_atom_shader.c | 21 +++++++------------- src/mesa/state_tracker/st_mesa_to_tgsi.c | 9 ++++++++- src/mesa/state_tracker/st_program.c | 34 ++++++++++++++++++++++---------- 3 files changed, 39 insertions(+), 25 deletions(-) (limited to 'src/mesa/state_tracker') diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c index c02ccc35283..299aa762c20 100644 --- a/src/mesa/state_tracker/st_atom_shader.c +++ b/src/mesa/state_tracker/st_atom_shader.c @@ -137,22 +137,15 @@ find_translated_vp(struct st_context *st, for (inAttr = 0; inAttr < FRAG_ATTRIB_MAX; inAttr++) { if (fragInputsRead & (1 << inAttr)) { + stfp->input_to_slot[inAttr] = numIn; + numIn++; if ((fragInputsRead & FRAG_BIT_FOGC)) { - if (stfp->Base.UsesPointCoord) { - stfp->input_to_slot[inAttr] = numIn; - numIn++; + /* leave placeholders for the + * extra registers we extract from fog */ + if (stfp->Base.UsesFrontFacing || + stfp->Base.UsesPointCoord) { + numIn += 2; } - if (stfp->Base.UsesFrontFacing) { - stfp->input_to_slot[inAttr] = numIn; - numIn++; - } - if (stfp->Base.UsesFogFragCoord) { - stfp->input_to_slot[inAttr] = numIn; - numIn++; - } - } else { - stfp->input_to_slot[inAttr] = numIn; - numIn++; } } else { diff --git a/src/mesa/state_tracker/st_mesa_to_tgsi.c b/src/mesa/state_tracker/st_mesa_to_tgsi.c index 3140ebe04ad..8aef3fc6dcf 100644 --- a/src/mesa/state_tracker/st_mesa_to_tgsi.c +++ b/src/mesa/state_tracker/st_mesa_to_tgsi.c @@ -122,8 +122,15 @@ map_register_file_index( SWIZZLE_X, SWIZZLE_X, SWIZZLE_X); + /* register after fog */ + return inputMapping[index] + 1; } else { - /* fixme: point coord */ + *swizzle = MAKE_SWIZZLE4(SWIZZLE_Z, + SWIZZLE_W, + SWIZZLE_Z, + SWIZZLE_W); + /* register after frontface */ + return inputMapping[index] + 2; } } /* inputs are mapped according to the user-defined map */ diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index 9a346fbde0c..18d10468317 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -433,20 +433,34 @@ st_translate_fragment_program(struct st_context *st, stfp->input_semantic_index[slot] = 1; interpMode[slot] = TGSI_INTERPOLATE_LINEAR; break; - case FRAG_ATTRIB_FOGC: - if (stfp->Base.UsesPointCoord) { - stfp->input_semantic_name[slot] = TGSI_SEMANTIC_GENERIC; - stfp->input_semantic_index[slot] = num_generic++; - interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE; - } else if (stfp->Base.UsesFrontFacing) { - stfp->input_semantic_name[slot] = TGSI_SEMANTIC_FACE; - stfp->input_semantic_index[slot] = 0; - interpMode[slot] = TGSI_INTERPOLATE_CONSTANT; - } else { + case FRAG_ATTRIB_FOGC: { + int extra_decls = 0; + if (stfp->Base.UsesFogFragCoord) { stfp->input_semantic_name[slot] = TGSI_SEMANTIC_FOG; stfp->input_semantic_index[slot] = 0; interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE; + input_flags[slot] = stfp->Base.Base.InputFlags[attr]; + ++extra_decls; } + if (stfp->Base.UsesFrontFacing) { + GLint idx = slot + extra_decls; + stfp->input_semantic_name[idx] = TGSI_SEMANTIC_FACE; + stfp->input_semantic_index[idx] = 0; + interpMode[idx] = TGSI_INTERPOLATE_CONSTANT; + input_flags[idx] = stfp->Base.Base.InputFlags[attr]; + ++extra_decls; + } + if (stfp->Base.UsesPointCoord) { + GLint idx = slot + extra_decls; + stfp->input_semantic_name[idx] = TGSI_SEMANTIC_GENERIC; + stfp->input_semantic_index[idx] = num_generic++; + interpMode[idx] = TGSI_INTERPOLATE_PERSPECTIVE; + input_flags[idx] = stfp->Base.Base.InputFlags[attr]; + ++extra_decls; + } + fs_num_inputs += extra_decls - 1; + continue; + } break; case FRAG_ATTRIB_TEX0: case FRAG_ATTRIB_TEX1: -- cgit v1.2.3 From 96601ec8e0e35d540c1819a48df7f08ec5874ab7 Mon Sep 17 00:00:00 2001 From: Michel Dänzer Date: Tue, 7 Jul 2009 12:17:04 +0200 Subject: gallium: Only set FRONT_STATUS_COPY_OF_BACK if there is a back buffer. Fixes potential crash when SwapBuffers is called but there's no back buffer. --- src/mesa/state_tracker/st_framebuffer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/mesa/state_tracker') diff --git a/src/mesa/state_tracker/st_framebuffer.c b/src/mesa/state_tracker/st_framebuffer.c index 33a90ea7db6..fe99fc08926 100644 --- a/src/mesa/state_tracker/st_framebuffer.c +++ b/src/mesa/state_tracker/st_framebuffer.c @@ -280,7 +280,8 @@ st_notify_swapbuffers(struct st_framebuffer *stfb) PIPE_FLUSH_SWAPBUFFERS | PIPE_FLUSH_FRAME, NULL ); - ctx->st->frontbuffer_status = FRONT_STATUS_COPY_OF_BACK; + if (st_renderbuffer(stfb->Base.Attachment[BUFFER_BACK_LEFT].Renderbuffer)) + ctx->st->frontbuffer_status = FRONT_STATUS_COPY_OF_BACK; } } -- cgit v1.2.3 From 71633abafc935c25da9731bab48c228ceb9b4097 Mon Sep 17 00:00:00 2001 From: Michel Dänzer Date: Tue, 7 Jul 2009 14:49:52 +0200 Subject: gallium: Fixes for clobbering stencil values in combined depth/stencil textures. Also fix one case where a 32 bit depth value was incorrectly converted to a combined depth/stencil value. --- src/gallium/auxiliary/util/u_tile.c | 28 ++++++++++++++++++++++++- src/mesa/state_tracker/st_cb_drawpixels.c | 12 ++++++++--- src/mesa/state_tracker/st_cb_texture.c | 35 ++++++++++++++++++++++++------- 3 files changed, 64 insertions(+), 11 deletions(-) (limited to 'src/mesa/state_tracker') diff --git a/src/gallium/auxiliary/util/u_tile.c b/src/gallium/auxiliary/util/u_tile.c index 9747a55cbfa..a0c8ed88f74 100644 --- a/src/gallium/auxiliary/util/u_tile.c +++ b/src/gallium/auxiliary/util/u_tile.c @@ -1202,6 +1202,19 @@ pipe_put_tile_z(struct pipe_transfer *pt, } break; case PIPE_FORMAT_S8Z24_UNORM: + { + uint *pDest = (uint *) (map + y * pt->stride + x*4); + assert(pt->usage == PIPE_TRANSFER_READ_WRITE); + for (i = 0; i < h; i++) { + for (j = 0; j < w; j++) { + /* convert 32-bit Z to 24-bit Z, preserve stencil */ + pDest[j] = (pDest[j] & 0xff000000) | ptrc[j] >> 8; + } + pDest += pt->stride/4; + ptrc += srcStride; + } + } + break; case PIPE_FORMAT_X8Z24_UNORM: { uint *pDest = (uint *) (map + y * pt->stride + x*4); @@ -1216,13 +1229,26 @@ pipe_put_tile_z(struct pipe_transfer *pt, } break; case PIPE_FORMAT_Z24S8_UNORM: + { + uint *pDest = (uint *) (map + y * pt->stride + x*4); + assert(pt->usage == PIPE_TRANSFER_READ_WRITE); + for (i = 0; i < h; i++) { + for (j = 0; j < w; j++) { + /* convert 32-bit Z to 24-bit Z, preserve stencil */ + pDest[j] = (pDest[j] & 0xff) | (ptrc[j] & 0xffffff00); + } + pDest += pt->stride/4; + ptrc += srcStride; + } + } + break; case PIPE_FORMAT_Z24X8_UNORM: { uint *pDest = (uint *) (map + y * pt->stride + x*4); for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { /* convert 32-bit Z to 24-bit Z (0 stencil) */ - pDest[j] = ptrc[j] << 8; + pDest[j] = ptrc[j] & 0xffffff00; } pDest += pt->stride/4; ptrc += srcStride; diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 2027b713ce0..8b5094a04f3 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -1037,10 +1037,16 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, st_cond_flush_get_tex_transfer(st, rbRead->texture, 0, 0, 0, PIPE_TRANSFER_READ, srcx, srcy, width, height); + struct pipe_transfer *ptTex; + enum pipe_transfer_usage transfer_usage; - struct pipe_transfer *ptTex = - st_cond_flush_get_tex_transfer(st, pt, 0, 0, 0, PIPE_TRANSFER_WRITE, - 0, 0, width, height); + if (type == GL_DEPTH && pf_is_depth_and_stencil(pt->format)) + transfer_usage = PIPE_TRANSFER_READ_WRITE; + else + transfer_usage = PIPE_TRANSFER_WRITE; + + ptTex = st_cond_flush_get_tex_transfer(st, pt, 0, 0, 0, transfer_usage, + 0, 0, width, height); if (type == GL_COLOR) { /* alternate path using get/put_tile() */ diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 0a72784ce06..909189f9d39 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -529,6 +529,7 @@ st_TexImage(GLcontext * ctx, GLint texelBytes, sizeInBytes; GLuint dstRowStride; struct gl_pixelstore_attrib unpackNB; + enum pipe_transfer_usage transfer_usage; DBG("%s target %s level %d %dx%dx%d border %d\n", __FUNCTION__, _mesa_lookup_enum_by_nr(target), level, width, height, depth, border); @@ -680,8 +681,14 @@ st_TexImage(GLcontext * ctx, } if (stImage->pt) { + if (format == GL_DEPTH_COMPONENT && + pf_is_depth_and_stencil(stImage->pt->format)) + transfer_usage = PIPE_TRANSFER_READ_WRITE; + else + transfer_usage = PIPE_TRANSFER_WRITE; + texImage->Data = st_texture_image_map(ctx->st, stImage, 0, - PIPE_TRANSFER_WRITE, 0, 0, + transfer_usage, 0, 0, stImage->base.Width, stImage->base.Height); if(stImage->transfer) @@ -742,7 +749,7 @@ st_TexImage(GLcontext * ctx, st_texture_image_unmap(ctx->st, stImage); /* map next slice of 3D texture */ texImage->Data = st_texture_image_map(ctx->st, stImage, i + 1, - PIPE_TRANSFER_WRITE, 0, 0, + transfer_usage, 0, 0, stImage->base.Width, stImage->base.Height); src += srcImageStride; @@ -1041,6 +1048,7 @@ st_TexSubimage(GLcontext *ctx, GLint dims, GLenum target, GLint level, _mesa_image_image_stride(packing, width, height, format, type); GLint i; const GLubyte *src; + enum pipe_transfer_usage transfer_usage; DBG("%s target %s level %d offset %d,%d %dx%d\n", __FUNCTION__, _mesa_lookup_enum_by_nr(target), @@ -1072,10 +1080,16 @@ st_TexSubimage(GLcontext *ctx, GLint dims, GLenum target, GLint level, * from uploading the buffer under us. */ if (stImage->pt) { + if (format == GL_DEPTH_COMPONENT && + pf_is_depth_and_stencil(stImage->pt->format)) + transfer_usage = PIPE_TRANSFER_READ_WRITE; + else + transfer_usage = PIPE_TRANSFER_WRITE; + st_teximage_flush_before_map(ctx->st, stImage->pt, 0, level, - PIPE_TRANSFER_WRITE); + transfer_usage); texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset, - PIPE_TRANSFER_WRITE, + transfer_usage, xoffset, yoffset, width, height); } @@ -1106,7 +1120,7 @@ st_TexSubimage(GLcontext *ctx, GLint dims, GLenum target, GLint level, /* map next slice of 3D texture */ texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset + i + 1, - PIPE_TRANSFER_WRITE, + transfer_usage, xoffset, yoffset, width, height); src += srcImageStride; @@ -1274,6 +1288,7 @@ fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level, struct pipe_screen *screen = pipe->screen; struct pipe_transfer *src_trans; GLvoid *texDest; + enum pipe_transfer_usage transfer_usage; assert(width <= MAX_WIDTH); @@ -1288,10 +1303,16 @@ fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level, srcX, srcY, width, height); + if (baseFormat == GL_DEPTH_COMPONENT && + pf_is_depth_and_stencil(stImage->pt->format)) + transfer_usage = PIPE_TRANSFER_READ_WRITE; + else + transfer_usage = PIPE_TRANSFER_WRITE; + st_teximage_flush_before_map(ctx->st, stImage->pt, 0, 0, - PIPE_TRANSFER_WRITE); + transfer_usage); - texDest = st_texture_image_map(ctx->st, stImage, 0, PIPE_TRANSFER_WRITE, + texDest = st_texture_image_map(ctx->st, stImage, 0, transfer_usage, destX, destY, width, height); if (baseFormat == GL_DEPTH_COMPONENT || -- cgit v1.2.3