From e1a92175542c6645c23cc78f2a4fcd36dd0235e6 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 31 Dec 2008 00:02:43 -0800 Subject: intel: Add support for glBitmap as metaops using GL calls. This lets us avoid software fallbacks when clients forget to turn some state off (engine demo) or just do crazy things to test conformance (OGLC). This should probably be brought into mesa generic code so other drivers can make use of it. Bug #19016. --- src/mesa/drivers/dri/intel/intel_context.h | 10 ++ src/mesa/drivers/dri/intel/intel_pixel.c | 133 ++++++++++++++++ src/mesa/drivers/dri/intel/intel_pixel.h | 8 + src/mesa/drivers/dri/intel/intel_pixel_bitmap.c | 199 ++++++++++++++++++++++++ 4 files changed, 350 insertions(+) (limited to 'src/mesa') diff --git a/src/mesa/drivers/dri/intel/intel_context.h b/src/mesa/drivers/dri/intel/intel_context.h index ac08117bb4..4100677750 100644 --- a/src/mesa/drivers/dri/intel/intel_context.h +++ b/src/mesa/drivers/dri/intel/intel_context.h @@ -157,6 +157,16 @@ struct intel_context void (*debug_batch)(struct intel_context *intel); } vtbl; + struct { + struct gl_fragment_program *bitmap_fp; + struct gl_vertex_program *passthrough_vp; + + struct gl_fragment_program *saved_fp; + GLboolean saved_fp_enable; + struct gl_vertex_program *saved_vp; + GLboolean saved_vp_enable; + } meta; + GLint refcount; GLuint Fallback; GLuint NewGLState; diff --git a/src/mesa/drivers/dri/intel/intel_pixel.c b/src/mesa/drivers/dri/intel/intel_pixel.c index 5702ad9bb5..91027d37e7 100644 --- a/src/mesa/drivers/dri/intel/intel_pixel.c +++ b/src/mesa/drivers/dri/intel/intel_pixel.c @@ -27,7 +27,11 @@ #include "main/enums.h" #include "main/state.h" +#include "main/context.h" +#include "main/enable.h" #include "swrast/swrast.h" +#include "shader/arbprogram.h" +#include "shader/program.h" #include "intel_context.h" #include "intel_pixel.h" @@ -167,6 +171,125 @@ intel_check_blit_format(struct intel_region * region, return GL_FALSE; } +/** + * Set up a vertex program to pass through the position and first texcoord + * for pixel path. + */ +void +intel_meta_set_passthrough_vertex_program(struct intel_context *intel) +{ + GLcontext *ctx = &intel->ctx; + static const char *vp = + "!!ARBvp1.0\n" + "TEMP vertexClip;\n" + "DP4 vertexClip.x, state.matrix.mvp.row[0], vertex.position;\n" + "DP4 vertexClip.y, state.matrix.mvp.row[1], vertex.position;\n" + "DP4 vertexClip.z, state.matrix.mvp.row[2], vertex.position;\n" + "DP4 vertexClip.w, state.matrix.mvp.row[3], vertex.position;\n" + "MOV result.position, vertexClip;\n" + "MOV result.texcoord[0], vertex.texcoord[0];\n" + "MOV result.color, vertex.color;\n" + "END\n"; + + assert(intel->meta.saved_vp == NULL); + + _mesa_reference_vertprog(ctx, &intel->meta.saved_vp, + ctx->VertexProgram.Current); + if (intel->meta.passthrough_vp == NULL) { + GLuint prog_name; + _mesa_GenPrograms(1, &prog_name); + _mesa_BindProgram(GL_VERTEX_PROGRAM_ARB, prog_name); + _mesa_ProgramStringARB(GL_VERTEX_PROGRAM_ARB, + GL_PROGRAM_FORMAT_ASCII_ARB, + strlen(vp), (const GLubyte *)vp); + _mesa_reference_vertprog(ctx, &intel->meta.passthrough_vp, + ctx->VertexProgram.Current); + _mesa_DeletePrograms(1, &prog_name); + } + + FLUSH_VERTICES(ctx, _NEW_PROGRAM); + _mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current, + intel->meta.passthrough_vp); + ctx->Driver.BindProgram(ctx, GL_VERTEX_PROGRAM_ARB, + &intel->meta.passthrough_vp->Base); + + intel->meta.saved_vp_enable = ctx->VertexProgram.Enabled; + _mesa_Enable(GL_VERTEX_PROGRAM_ARB); +} + +/** + * Restores the previous vertex program after + * intel_meta_set_passthrough_vertex_program() + */ +void +intel_meta_restore_vertex_program(struct intel_context *intel) +{ + GLcontext *ctx = &intel->ctx; + + FLUSH_VERTICES(ctx, _NEW_PROGRAM); + _mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current, + intel->meta.saved_vp); + _mesa_reference_vertprog(ctx, &intel->meta.saved_vp, NULL); + ctx->Driver.BindProgram(ctx, GL_VERTEX_PROGRAM_ARB, + &ctx->VertexProgram.Current->Base); + + if (!intel->meta.saved_vp_enable) + _mesa_Disable(GL_VERTEX_PROGRAM_ARB); +} + +/** + * Binds the given program string to GL_FRAGMENT_PROGRAM_ARB, caching the + * program object. + */ +void +intel_meta_set_fragment_program(struct intel_context *intel, + struct gl_fragment_program **prog, + const char *prog_string) +{ + GLcontext *ctx = &intel->ctx; + assert(intel->meta.saved_fp == NULL); + + _mesa_reference_fragprog(ctx, &intel->meta.saved_fp, + ctx->FragmentProgram.Current); + if (*prog == NULL) { + GLuint prog_name; + _mesa_GenPrograms(1, &prog_name); + _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB, prog_name); + _mesa_ProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, + GL_PROGRAM_FORMAT_ASCII_ARB, + strlen(prog_string), (const GLubyte *)prog_string); + _mesa_reference_fragprog(ctx, prog, ctx->FragmentProgram.Current); + /* Note that DeletePrograms unbinds the program on us */ + _mesa_DeletePrograms(1, &prog_name); + } + + FLUSH_VERTICES(ctx, _NEW_PROGRAM); + _mesa_reference_fragprog(ctx, &ctx->FragmentProgram.Current, *prog); + ctx->Driver.BindProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, &((*prog)->Base)); + + intel->meta.saved_fp_enable = ctx->FragmentProgram.Enabled; + _mesa_Enable(GL_FRAGMENT_PROGRAM_ARB); +} + +/** + * Restores the previous fragment program after + * intel_meta_set_fragment_program() + */ +void +intel_meta_restore_fragment_program(struct intel_context *intel) +{ + GLcontext *ctx = &intel->ctx; + + FLUSH_VERTICES(ctx, _NEW_PROGRAM); + _mesa_reference_fragprog(ctx, &ctx->FragmentProgram.Current, + intel->meta.saved_fp); + _mesa_reference_fragprog(ctx, &intel->meta.saved_fp, NULL); + ctx->Driver.BindProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, + &ctx->FragmentProgram.Current->Base); + + if (!intel->meta.saved_fp_enable) + _mesa_Disable(GL_FRAGMENT_PROGRAM_ARB); +} void intelInitPixelFuncs(struct dd_function_table *functions) @@ -181,3 +304,13 @@ intelInitPixelFuncs(struct dd_function_table *functions) #endif } } + +void +intel_free_pixel_state(struct intel_context *intel) +{ + GLcontext *ctx = &intel->ctx; + + _mesa_reference_vertprog(ctx, &intel->meta.passthrough_vp, NULL); + _mesa_reference_fragprog(ctx, &intel->meta.bitmap_fp, NULL); +} + diff --git a/src/mesa/drivers/dri/intel/intel_pixel.h b/src/mesa/drivers/dri/intel/intel_pixel.h index 6fa6effe83..9556efc71c 100644 --- a/src/mesa/drivers/dri/intel/intel_pixel.h +++ b/src/mesa/drivers/dri/intel/intel_pixel.h @@ -32,6 +32,14 @@ void intelInitPixelFuncs(struct dd_function_table *functions); +void intel_meta_set_passthrough_vertex_program(struct intel_context *intel); +void intel_meta_restore_vertex_program(struct intel_context *intel); +void intel_meta_set_fragment_program(struct intel_context *intel, + struct gl_fragment_program **prog, + const char *prog_string); +void intel_meta_restore_fragment_program(struct intel_context *intel); +void intel_free_pixel_state(struct intel_context *intel); + GLboolean intel_check_blit_fragment_ops(GLcontext * ctx, GLboolean src_alpha_is_one); diff --git a/src/mesa/drivers/dri/intel/intel_pixel_bitmap.c b/src/mesa/drivers/dri/intel/intel_pixel_bitmap.c index 5e0e0d29ca..88e181a51f 100644 --- a/src/mesa/drivers/dri/intel/intel_pixel_bitmap.c +++ b/src/mesa/drivers/dri/intel/intel_pixel_bitmap.c @@ -32,7 +32,19 @@ #include "main/mtypes.h" #include "main/macros.h" #include "main/bufferobj.h" +#include "main/pixelstore.h" #include "main/state.h" +#include "main/teximage.h" +#include "main/texenv.h" +#include "main/texobj.h" +#include "main/texstate.h" +#include "main/texparam.h" +#include "main/matrix.h" +#include "main/varray.h" +#include "main/attrib.h" +#include "main/enable.h" +#include "shader/arbprogram.h" +#include "glapi/dispatch.h" #include "swrast/swrast.h" #include "intel_screen.h" @@ -87,6 +99,11 @@ static GLboolean test_bit( const GLubyte *src, return (src[bit/8] & (1<<(bit % 8))) ? 1 : 0; } +static GLboolean test_msb_bit(const GLubyte *src, GLuint bit) +{ + return (src[bit/8] & (1<<(7 - (bit % 8)))) ? 1 : 0; +} + static void set_bit( GLubyte *dest, GLuint bit ) { @@ -317,9 +334,187 @@ out: return GL_TRUE; } +static GLboolean +intel_texture_bitmap(GLcontext * ctx, + GLint dst_x, GLint dst_y, + GLsizei width, GLsizei height, + const struct gl_pixelstore_attrib *unpack, + const GLubyte *bitmap) +{ + struct intel_context *intel = intel_context(ctx); + static const char *fp = + "!!ARBfp1.0\n" + "TEMP val;\n" + "PARAM color=program.local[0];\n" + "TEX val, fragment.texcoord[0], texture[0], 2D;\n" + "ADD val, val.wwww, {-.5, -.5, -.5, -.5};\n" + "KIL val;\n" + "MOV result.color, color;\n" + "END\n"; + GLuint texname; + GLfloat vertices[4][4]; + GLfloat texcoords[4][2]; + GLint old_active_texture; + GLubyte *unpacked_bitmap; + GLubyte *a8_bitmap; + int x, y; + + /* We need a fragment program for the KIL effect */ + if (!ctx->Extensions.ARB_fragment_program || + !ctx->Extensions.ARB_vertex_program) { + if (INTEL_DEBUG & DEBUG_FALLBACKS) + fprintf(stderr, + "glBitmap fallback: No fragment/vertex program support\n"); + return GL_FALSE; + } + + /* We're going to mess with texturing with no regard to existing texture + * state, so if there is some set up we have to bail. + */ + if (ctx->Texture._EnabledUnits != 0) { + if (INTEL_DEBUG & DEBUG_FALLBACKS) + fprintf(stderr, "glBitmap fallback: texturing enabled\n"); + return GL_FALSE; + } + + /* Can't do textured DrawPixels with a fragment program, unless we were + * to generate a new program that sampled our texture and put the results + * in the fragment color before the user's program started. + */ + if (ctx->FragmentProgram.Enabled) { + if (INTEL_DEBUG & DEBUG_FALLBACKS) + fprintf(stderr, "glBitmap fallback: fragment program enabled\n"); + return GL_FALSE; + } + + if (ctx->VertexProgram.Enabled) { + if (INTEL_DEBUG & DEBUG_FALLBACKS) + fprintf(stderr, "glBitmap fallback: vertex program enabled\n"); + return GL_FALSE; + } + + /* Check that we can load in a texture this big. */ + if (width > (1 << (ctx->Const.MaxTextureLevels - 1)) || + height > (1 << (ctx->Const.MaxTextureLevels - 1))) { + if (INTEL_DEBUG & DEBUG_FALLBACKS) + fprintf(stderr, "glBitmap fallback: bitmap too large (%dx%d)\n", + width, height); + return GL_FALSE; + } + /* Convert the A1 bitmap to an A8 format suitable for glTexImage */ + if (unpack->BufferObj->Name) { + bitmap = map_pbo(ctx, width, height, unpack, bitmap); + if (bitmap == NULL) + return GL_TRUE; /* even though this is an error, we're done */ + } + unpacked_bitmap = _mesa_unpack_bitmap(width, height, bitmap, + unpack); + a8_bitmap = _mesa_calloc(width * height); + for (y = 0; y < height; y++) { + for (x = 0; x < width; x++) { + if (test_msb_bit(unpacked_bitmap, ALIGN(width, 8) * y + x)) + a8_bitmap[y * width + x] = 0xff; + } + } + _mesa_free(unpacked_bitmap); + if (unpack->BufferObj->Name) { + /* done with PBO so unmap it now */ + ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT, + unpack->BufferObj); + } + /* Save GL state before we start setting up our drawing */ + _mesa_PushAttrib(GL_ENABLE_BIT | GL_TRANSFORM_BIT | GL_CURRENT_BIT | + GL_VIEWPORT_BIT); + _mesa_PushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT | + GL_CLIENT_PIXEL_STORE_BIT); + old_active_texture = ctx->Texture.CurrentUnit; + + _mesa_Disable(GL_POLYGON_STIPPLE); + + /* Upload our bitmap data to an alpha texture */ + _mesa_ActiveTextureARB(GL_TEXTURE0_ARB); + _mesa_Enable(GL_TEXTURE_2D); + _mesa_GenTextures(1, &texname); + _mesa_BindTexture(GL_TEXTURE_2D, texname); + _mesa_TexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + _mesa_TexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + _mesa_PixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); + _mesa_PixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE); + _mesa_PixelStorei(GL_UNPACK_ROW_LENGTH, 0); + _mesa_PixelStorei(GL_UNPACK_SKIP_PIXELS, 0); + _mesa_PixelStorei(GL_UNPACK_SKIP_ROWS, 0); + _mesa_PixelStorei(GL_UNPACK_ALIGNMENT, 1); + _mesa_TexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, + GL_ALPHA, GL_UNSIGNED_BYTE, a8_bitmap); + _mesa_free(a8_bitmap); + + _mesa_Viewport(0, 0, ctx->DrawBuffer->Width, ctx->DrawBuffer->Height); + _mesa_MatrixMode(GL_PROJECTION); + _mesa_PushMatrix(); + _mesa_LoadIdentity(); + _mesa_Ortho(0, ctx->DrawBuffer->Width, 0, ctx->DrawBuffer->Height, 1, -1); + + _mesa_MatrixMode(GL_MODELVIEW); + _mesa_PushMatrix(); + _mesa_LoadIdentity(); + + intel_meta_set_fragment_program(intel, &intel->meta.bitmap_fp, fp); + _mesa_ProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 0, + ctx->Current.RasterColor); + intel_meta_set_passthrough_vertex_program(intel); + + vertices[0][0] = dst_x; + vertices[0][1] = dst_y; + vertices[0][2] = ctx->Current.RasterPos[2]; + vertices[0][3] = 1.0; + vertices[1][0] = dst_x + width; + vertices[1][1] = dst_y; + vertices[1][2] = ctx->Current.RasterPos[2]; + vertices[1][3] = 1.0; + vertices[2][0] = dst_x + width; + vertices[2][1] = dst_y + height; + vertices[2][2] = ctx->Current.RasterPos[2]; + vertices[2][3] = 1.0; + vertices[3][0] = dst_x; + vertices[3][1] = dst_y + height; + vertices[3][2] = ctx->Current.RasterPos[2]; + vertices[3][3] = 1.0; + + texcoords[0][0] = 0.0; + texcoords[0][1] = 0.0; + texcoords[1][0] = 1.0; + texcoords[1][1] = 0.0; + texcoords[2][0] = 1.0; + texcoords[2][1] = 1.0; + texcoords[3][0] = 0.0; + texcoords[3][1] = 1.0; + + _mesa_VertexPointer(4, GL_FLOAT, 4 * sizeof(GLfloat), &vertices); + _mesa_TexCoordPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), &texcoords); + _mesa_Enable(GL_VERTEX_ARRAY); + _mesa_Enable(GL_TEXTURE_COORD_ARRAY); + CALL_DrawArrays(ctx->Exec, (GL_TRIANGLE_FAN, 0, 4)); + + intel_meta_restore_fragment_program(intel); + intel_meta_restore_vertex_program(intel); + + _mesa_MatrixMode(GL_PROJECTION); + _mesa_PopMatrix(); + _mesa_MatrixMode(GL_MODELVIEW); + _mesa_PopMatrix(); + + _mesa_PopClientAttrib(); + _mesa_Disable(GL_TEXTURE_2D); /* asserted that it was disabled at entry */ + _mesa_ActiveTextureARB(GL_TEXTURE0_ARB + old_active_texture); + _mesa_PopAttrib(); + + _mesa_DeleteTextures(1, &texname); + return GL_TRUE; +} /* There are a large number of possible ways to implement bitmap on * this hardware, most of them have some sort of drawback. Here are a @@ -352,6 +547,10 @@ intelBitmap(GLcontext * ctx, unpack, pixels)) return; + if (intel_texture_bitmap(ctx, x, y, width, height, + unpack, pixels)) + return; + if (INTEL_DEBUG & DEBUG_PIXEL) _mesa_printf("%s: fallback to swrast\n", __FUNCTION__); -- cgit v1.2.3 From bfebeffc0045266d354a36968336337e099a9f27 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 31 Dec 2008 00:29:49 -0800 Subject: intel: Share passthrough transform setup between glBitmap and glDrawPixels. The DrawPixels path was missing glViewport care, so blender's toolbar icons would go to the wrong places. Bug #19118. --- src/mesa/drivers/dri/intel/intel_context.h | 3 +++ src/mesa/drivers/dri/intel/intel_pixel.c | 35 ++++++++++++++++++++++++ src/mesa/drivers/dri/intel/intel_pixel.h | 3 ++- src/mesa/drivers/dri/intel/intel_pixel_bitmap.c | 20 +++----------- src/mesa/drivers/dri/intel/intel_pixel_draw.c | 36 +++++++------------------ 5 files changed, 52 insertions(+), 45 deletions(-) (limited to 'src/mesa') diff --git a/src/mesa/drivers/dri/intel/intel_context.h b/src/mesa/drivers/dri/intel/intel_context.h index 4100677750..048286c196 100644 --- a/src/mesa/drivers/dri/intel/intel_context.h +++ b/src/mesa/drivers/dri/intel/intel_context.h @@ -165,6 +165,9 @@ struct intel_context GLboolean saved_fp_enable; struct gl_vertex_program *saved_vp; GLboolean saved_vp_enable; + + GLint saved_vp_x, saved_vp_y; + GLsizei saved_vp_width, saved_vp_height; } meta; GLint refcount; diff --git a/src/mesa/drivers/dri/intel/intel_pixel.c b/src/mesa/drivers/dri/intel/intel_pixel.c index 91027d37e7..cf2f32d384 100644 --- a/src/mesa/drivers/dri/intel/intel_pixel.c +++ b/src/mesa/drivers/dri/intel/intel_pixel.c @@ -29,6 +29,7 @@ #include "main/state.h" #include "main/context.h" #include "main/enable.h" +#include "main/matrix.h" #include "swrast/swrast.h" #include "shader/arbprogram.h" #include "shader/program.h" @@ -171,6 +172,40 @@ intel_check_blit_format(struct intel_region * region, return GL_FALSE; } +void +intel_meta_set_passthrough_transform(struct intel_context *intel) +{ + GLcontext *ctx = &intel->ctx; + + intel->meta.saved_vp_x = ctx->Viewport.X; + intel->meta.saved_vp_y = ctx->Viewport.Y; + intel->meta.saved_vp_width = ctx->Viewport.Width; + intel->meta.saved_vp_height = ctx->Viewport.Height; + + _mesa_Viewport(0, 0, ctx->DrawBuffer->Width, ctx->DrawBuffer->Height); + + _mesa_MatrixMode(GL_PROJECTION); + _mesa_PushMatrix(); + _mesa_LoadIdentity(); + _mesa_Ortho(0, ctx->DrawBuffer->Width, 0, ctx->DrawBuffer->Height, 1, -1); + + _mesa_MatrixMode(GL_MODELVIEW); + _mesa_PushMatrix(); + _mesa_LoadIdentity(); +} + +void +intel_meta_restore_transform(struct intel_context *intel) +{ + _mesa_MatrixMode(GL_PROJECTION); + _mesa_PopMatrix(); + _mesa_MatrixMode(GL_MODELVIEW); + _mesa_PopMatrix(); + + _mesa_Viewport(intel->meta.saved_vp_x, intel->meta.saved_vp_y, + intel->meta.saved_vp_width, intel->meta.saved_vp_height); +} + /** * Set up a vertex program to pass through the position and first texcoord * for pixel path. diff --git a/src/mesa/drivers/dri/intel/intel_pixel.h b/src/mesa/drivers/dri/intel/intel_pixel.h index 9556efc71c..76b8781316 100644 --- a/src/mesa/drivers/dri/intel/intel_pixel.h +++ b/src/mesa/drivers/dri/intel/intel_pixel.h @@ -31,7 +31,8 @@ #include "main/mtypes.h" void intelInitPixelFuncs(struct dd_function_table *functions); - +void intel_meta_set_passthrough_transform(struct intel_context *intel); +void intel_meta_restore_transform(struct intel_context *intel); void intel_meta_set_passthrough_vertex_program(struct intel_context *intel); void intel_meta_restore_vertex_program(struct intel_context *intel); void intel_meta_set_fragment_program(struct intel_context *intel, diff --git a/src/mesa/drivers/dri/intel/intel_pixel_bitmap.c b/src/mesa/drivers/dri/intel/intel_pixel_bitmap.c index 88e181a51f..1d7f15f10a 100644 --- a/src/mesa/drivers/dri/intel/intel_pixel_bitmap.c +++ b/src/mesa/drivers/dri/intel/intel_pixel_bitmap.c @@ -39,7 +39,6 @@ #include "main/texobj.h" #include "main/texstate.h" #include "main/texparam.h" -#include "main/matrix.h" #include "main/varray.h" #include "main/attrib.h" #include "main/enable.h" @@ -425,7 +424,7 @@ intel_texture_bitmap(GLcontext * ctx, } /* Save GL state before we start setting up our drawing */ - _mesa_PushAttrib(GL_ENABLE_BIT | GL_TRANSFORM_BIT | GL_CURRENT_BIT | + _mesa_PushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_VIEWPORT_BIT); _mesa_PushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT | GL_CLIENT_PIXEL_STORE_BIT); @@ -451,20 +450,11 @@ intel_texture_bitmap(GLcontext * ctx, GL_ALPHA, GL_UNSIGNED_BYTE, a8_bitmap); _mesa_free(a8_bitmap); - _mesa_Viewport(0, 0, ctx->DrawBuffer->Width, ctx->DrawBuffer->Height); - _mesa_MatrixMode(GL_PROJECTION); - _mesa_PushMatrix(); - _mesa_LoadIdentity(); - _mesa_Ortho(0, ctx->DrawBuffer->Width, 0, ctx->DrawBuffer->Height, 1, -1); - - _mesa_MatrixMode(GL_MODELVIEW); - _mesa_PushMatrix(); - _mesa_LoadIdentity(); - intel_meta_set_fragment_program(intel, &intel->meta.bitmap_fp, fp); _mesa_ProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 0, ctx->Current.RasterColor); intel_meta_set_passthrough_vertex_program(intel); + intel_meta_set_passthrough_transform(intel); vertices[0][0] = dst_x; vertices[0][1] = dst_y; @@ -498,14 +488,10 @@ intel_texture_bitmap(GLcontext * ctx, _mesa_Enable(GL_TEXTURE_COORD_ARRAY); CALL_DrawArrays(ctx->Exec, (GL_TRIANGLE_FAN, 0, 4)); + intel_meta_restore_transform(intel); intel_meta_restore_fragment_program(intel); intel_meta_restore_vertex_program(intel); - _mesa_MatrixMode(GL_PROJECTION); - _mesa_PopMatrix(); - _mesa_MatrixMode(GL_MODELVIEW); - _mesa_PopMatrix(); - _mesa_PopClientAttrib(); _mesa_Disable(GL_TEXTURE_2D); /* asserted that it was disabled at entry */ _mesa_ActiveTextureARB(GL_TEXTURE0_ARB + old_active_texture); diff --git a/src/mesa/drivers/dri/intel/intel_pixel_draw.c b/src/mesa/drivers/dri/intel/intel_pixel_draw.c index 8ebbc95a1d..0d66935ad2 100644 --- a/src/mesa/drivers/dri/intel/intel_pixel_draw.c +++ b/src/mesa/drivers/dri/intel/intel_pixel_draw.c @@ -36,7 +36,6 @@ #include "main/texobj.h" #include "main/texstate.h" #include "main/texparam.h" -#include "main/matrix.h" #include "main/varray.h" #include "main/attrib.h" #include "main/enable.h" @@ -68,6 +67,7 @@ intel_texture_drawpixels(GLcontext * ctx, const struct gl_pixelstore_attrib *unpack, const GLvoid *pixels) { + struct intel_context *intel = intel_context(ctx); GLuint texname; GLfloat vertices[4][4]; GLfloat texcoords[4][2]; @@ -117,7 +117,7 @@ intel_texture_drawpixels(GLcontext * ctx, return GL_FALSE; } - _mesa_PushAttrib(GL_ENABLE_BIT | GL_TRANSFORM_BIT | GL_TEXTURE_BIT | + _mesa_PushAttrib(GL_ENABLE_BIT | GL_TEXTURE_BIT | GL_CURRENT_BIT); _mesa_PushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT); @@ -138,14 +138,7 @@ intel_texture_drawpixels(GLcontext * ctx, _mesa_TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, format, type, pixels); - _mesa_MatrixMode(GL_PROJECTION); - _mesa_PushMatrix(); - _mesa_LoadIdentity(); - _mesa_Ortho(0, ctx->DrawBuffer->Width, 0, ctx->DrawBuffer->Height, 1, -1); - - _mesa_MatrixMode(GL_MODELVIEW); - _mesa_PushMatrix(); - _mesa_LoadIdentity(); + intel_meta_set_passthrough_transform(intel); /* Create the vertex buffer based on the current raster pos. The x and y * we're handed are ctx->Current.RasterPos[0,1] rounded to integers. @@ -184,10 +177,7 @@ intel_texture_drawpixels(GLcontext * ctx, _mesa_Enable(GL_TEXTURE_COORD_ARRAY); CALL_DrawArrays(ctx->Exec, (GL_TRIANGLE_FAN, 0, 4)); - _mesa_MatrixMode(GL_PROJECTION); - _mesa_PopMatrix(); - _mesa_MatrixMode(GL_MODELVIEW); - _mesa_PopMatrix(); + intel_meta_restore_transform(intel); _mesa_PopClientAttrib(); _mesa_PopAttrib(); @@ -205,6 +195,7 @@ intel_stencil_drawpixels(GLcontext * ctx, const struct gl_pixelstore_attrib *unpack, const GLvoid *pixels) { + struct intel_context *intel = intel_context(ctx); GLuint texname, rb_name, fb_name, old_fb_name; GLfloat vertices[4][2]; GLfloat texcoords[4][2]; @@ -267,7 +258,7 @@ intel_stencil_drawpixels(GLcontext * ctx, return GL_FALSE; } - _mesa_PushAttrib(GL_ENABLE_BIT | GL_TRANSFORM_BIT | GL_TEXTURE_BIT | + _mesa_PushAttrib(GL_ENABLE_BIT | GL_TEXTURE_BIT | GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); _mesa_PushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT); old_fb_name = ctx->DrawBuffer->Name; @@ -335,14 +326,7 @@ intel_stencil_drawpixels(GLcontext * ctx, ctx->Unpack = old_unpack; _mesa_free(stencil_pixels); - _mesa_MatrixMode(GL_PROJECTION); - _mesa_PushMatrix(); - _mesa_LoadIdentity(); - _mesa_Ortho(0, ctx->DrawBuffer->Width, 0, ctx->DrawBuffer->Height, 1, -1); - - _mesa_MatrixMode(GL_MODELVIEW); - _mesa_PushMatrix(); - _mesa_LoadIdentity(); + intel_meta_set_passthrough_transform(intel); vertices[0][0] = x; vertices[0][1] = y; @@ -368,12 +352,10 @@ intel_stencil_drawpixels(GLcontext * ctx, _mesa_Enable(GL_TEXTURE_COORD_ARRAY); CALL_DrawArrays(ctx->Exec, (GL_TRIANGLE_FAN, 0, 4)); + intel_meta_restore_transform(intel); + _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, old_fb_name); - _mesa_MatrixMode(GL_PROJECTION); - _mesa_PopMatrix(); - _mesa_MatrixMode(GL_MODELVIEW); - _mesa_PopMatrix(); _mesa_PopClientAttrib(); _mesa_PopAttrib(); -- cgit v1.2.3 From e9b34885b8ff2ccb67a801cd1ce07e0df1b0e397 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 31 Dec 2008 11:54:02 -0700 Subject: mesa: increase max texture image units and GLSL samplers to 16 The max texture coord units is still 8. All the fixed-function paths are still limited to 8 too. But GLSL shaders can use more samplers now. Note that some texcoord-related data structures are declared to be 16 elements in size rather than 8. This just simplifies the code in a few places; the extra elements aren't accessible to the user. These changes haven't been extensively tested yet, but sanity checking has been done. It should be possible to increase the max image units/samplers to 32 without doing anything special. Beyond that we'll need longer bitfields in a few places. --- src/mesa/main/arrayobj.c | 6 +- src/mesa/main/attrib.c | 5 +- src/mesa/main/bufferobj.c | 2 +- src/mesa/main/config.h | 53 ++++++------ src/mesa/main/context.c | 20 ++--- src/mesa/main/enable.c | 148 +++++++++++++++++++++------------- src/mesa/main/ffvertex_prog.c | 4 +- src/mesa/main/mtypes.h | 37 +++++---- src/mesa/main/points.c | 2 +- src/mesa/main/rastpos.c | 2 +- src/mesa/main/texenvprogram.c | 23 +++++- src/mesa/main/texstate.c | 11 ++- src/mesa/shader/slang/slang_codegen.c | 2 +- src/mesa/shader/slang/slang_link.c | 11 +-- 14 files changed, 189 insertions(+), 137 deletions(-) (limited to 'src/mesa') diff --git a/src/mesa/main/arrayobj.c b/src/mesa/main/arrayobj.c index 1461239317..f3f482f8c8 100644 --- a/src/mesa/main/arrayobj.c +++ b/src/mesa/main/arrayobj.c @@ -142,7 +142,7 @@ _mesa_initialize_array_object( GLcontext *ctx, obj->Index.StrideB = 0; obj->Index.Ptr = NULL; obj->Index.Enabled = GL_FALSE; - for (i = 0; i < MAX_TEXTURE_UNITS; i++) { + for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) { obj->TexCoord[i].Size = 4; obj->TexCoord[i].Type = GL_FLOAT; obj->TexCoord[i].Stride = 0; @@ -181,7 +181,7 @@ _mesa_initialize_array_object( GLcontext *ctx, obj->SecondaryColor.BufferObj = ctx->Array.NullBufferObj; obj->FogCoord.BufferObj = ctx->Array.NullBufferObj; obj->Index.BufferObj = ctx->Array.NullBufferObj; - for (i = 0; i < MAX_TEXTURE_UNITS; i++) { + for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) { obj->TexCoord[i].BufferObj = ctx->Array.NullBufferObj; } obj->EdgeFlag.BufferObj = ctx->Array.NullBufferObj; @@ -335,7 +335,7 @@ _mesa_DeleteVertexArraysAPPLE(GLsizei n, const GLuint *ids) unbind_buffer_object( ctx, obj->SecondaryColor.BufferObj ); unbind_buffer_object( ctx, obj->FogCoord.BufferObj ); unbind_buffer_object( ctx, obj->Index.BufferObj ); - for (i = 0; i < MAX_TEXTURE_UNITS; i++) { + for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) { unbind_buffer_object( ctx, obj->TexCoord[i].BufferObj ); } unbind_buffer_object( ctx, obj->EdgeFlag.BufferObj ); diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c index dc85da2518..825c841ee2 100644 --- a/src/mesa/main/attrib.c +++ b/src/mesa/main/attrib.c @@ -1,8 +1,9 @@ /* * Mesa 3-D graphics library - * Version: 7.2 + * Version: 7.3 * * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. + * Copyright (C) 2009 VMware, Inc. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -224,7 +225,7 @@ _mesa_PushAttrib(GLbitfield mask) attr->SampleAlphaToOne = ctx->Multisample.SampleAlphaToOne; attr->SampleCoverage = ctx->Multisample.SampleCoverage; attr->SampleCoverageInvert = ctx->Multisample.SampleCoverageInvert; - for (i=0; iConst.MaxTextureUnits; i++) { attr->Texture[i] = ctx->Texture.Unit[i].Enabled; attr->TexGen[i] = ctx->Texture.Unit[i].TexGenEnabled; attr->TextureColorTable[i] = ctx->Texture.Unit[i].ColorTableEnabled; diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c index 918e87246f..59fe8e25de 100644 --- a/src/mesa/main/bufferobj.c +++ b/src/mesa/main/bufferobj.c @@ -801,7 +801,7 @@ _mesa_DeleteBuffersARB(GLsizei n, const GLuint *ids) unbind(ctx, &ctx->Array.ArrayObj->FogCoord.BufferObj, bufObj); unbind(ctx, &ctx->Array.ArrayObj->Index.BufferObj, bufObj); unbind(ctx, &ctx->Array.ArrayObj->EdgeFlag.BufferObj, bufObj); - for (j = 0; j < MAX_TEXTURE_UNITS; j++) { + for (j = 0; j < MAX_TEXTURE_COORD_UNITS; j++) { unbind(ctx, &ctx->Array.ArrayObj->TexCoord[j].BufferObj, bufObj); } for (j = 0; j < VERT_ATTRIB_MAX; j++) { diff --git a/src/mesa/main/config.h b/src/mesa/main/config.h index 424ed60b57..cf1198cd0d 100644 --- a/src/mesa/main/config.h +++ b/src/mesa/main/config.h @@ -1,13 +1,9 @@ -/** - * \file config.h - * Tunable configuration parameters. - */ - /* * Mesa 3-D graphics library - * Version: 7.1 + * Version: 7.3 * * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. + * Copyright (C) 2008 VMware, Inc. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -27,6 +23,10 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/** + * \file config.h + * Tunable configuration parameters. + */ #ifndef MESA_CONFIG_H_INCLUDED #define MESA_CONFIG_H_INCLUDED @@ -115,27 +115,28 @@ /** Maximum number of layers in a 1D or 2D array texture - GL_MESA_texture_array */ #define MAX_ARRAY_TEXTURE_LAYERS 64 -/** Number of texture units - GL_ARB_multitexture - * This needs to be the larger of MAX_TEXTURE_COORD_UNITS and - * MAX_TEXTURE_IMAGE_UNITS seen below, since MAX_TEXTURE_UNITS is used - * to dimension some arrays that store both coord and image data. -*/ -#define MAX_TEXTURE_UNITS 8 - -/*@}*/ +/** + * Max number of texture coordinate units. This mainly just applies to + * the fixed-function vertex code. This will be difficult to raise above + * eight because of various vertex attribute bitvectors. + */ +#define MAX_TEXTURE_COORD_UNITS 8 +/** + * Max number of texture image units. Also determines number of texture + * samplers in shaders. + */ +#define MAX_TEXTURE_IMAGE_UNITS 16 /** - * \name Separate numbers of texture coordinates and texture image units. - * - * These values will eventually replace most instances of MAX_TEXTURE_UNITS. - * We should always have MAX_TEXTURE_COORD_UNITS <= MAX_TEXTURE_IMAGE_UNITS. - * And, GL_MAX_TEXTURE_UNITS <= MAX_TEXTURE_COORD_UNITS. + * Larger of MAX_TEXTURE_COORD_UNITS and MAX_TEXTURE_IMAGE_UNITS. + * This value is only used for dimensioning arrays. + * Either MAX_TEXTURE_COORD_UNITS or MAX_TEXTURE_IMAGE_UNITS (or the + * corresponding ctx->Const.MaxTextureCoord/ImageUnits fields) should be + * used almost everywhere else. */ -/*@{*/ -#define MAX_TEXTURE_COORD_UNITS 8 -#define MAX_TEXTURE_IMAGE_UNITS 8 -/*@}*/ +#define MAX_TEXTURE_UNITS ((MAX_TEXTURE_COORD_UNITS > MAX_TEXTURE_IMAGE_UNITS) ? MAX_TEXTURE_COORD_UNITS : MAX_TEXTURE_IMAGE_UNITS) + /** * Maximum viewport/image width. Must accomodate all texture sizes too. @@ -192,7 +193,7 @@ #define MAX_PROGRAM_ADDRESS_REGS 2 #define MAX_UNIFORMS 256 /**< number of vec4 uniforms */ #define MAX_VARYING 8 /**< number of float[4] vectors */ -#define MAX_SAMPLERS 8 +#define MAX_SAMPLERS MAX_TEXTURE_IMAGE_UNITS #define MAX_PROGRAM_INPUTS 32 #define MAX_PROGRAM_OUTPUTS 32 /*@}*/ @@ -220,8 +221,8 @@ /** For GL_ARB_vertex_shader */ /*@{*/ #define MAX_VERTEX_ATTRIBS 16 -#define MAX_VERTEX_TEXTURE_IMAGE_UNITS MAX_TEXTURE_UNITS -#define MAX_COMBINED_TEXTURE_IMAGE_UNITS (MAX_TEXTURE_IMAGE_UNITS + MAX_VERTEX_TEXTURE_IMAGE_UNITS) +#define MAX_VERTEX_TEXTURE_IMAGE_UNITS MAX_TEXTURE_IMAGE_UNITS +#define MAX_COMBINED_TEXTURE_IMAGE_UNITS MAX_TEXTURE_IMAGE_UNITS /*@}*/ diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index a41cb42952..b59ad355fb 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -1,14 +1,9 @@ -/** - * \file context.c - * Mesa context/visual/framebuffer management functions. - * \author Brian Paul - */ - /* * Mesa 3-D graphics library - * Version: 7.1 + * Version: 7.3 * * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. + * Copyright (C) 2008 VMware, Inc. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -28,6 +23,11 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/** + * \file context.c + * Mesa context/visual/framebuffer management functions. + * \author Brian Paul + */ /** * \mainpage Mesa Main Module @@ -847,9 +847,6 @@ _mesa_init_constants(GLcontext *ctx) assert(MAX_TEXTURE_LEVELS >= MAX_3D_TEXTURE_LEVELS); assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS); - assert(MAX_TEXTURE_UNITS >= MAX_TEXTURE_COORD_UNITS); - assert(MAX_TEXTURE_UNITS >= MAX_TEXTURE_IMAGE_UNITS); - /* Constants, may be overriden (usually only reduced) by device drivers */ ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS; ctx->Const.Max3DTextureLevels = MAX_3D_TEXTURE_LEVELS; @@ -963,6 +960,9 @@ check_context_limits(GLcontext *ctx) assert(ctx->Const.MaxTextureUnits <= MAX_TEXTURE_IMAGE_UNITS); assert(ctx->Const.MaxTextureUnits <= MAX_TEXTURE_COORD_UNITS); + /* number of coord units cannot be greater than number of image units */ + assert(ctx->Const.MaxTextureCoordUnits <= ctx->Const.MaxTextureImageUnits); + assert(ctx->Const.MaxViewportWidth <= MAX_WIDTH); assert(ctx->Const.MaxViewportHeight <= MAX_WIDTH); diff --git a/src/mesa/main/enable.c b/src/mesa/main/enable.c index e0483a72e8..160a6fc086 100644 --- a/src/mesa/main/enable.c +++ b/src/mesa/main/enable.c @@ -201,6 +201,26 @@ _mesa_DisableClientState( GLenum cap ) } + +/** + * Return pointer to current texture unit for setting/getting coordinate + * state. + * Note that we'll set GL_INVALID_OPERATION if the active texture unit is + * higher than the number of supported coordinate units. And we'll return NULL. + */ +static struct gl_texture_unit * +get_texcoord_unit(GLcontext *ctx) +{ + if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) { + _mesa_error(ctx, GL_INVALID_OPERATION, "glEnable/Disable(texcoord unit)"); + return NULL; + } + else { + return &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; + } +} + + /** * Helper function to enable or disable a texture target. */ @@ -612,54 +632,62 @@ _mesa_set_enable(GLcontext *ctx, GLenum cap, GLboolean state) return; } break; - case GL_TEXTURE_GEN_Q: { - GLuint unit = ctx->Texture.CurrentUnit; - struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; - GLuint newenabled = texUnit->TexGenEnabled & ~Q_BIT; - if (state) - newenabled |= Q_BIT; - if (texUnit->TexGenEnabled == newenabled) - return; - FLUSH_VERTICES(ctx, _NEW_TEXTURE); - texUnit->TexGenEnabled = newenabled; + case GL_TEXTURE_GEN_Q: + { + struct gl_texture_unit *texUnit = get_texcoord_unit(ctx); + if (texUnit) { + GLuint newenabled = texUnit->TexGenEnabled & ~Q_BIT; + if (state) + newenabled |= Q_BIT; + if (texUnit->TexGenEnabled == newenabled) + return; + FLUSH_VERTICES(ctx, _NEW_TEXTURE); + texUnit->TexGenEnabled = newenabled; + } + } break; - } - case GL_TEXTURE_GEN_R: { - GLuint unit = ctx->Texture.CurrentUnit; - struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; - GLuint newenabled = texUnit->TexGenEnabled & ~R_BIT; - if (state) - newenabled |= R_BIT; - if (texUnit->TexGenEnabled == newenabled) - return; - FLUSH_VERTICES(ctx, _NEW_TEXTURE); - texUnit->TexGenEnabled = newenabled; + case GL_TEXTURE_GEN_R: + { + struct gl_texture_unit *texUnit = get_texcoord_unit(ctx); + if (texUnit) { + GLuint newenabled = texUnit->TexGenEnabled & ~R_BIT; + if (state) + newenabled |= R_BIT; + if (texUnit->TexGenEnabled == newenabled) + return; + FLUSH_VERTICES(ctx, _NEW_TEXTURE); + texUnit->TexGenEnabled = newenabled; + } + } break; - } - case GL_TEXTURE_GEN_S: { - GLuint unit = ctx->Texture.CurrentUnit; - struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; - GLuint newenabled = texUnit->TexGenEnabled & ~S_BIT; - if (state) - newenabled |= S_BIT; - if (texUnit->TexGenEnabled == newenabled) - return; - FLUSH_VERTICES(ctx, _NEW_TEXTURE); - texUnit->TexGenEnabled = newenabled; + case GL_TEXTURE_GEN_S: + { + struct gl_texture_unit *texUnit = get_texcoord_unit(ctx); + if (texUnit) { + GLuint newenabled = texUnit->TexGenEnabled & ~S_BIT; + if (state) + newenabled |= S_BIT; + if (texUnit->TexGenEnabled == newenabled) + return; + FLUSH_VERTICES(ctx, _NEW_TEXTURE); + texUnit->TexGenEnabled = newenabled; + } + } break; - } - case GL_TEXTURE_GEN_T: { - GLuint unit = ctx->Texture.CurrentUnit; - struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; - GLuint newenabled = texUnit->TexGenEnabled & ~T_BIT; - if (state) - newenabled |= T_BIT; - if (texUnit->TexGenEnabled == newenabled) - return; - FLUSH_VERTICES(ctx, _NEW_TEXTURE); - texUnit->TexGenEnabled = newenabled; + case GL_TEXTURE_GEN_T: + { + struct gl_texture_unit *texUnit = get_texcoord_unit(ctx); + if (texUnit) { + GLuint newenabled = texUnit->TexGenEnabled & ~T_BIT; + if (state) + newenabled |= T_BIT; + if (texUnit->TexGenEnabled == newenabled) + return; + FLUSH_VERTICES(ctx, _NEW_TEXTURE); + texUnit->TexGenEnabled = newenabled; + } + } break; - } /* * CLIENT STATE!!! @@ -1153,28 +1181,36 @@ _mesa_IsEnabled( GLenum cap ) return is_texture_enabled(ctx, TEXTURE_3D_BIT); case GL_TEXTURE_GEN_Q: { - const struct gl_texture_unit *texUnit; - texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; - return (texUnit->TexGenEnabled & Q_BIT) ? GL_TRUE : GL_FALSE; + const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx); + if (texUnit) { + return (texUnit->TexGenEnabled & Q_BIT) ? GL_TRUE : GL_FALSE; + } } + return GL_FALSE; case GL_TEXTURE_GEN_R: { - const struct gl_texture_unit *texUnit; - texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; - return (texUnit->TexGenEnabled & R_BIT) ? GL_TRUE : GL_FALSE; + const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx); + if (texUnit) { + return (texUnit->TexGenEnabled & R_BIT) ? GL_TRUE : GL_FALSE; + } } + return GL_FALSE; case GL_TEXTURE_GEN_S: { - const struct gl_texture_unit *texUnit; - texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; - return (texUnit->TexGenEnabled & S_BIT) ? GL_TRUE : GL_FALSE; + const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx); + if (texUnit) { + return (texUnit->TexGenEnabled & S_BIT) ? GL_TRUE : GL_FALSE; + } } + return GL_FALSE; case GL_TEXTURE_GEN_T: { - const struct gl_texture_unit *texUnit; - texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; - return (texUnit->TexGenEnabled & T_BIT) ? GL_TRUE : GL_FALSE; + const struct gl_texture_unit *texUnit = get_texcoord_unit(ctx); + if (texUnit) { + return (texUnit->TexGenEnabled & T_BIT) ? GL_TRUE : GL_FALSE; + } } + return GL_FALSE; /* * CLIENT STATE!!! diff --git a/src/mesa/main/ffvertex_prog.c b/src/mesa/main/ffvertex_prog.c index ebc02940de..9021931b35 100644 --- a/src/mesa/main/ffvertex_prog.c +++ b/src/mesa/main/ffvertex_prog.c @@ -275,7 +275,7 @@ static void make_state_key( GLcontext *ctx, struct state_key *key ) ctx->Texture._EnabledUnits) key->texture_enabled_global = 1; - for (i = 0; i < MAX_TEXTURE_UNITS; i++) { + for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) { struct gl_texture_unit *texUnit = &ctx->Texture.Unit[i]; if (texUnit->_ReallyEnabled) @@ -1451,7 +1451,7 @@ static void build_texture_transform( struct tnl_program *p ) { GLuint i, j; - for (i = 0; i < MAX_TEXTURE_UNITS; i++) { + for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) { if (!(p->state->fragprog_inputs_read & FRAG_BIT_TEX(i))) continue; diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 5ed73b7d0e..9cb6159f00 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -1,15 +1,9 @@ -/** - * \file mtypes.h - * Main Mesa data structures. - * - * Please try to mark derived values with a leading underscore ('_'). - */ - /* * Mesa 3-D graphics library * Version: 7.3 * * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2008 VMware, Inc. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -29,7 +23,12 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - +/** + * \file mtypes.h + * Main Mesa data structures. + * + * Please try to mark derived values with a leading underscore ('_'). + */ #ifndef TYPES_H #define TYPES_H @@ -639,7 +638,7 @@ struct gl_current_attrib GLfloat RasterColor[4]; GLfloat RasterSecondaryColor[4]; GLfloat RasterIndex; - GLfloat RasterTexCoords[MAX_TEXTURE_COORD_UNITS][4]; + GLfloat RasterTexCoords[MAX_TEXTURE_UNITS][4]; GLboolean RasterPosValid; /*@}*/ }; @@ -723,10 +722,10 @@ struct gl_enable_attrib GLboolean SampleCoverage; /* GL_ARB_multisample */ GLboolean SampleCoverageInvert; /* GL_ARB_multisample */ GLboolean RasterPositionUnclipped; /* GL_IBM_rasterpos_clip */ - GLuint Texture[MAX_TEXTURE_IMAGE_UNITS]; - GLuint TexGen[MAX_TEXTURE_COORD_UNITS]; + GLuint Texture[MAX_TEXTURE_UNITS]; + GLuint TexGen[MAX_TEXTURE_UNITS]; /* SGI_texture_color_table */ - GLboolean TextureColorTable[MAX_TEXTURE_IMAGE_UNITS]; + GLboolean TextureColorTable[MAX_TEXTURE_UNITS]; /* GL_ARB_vertex_program / GL_NV_vertex_program */ GLboolean VertexProgram; GLboolean VertexProgramPointSize; @@ -1069,7 +1068,7 @@ struct gl_point_attrib GLfloat Threshold; /**< GL_EXT_point_parameters */ GLboolean _Attenuated; /**< True if Params != [1, 0, 0] */ GLboolean PointSprite; /**< GL_NV/ARB_point_sprite */ - GLboolean CoordReplace[MAX_TEXTURE_COORD_UNITS]; /**< GL_ARB_point_sprite */ + GLboolean CoordReplace[MAX_TEXTURE_UNITS]; /**< GL_ARB_point_sprite */ GLenum SpriteRMode; /**< GL_NV_point_sprite (only!) */ GLenum SpriteOrigin; /**< GL_ARB_point_sprite */ }; @@ -1557,7 +1556,7 @@ struct gl_texture_attrib * name multitexture */ /**@{*/ - GLuint CurrentUnit; /**< Active texture unit */ + GLuint CurrentUnit; /**< Active texture unit [0, MaxTextureImageUnits-1] */ GLbitfield _EnabledUnits; /**< one bit set for each really-enabled unit */ GLbitfield _EnabledCoordUnits; /**< one bit per enabled coordinate unit */ GLbitfield _GenFlags; /**< for texgen */ @@ -1875,7 +1874,7 @@ struct gl_program GLbitfield OutputsWritten; /**< Bitmask of which output regs are written to */ GLbitfield InputFlags[MAX_PROGRAM_INPUTS]; /**< PROG_PARAM_BIT_x flags */ GLbitfield OutputFlags[MAX_PROGRAM_OUTPUTS]; /**< PROG_PARAM_BIT_x flags */ - GLbitfield TexturesUsed[MAX_TEXTURE_IMAGE_UNITS]; /**< TEXTURE_x_BIT bitmask */ + GLbitfield TexturesUsed[MAX_TEXTURE_UNITS]; /**< TEXTURE_x_BIT bitmask */ GLbitfield SamplersUsed; /**< Bitfield of which samplers are used */ GLbitfield ShadowSamplers; /**< Texture units used for shadow sampling. */ @@ -2469,9 +2468,9 @@ struct gl_constants GLint MaxTextureRectSize; /* GL_NV_texture_rectangle */ GLuint MaxTextureCoordUnits; GLuint MaxTextureImageUnits; - GLuint MaxTextureUnits; /* = MIN(CoordUnits, ImageUnits) */ - GLfloat MaxTextureMaxAnisotropy; /* GL_EXT_texture_filter_anisotropic */ - GLfloat MaxTextureLodBias; /* GL_EXT_texture_lod_bias */ + GLuint MaxTextureUnits; /**< = MIN(CoordUnits, ImageUnits) */ + GLfloat MaxTextureMaxAnisotropy; /**< GL_EXT_texture_filter_anisotropic */ + GLfloat MaxTextureLodBias; /**< GL_EXT_texture_lod_bias */ GLuint MaxArrayLockSize; GLint SubPixelBits; GLfloat MinPointSize, MaxPointSize; /* aliased */ @@ -2946,7 +2945,7 @@ struct __GLcontextRec struct gl_matrix_stack ModelviewMatrixStack; struct gl_matrix_stack ProjectionMatrixStack; struct gl_matrix_stack ColorMatrixStack; - struct gl_matrix_stack TextureMatrixStack[MAX_TEXTURE_COORD_UNITS]; + struct gl_matrix_stack TextureMatrixStack[MAX_TEXTURE_UNITS]; struct gl_matrix_stack ProgramMatrixStack[MAX_PROGRAM_MATRICES]; struct gl_matrix_stack *CurrentStack; /**< Points to one of the above stacks */ /*@}*/ diff --git a/src/mesa/main/points.c b/src/mesa/main/points.c index 1fe697033f..4c8fc1f72e 100644 --- a/src/mesa/main/points.c +++ b/src/mesa/main/points.c @@ -257,7 +257,7 @@ _mesa_init_point(GLcontext *ctx) ctx->Point.PointSprite = GL_FALSE; /* GL_ARB/NV_point_sprite */ ctx->Point.SpriteRMode = GL_ZERO; /* GL_NV_point_sprite (only!) */ ctx->Point.SpriteOrigin = GL_UPPER_LEFT; /* GL_ARB_point_sprite */ - for (i = 0; i < MAX_TEXTURE_UNITS; i++) { + for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) { ctx->Point.CoordReplace[i] = GL_FALSE; /* GL_ARB/NV_point_sprite */ } } diff --git a/src/mesa/main/rastpos.c b/src/mesa/main/rastpos.c index 9842172f46..9f309d6ab8 100644 --- a/src/mesa/main/rastpos.c +++ b/src/mesa/main/rastpos.c @@ -500,7 +500,7 @@ void _mesa_init_rastpos( GLcontext * ctx ) ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 ); ASSIGN_4V( ctx->Current.RasterSecondaryColor, 0.0, 0.0, 0.0, 1.0 ); ctx->Current.RasterIndex = 1.0; - for (i=0; iCurrent.RasterTexCoords[i], 0.0, 0.0, 0.0, 1.0 ); ctx->Current.RasterPosValid = GL_TRUE; } diff --git a/src/mesa/main/texenvprogram.c b/src/mesa/main/texenvprogram.c index ba7ce4a3cc..6a57d50193 100644 --- a/src/mesa/main/texenvprogram.c +++ b/src/mesa/main/texenvprogram.c @@ -38,6 +38,21 @@ #include "texenvprogram.h" +/* + * Note on texture units: + * + * The number of texture units supported by fixed-function fragment + * processing is MAX_TEXTURE_COORD_UNITS, not MAX_TEXTURE_IMAGE_UNITS. + * That's because there's a one-to-one correspondence between texture + * coordinates and samplers in fixed-function processing. + * + * Since fixed-function vertex processing is limited to MAX_TEXTURE_COORD_UNITS + * sets of texcoords, so is fixed-function fragment processing. + * + * We can safely use ctx->Const.MaxTextureUnits for loop bounds. + */ + + struct texenvprog_cache_item { GLuint hash; @@ -52,7 +67,7 @@ struct texenvprog_cache_item * up to four instructions per texture unit (TEX + 3 for combine), * then there's fog and specular add. */ -#define MAX_INSTRUCTIONS ((MAX_TEXTURE_UNITS * 4) + 12) +#define MAX_INSTRUCTIONS ((MAX_TEXTURE_COORD_UNITS * 4) + 12) #define DISASSEM (MESA_VERBOSE & VERBOSE_DISASSEM) @@ -211,7 +226,7 @@ static void make_state_key( GLcontext *ctx, struct state_key *key ) memset(key, 0, sizeof(*key)); - for (i=0;iConst.MaxTextureUnits; i++) { const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[i]; GLenum format; @@ -306,7 +321,7 @@ struct texenv_fragment_program { GLbitfield temp_in_use; /* Tracks temporary regs which are in use. */ GLboolean error; - struct ureg src_texture[MAX_TEXTURE_UNITS]; + struct ureg src_texture[MAX_TEXTURE_COORD_UNITS]; /* Reg containing each texture unit's sampled texture color, * else undef. */ @@ -1056,7 +1071,7 @@ create_new_program(GLcontext *ctx, struct state_key *key, p.program->Base.InputsRead = 0; p.program->Base.OutputsWritten = 1 << FRAG_RESULT_COLR; - for (unit = 0; unit < MAX_TEXTURE_UNITS; unit++) + for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) p.src_texture[unit] = undef; p.src_previous = undef; diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c index f019377041..29955d76cb 100644 --- a/src/mesa/main/texstate.c +++ b/src/mesa/main/texstate.c @@ -81,7 +81,7 @@ _mesa_copy_texture_state( const GLcontext *src, GLcontext *dst ) dst->Texture.SharedPalette = src->Texture.SharedPalette; /* per-unit state */ - for (i = 0; i < src->Const.MaxTextureUnits; i++) { + for (i = 0; i < src->Const.MaxTextureImageUnits; i++) { dst->Texture.Unit[i].Enabled = src->Texture.Unit[i].Enabled; dst->Texture.Unit[i].EnvMode = src->Texture.Unit[i].EnvMode; COPY_4V(dst->Texture.Unit[i].EnvColor, src->Texture.Unit[i].EnvColor); @@ -307,8 +307,7 @@ _mesa_ActiveTextureARB(GLenum texture) _mesa_debug(ctx, "glActiveTexture %s\n", _mesa_lookup_enum_by_nr(texture)); - /* XXX error-check against max(coordunits, imageunits) */ - if (texUnit >= ctx->Const.MaxTextureUnits) { + if (texUnit >= ctx->Const.MaxTextureImageUnits) { _mesa_error(ctx, GL_INVALID_ENUM, "glActiveTexture(texture)"); return; } @@ -369,7 +368,7 @@ update_texture_matrices( GLcontext *ctx ) ctx->Texture._TexMatEnabled = 0; - for (i=0; i < ctx->Const.MaxTextureUnits; i++) { + for (i=0; i < ctx->Const.MaxTextureCoordUnits; i++) { if (_math_matrix_is_dirty(ctx->TextureMatrixStack[i].Top)) { _math_matrix_analyse( ctx->TextureMatrixStack[i].Top ); @@ -491,7 +490,7 @@ update_texture_state( GLcontext *ctx ) /* * Update texture unit state. */ - for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) { + for (unit = 0; unit < ctx->Const.MaxTextureImageUnits; unit++) { struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; GLbitfield enableBits; @@ -621,7 +620,7 @@ update_texture_state( GLcontext *ctx ) } /* Setup texgen for those texture coordinate sets that are in use */ - for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) { + for (unit = 0; unit < ctx->Const.MaxTextureCoordUnits; unit++) { struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; if (!(ctx->Texture._EnabledCoordUnits & (1 << unit))) diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index 7d764cb5c1..4976daf533 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -391,7 +391,7 @@ _slang_input_index(const char *name, GLenum target, GLuint *swizzleOut) const struct input_info *inputs = (target == GL_VERTEX_PROGRAM_ARB) ? vertInputs : fragInputs; - ASSERT(MAX_TEXTURE_UNITS == 8); /* if this fails, fix vertInputs above */ + ASSERT(MAX_TEXTURE_COORD_UNITS == 8); /* if this fails, fix vertInputs above */ for (i = 0; inputs[i].Name; i++) { if (strcmp(inputs[i].Name, name) == 0) { diff --git a/src/mesa/shader/slang/slang_link.c b/src/mesa/shader/slang/slang_link.c index 22ae635b06..b49fd0e99d 100644 --- a/src/mesa/shader/slang/slang_link.c +++ b/src/mesa/shader/slang/slang_link.c @@ -208,7 +208,8 @@ link_varying_vars(struct gl_shader_program *shProg, struct gl_program *prog) * the vertex and fragment shaders. */ static GLboolean -link_uniform_vars(struct gl_shader_program *shProg, +link_uniform_vars(GLcontext *ctx, + struct gl_shader_program *shProg, struct gl_program *prog, GLuint *numSamplers) { @@ -239,10 +240,10 @@ link_uniform_vars(struct gl_shader_program *shProg, /* Allocate a new sampler index */ GLuint sampNum = *numSamplers; GLuint oldSampNum = (GLuint) prog->Parameters->ParameterValues[i][0]; - if (oldSampNum >= MAX_SAMPLERS) { + if (oldSampNum >= ctx->Const.MaxTextureImageUnits) { char s[100]; sprintf(s, "Too many texture samplers (%u, max is %u)", - oldSampNum + 1, MAX_SAMPLERS); + oldSampNum + 1, ctx->Const.MaxTextureImageUnits); link_error(shProg, s); return GL_FALSE; } @@ -568,13 +569,13 @@ _slang_link(GLcontext *ctx, /* link uniform vars */ if (shProg->VertexProgram) { - if (!link_uniform_vars(shProg, &shProg->VertexProgram->Base, + if (!link_uniform_vars(ctx, shProg, &shProg->VertexProgram->Base, &numSamplers)) { return; } } if (shProg->FragmentProgram) { - if (!link_uniform_vars(shProg, &shProg->FragmentProgram->Base, + if (!link_uniform_vars(ctx, shProg, &shProg->FragmentProgram->Base, &numSamplers)) { return; } -- cgit v1.2.3 From dfada459aabf1a02dc2dbdb6644283fc95df2586 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 1 Jan 2009 08:07:54 -0700 Subject: mesa: updated comments about GLSL constants --- src/mesa/shader/slang/library/slang_common_builtin.gc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/mesa') diff --git a/src/mesa/shader/slang/library/slang_common_builtin.gc b/src/mesa/shader/slang/library/slang_common_builtin.gc index 3e03b101b8..230c57cea8 100644 --- a/src/mesa/shader/slang/library/slang_common_builtin.gc +++ b/src/mesa/shader/slang/library/slang_common_builtin.gc @@ -27,8 +27,9 @@ // From Shader Spec, ver. 1.10, rev. 59 // -//bp: XXX these will probably go away since the value needs to be -//determined at runtime and may vary from one GLcontext to another... +// Note: the values assigned to these constants here aren't actually used. +// They're set by the compiler according to the GL context limits. +// See slang_simplify.c const int gl_MaxLights = 8; const int gl_MaxClipPlanes = 6; const int gl_MaxTextureUnits = 8; -- cgit v1.2.3 From 1d03f2834fd7279c28de3e57281f5a45c2fb4b8a Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 31 Dec 2008 16:38:10 -0700 Subject: mesa: comments, whitespace changes --- src/mesa/main/ffvertex_prog.c | 44 ++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) (limited to 'src/mesa') diff --git a/src/mesa/main/ffvertex_prog.c b/src/mesa/main/ffvertex_prog.c index 9021931b35..cc1b44de64 100644 --- a/src/mesa/main/ffvertex_prog.c +++ b/src/mesa/main/ffvertex_prog.c @@ -26,7 +26,7 @@ **************************************************************************/ /** - * \file ffvertex_prog. + * \file ffvertex_prog.c * * Create a vertex program to execute the current fixed function T&L pipeline. * \author Keith Whitwell @@ -99,6 +99,7 @@ static GLuint translate_fog_mode( GLenum mode ) } } + #define TXG_NONE 0 #define TXG_OBJ_LINEAR 1 #define TXG_EYE_LINEAR 2 @@ -143,6 +144,7 @@ tnl_get_per_vertex_materials(GLcontext *ctx) return mask; } + /** * Should fog be computed per-vertex? */ @@ -157,6 +159,7 @@ tnl_get_per_vertex_fog(GLcontext *ctx) #endif } + static GLboolean check_active_shininess( GLcontext *ctx, const struct state_key *key, GLuint side ) @@ -174,8 +177,6 @@ static GLboolean check_active_shininess( GLcontext *ctx, return GL_FALSE; } - - static void make_state_key( GLcontext *ctx, struct state_key *key ) @@ -407,11 +408,13 @@ static struct ureg swizzle( struct ureg reg, int x, int y, int z, int w ) return reg; } + static struct ureg swizzle1( struct ureg reg, int x ) { return swizzle(reg, x, x, x, x); } + static struct ureg get_temp( struct tnl_program *p ) { int bit = _mesa_ffs( ~p->temp_in_use ); @@ -427,6 +430,7 @@ static struct ureg get_temp( struct tnl_program *p ) return make_ureg(PROGRAM_TEMPORARY, bit-1); } + static struct ureg reserve_temp( struct tnl_program *p ) { struct ureg temp = get_temp( p ); @@ -434,6 +438,7 @@ static struct ureg reserve_temp( struct tnl_program *p ) return temp; } + static void release_temp( struct tnl_program *p, struct ureg reg ) { if (reg.file == PROGRAM_TEMPORARY) { @@ -442,13 +447,13 @@ static void release_temp( struct tnl_program *p, struct ureg reg ) } } + static void release_temps( struct tnl_program *p ) { p->temp_in_use = p->temp_reserved; } - /** * \param input one of VERT_ATTRIB_x tokens. */ @@ -458,6 +463,7 @@ static struct ureg register_input( struct tnl_program *p, GLuint input ) return make_ureg(PROGRAM_INPUT, input); } + /** * \param input one of VERT_RESULT_x tokens. */ @@ -467,6 +473,7 @@ static struct ureg register_output( struct tnl_program *p, GLuint output ) return make_ureg(PROGRAM_OUTPUT, output); } + static struct ureg register_const4f( struct tnl_program *p, GLfloat s0, GLfloat s1, @@ -486,6 +493,7 @@ static struct ureg register_const4f( struct tnl_program *p, return make_ureg(PROGRAM_CONSTANT, idx); } + #define register_const1f(p, s0) register_const4f(p, s0, 0, 0, 1) #define register_scalar_const(p, s0) register_const4f(p, s0, s0, s0, s0) #define register_const2f(p, s0, s1) register_const4f(p, s0, s1, 0, 1) @@ -496,6 +504,7 @@ static GLboolean is_undef( struct ureg reg ) return reg.file == PROGRAM_UNDEFINED; } + static struct ureg get_identity_param( struct tnl_program *p ) { if (is_undef(p->identity)) @@ -504,6 +513,7 @@ static struct ureg get_identity_param( struct tnl_program *p ) return p->identity; } + static struct ureg register_param5(struct tnl_program *p, GLint s0, GLint s1, @@ -561,6 +571,7 @@ static void emit_arg( struct prog_src_register *src, ASSERT(src->Index == reg.idx); } + static void emit_dst( struct prog_dst_register *dst, struct ureg reg, GLuint mask ) { @@ -576,6 +587,7 @@ static void emit_dst( struct prog_dst_register *dst, ASSERT(dst->Index == reg.idx); } + static void debug_insn( struct prog_instruction *inst, const char *fn, GLuint line ) { @@ -686,6 +698,7 @@ static void emit_matrix_transform_vec4( struct tnl_program *p, emit_op2(p, OPCODE_DP4, dest, WRITEMASK_W, src, mat[3]); } + /* This version is much easier to implement if writemasks are not * supported natively on the target or (like SSE), the target doesn't * have a clean/obvious dotproduct implementation. @@ -711,6 +724,7 @@ static void emit_transpose_matrix_transform_vec4( struct tnl_program *p, release_temp(p, tmp); } + static void emit_matrix_transform_vec3( struct tnl_program *p, struct ureg dest, const struct ureg *mat, @@ -738,6 +752,7 @@ static void emit_normalize_vec3( struct tnl_program *p, #endif } + static void emit_passthrough( struct tnl_program *p, GLuint input, GLuint output ) @@ -746,6 +761,7 @@ static void emit_passthrough( struct tnl_program *p, emit_op1(p, OPCODE_MOV, out, 0, register_input(p, input)); } + static struct ureg get_eye_position( struct tnl_program *p ) { if (is_undef(p->eye_position)) { @@ -793,7 +809,6 @@ static struct ureg get_eye_position_z( struct tnl_program *p ) } - static struct ureg get_eye_position_normalized( struct tnl_program *p ) { if (is_undef(p->eye_position_normalized)) { @@ -855,7 +870,6 @@ static struct ureg get_transformed_normal( struct tnl_program *p ) } - static void build_hpos( struct tnl_program *p ) { struct ureg pos = register_input( p, VERT_ATTRIB_POS ); @@ -881,7 +895,9 @@ static GLuint material_attrib( GLuint side, GLuint property ) side); } -/* Get a bitmask of which material values vary on a per-vertex basis. + +/** + * Get a bitmask of which material values vary on a per-vertex basis. */ static void set_material_flags( struct tnl_program *p ) { @@ -917,7 +933,9 @@ static struct ureg get_material( struct tnl_program *p, GLuint side, MAT_BIT_FRONT_AMBIENT | \ MAT_BIT_FRONT_DIFFUSE) << (side)) -/* Either return a precalculated constant value or emit code to + +/** + * Either return a precalculated constant value or emit code to * calculate these values dynamically in the case where material calls * are present between begin/end pairs. * @@ -960,6 +978,7 @@ static struct ureg get_lightprod( struct tnl_program *p, GLuint light, return register_param4(p, STATE_LIGHTPROD, light, side, property); } + static struct ureg calculate_light_attenuation( struct tnl_program *p, GLuint i, struct ureg VPpli, @@ -1216,7 +1235,6 @@ static void build_lighting( struct tnl_program *p ) struct ureg res0, res1; GLuint mask0, mask1; - if (count == nr_lights) { if (separate) { mask0 = WRITEMASK_XYZ; @@ -1237,7 +1255,6 @@ static void build_lighting( struct tnl_program *p ) res1 = _col1; } - if (!is_undef(att)) { /* light is attenuated by distance */ emit_op1(p, OPCODE_LIT, lit, 0, dots); @@ -1310,7 +1327,6 @@ static void build_lighting( struct tnl_program *p ) emit_op3(p, OPCODE_MAD, res0, mask0, swizzle1(lit,Y), diffuse, _bfc0); emit_op3(p, OPCODE_MAD, res1, mask1, swizzle1(lit,Z), specular, _bfc1); - /* restore negate flag for next lighting */ dots = negate(dots); @@ -1385,6 +1401,7 @@ static void build_fog( struct tnl_program *p ) emit_op1(p, useabs ? OPCODE_ABS : OPCODE_MOV, fog, WRITEMASK_X, input); } } + static void build_reflect_texgen( struct tnl_program *p, struct ureg dest, @@ -1404,6 +1421,7 @@ static void build_reflect_texgen( struct tnl_program *p, release_temp(p, tmp); } + static void build_sphere_texgen( struct tnl_program *p, struct ureg dest, GLuint writemask ) @@ -1514,10 +1532,8 @@ static void build_texture_transform( struct tnl_program *p ) case TXG_NONE: copy_mask |= WRITEMASK_X << j; } - } - if (sphere_mask) { build_sphere_texgen(p, out_texgen, sphere_mask); } @@ -1600,6 +1616,7 @@ static void build_atten_pointsize( struct tnl_program *p ) release_temp(p, ut); } + /** * Emit constant point size. */ @@ -1610,6 +1627,7 @@ static void build_constant_pointsize( struct tnl_program *p ) emit_op1(p, OPCODE_MOV, out, WRITEMASK_X, state_size); } + /** * Pass-though per-vertex point size, from user's point size array. */ -- cgit v1.2.3 From 23b0ad4d7e9130a07fec1e968777dfa59bc1d54e Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 31 Dec 2008 16:43:57 -0700 Subject: i965: whitespace, comment changes --- src/mesa/drivers/dri/i965/brw_vs_emit.c | 37 ++++++++++----------------------- 1 file changed, 11 insertions(+), 26 deletions(-) (limited to 'src/mesa') diff --git a/src/mesa/drivers/dri/i965/brw_vs_emit.c b/src/mesa/drivers/dri/i965/brw_vs_emit.c index 4a9541378f..ebd8a17f79 100644 --- a/src/mesa/drivers/dri/i965/brw_vs_emit.c +++ b/src/mesa/drivers/dri/i965/brw_vs_emit.c @@ -73,8 +73,6 @@ static void brw_vs_alloc_regs( struct brw_vs_compile *c ) c->prog_data.curb_read_length = reg - 1; - - /* Allocate input regs: */ c->nr_inputs = 0; @@ -84,8 +82,7 @@ static void brw_vs_alloc_regs( struct brw_vs_compile *c ) c->regs[PROGRAM_INPUT][i] = brw_vec8_grf(reg, 0); reg++; } - } - + } /* Allocate outputs: TODO: could organize the non-position outputs * to go straight into message regs. @@ -339,6 +336,7 @@ static void emit_math1( struct brw_vs_compile *c, } } + static void emit_math2( struct brw_vs_compile *c, GLuint function, struct brw_reg dst, @@ -370,7 +368,6 @@ static void emit_math2( struct brw_vs_compile *c, release_tmp(c, tmp); } } - static void emit_exp_noalias( struct brw_vs_compile *c, @@ -521,8 +518,6 @@ static void emit_log_noalias( struct brw_vs_compile *c, } - - /* Need to unalias - consider swizzles: r0 = DST r0.xxxx r1 */ static void emit_dst_noalias( struct brw_vs_compile *c, @@ -544,6 +539,7 @@ static void emit_dst_noalias( struct brw_vs_compile *c, brw_MOV(p, brw_writemask(dst, WRITEMASK_W), arg1); } + static void emit_xpd( struct brw_compile *p, struct brw_reg dst, struct brw_reg t, @@ -554,7 +550,6 @@ static void emit_xpd( struct brw_compile *p, } - static void emit_lit_noalias( struct brw_vs_compile *c, struct brw_reg dst, struct brw_reg arg0 ) @@ -596,9 +591,6 @@ static void emit_lit_noalias( struct brw_vs_compile *c, } - - - /* TODO: relative addressing! */ static struct brw_reg get_reg( struct brw_vs_compile *c, @@ -634,7 +626,6 @@ static struct brw_reg get_reg( struct brw_vs_compile *c, } - static struct brw_reg deref( struct brw_vs_compile *c, struct brw_reg arg, GLint offset) @@ -728,8 +719,6 @@ static struct brw_reg get_dst( struct brw_vs_compile *c, } - - static void emit_swz( struct brw_vs_compile *c, struct brw_reg dst, struct prog_src_register src ) @@ -801,8 +790,8 @@ static void emit_swz( struct brw_vs_compile *c, } - -/* Post-vertex-program processing. Send the results to the URB. +/** + * Post-vertex-program processing. Send the results to the URB. */ static void emit_vertex_write( struct brw_vs_compile *c) { @@ -817,7 +806,6 @@ static void emit_vertex_write( struct brw_vs_compile *c) get_reg(c, PROGRAM_INPUT, VERT_ATTRIB_EDGEFLAG)); } - /* Build ndc coords */ if (!c->key.know_w_is_one) { ndc = get_tmp(c); @@ -848,7 +836,6 @@ static void emit_vertex_write( struct brw_vs_compile *c) brw_AND(p, brw_writemask(header1, WRITEMASK_W), header1, brw_imm_ud(0x7ff<<8)); } - for (i = 0; i < c->key.nr_userclip; i++) { brw_set_conditionalmod(p, BRW_CONDITIONAL_L); brw_DP4(p, brw_null_reg(), pos, c->userplane[i]); @@ -856,7 +843,6 @@ static void emit_vertex_write( struct brw_vs_compile *c) brw_set_predicate_control(p, BRW_PREDICATE_NONE); } - /* i965 clipping workaround: * 1) Test for -ve rhw * 2) If set, @@ -888,14 +874,12 @@ static void emit_vertex_write( struct brw_vs_compile *c) brw_MOV(p, retype(brw_message_reg(1), BRW_REGISTER_TYPE_UD), brw_imm_ud(0)); } - /* Emit the (interleaved) headers for the two vertices - an 8-reg * of zeros followed by two sets of NDC coordinates: */ brw_set_access_mode(p, BRW_ALIGN_1); brw_MOV(p, offset(m0, 2), ndc); brw_MOV(p, offset(m0, 3), pos); - brw_urb_WRITE(p, brw_null_reg(), /* dest */ @@ -909,9 +893,9 @@ static void emit_vertex_write( struct brw_vs_compile *c) 1, /* writes complete */ 0, /* urb destination offset */ BRW_URB_SWIZZLE_INTERLEAVE); - } + static void post_vs_emit( struct brw_vs_compile *c, struct brw_instruction *end_inst ) { @@ -1102,7 +1086,7 @@ void brw_vs_emit(struct brw_vs_compile *c ) break; case OPCODE_SGT: emit_sgt(p, dst, args[0], args[1]); - break; + break; case OPCODE_SLT: emit_slt(p, dst, args[0], args[1]); break; @@ -1136,7 +1120,7 @@ void brw_vs_emit(struct brw_vs_compile *c ) brw_set_predicate_control(p, BRW_PREDICATE_NORMAL); brw_ADD(p, brw_ip_reg(), brw_ip_reg(), brw_imm_d(1*16)); brw_set_predicate_control_flag_value(p, 0xff); - break; + break; case OPCODE_CAL: brw_set_access_mode(p, BRW_ALIGN_1); brw_ADD(p, deref_1d(stack_index, 0), brw_ip_reg(), brw_imm_d(3*16)); @@ -1145,7 +1129,7 @@ void brw_vs_emit(struct brw_vs_compile *c ) get_addr_reg(stack_index), brw_imm_d(4)); inst->Data = &p->store[p->nr_insn]; brw_ADD(p, brw_ip_reg(), brw_ip_reg(), brw_imm_d(1*16)); - break; + break; case OPCODE_RET: brw_ADD(p, get_addr_reg(stack_index), get_addr_reg(stack_index), brw_imm_d(-4)); @@ -1154,10 +1138,11 @@ void brw_vs_emit(struct brw_vs_compile *c ) brw_set_access_mode(p, BRW_ALIGN_16); case OPCODE_END: brw_ADD(p, brw_ip_reg(), brw_ip_reg(), brw_imm_d(1*16)); - break; + break; case OPCODE_PRINT: case OPCODE_BGNSUB: case OPCODE_ENDSUB: + /* no-op instructions */ break; default: _mesa_printf("Unsupported opcode %i (%s) in vertex shader\n", -- cgit v1.2.3 From 131ac5b465d1f676ca2e592e4fecfcbc14b23b49 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 31 Dec 2008 16:49:58 -0700 Subject: i965: implement OPCODE_NRM3/NRM4 --- src/mesa/drivers/dri/i965/brw_vs_emit.c | 36 ++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'src/mesa') diff --git a/src/mesa/drivers/dri/i965/brw_vs_emit.c b/src/mesa/drivers/dri/i965/brw_vs_emit.c index ebd8a17f79..10f3e28190 100644 --- a/src/mesa/drivers/dri/i965/brw_vs_emit.c +++ b/src/mesa/drivers/dri/i965/brw_vs_emit.c @@ -591,6 +591,31 @@ static void emit_lit_noalias( struct brw_vs_compile *c, } +/** 3 or 4-component vector normalization */ +static void emit_nrm( struct brw_vs_compile *c, + struct brw_reg dst, + struct brw_reg arg0, + int num_comps) +{ + struct brw_compile *p = &c->func; + struct brw_reg tmp = get_tmp(c); + + /* tmp = dot(arg0, arg0) */ + if (num_comps == 3) + brw_DP3(p, tmp, arg0, arg0); + else + brw_DP4(p, tmp, arg0, arg0); + + /* tmp = 1 / tmp */ + emit_math1(c, BRW_MATH_FUNCTION_RSQ, tmp, tmp, BRW_MATH_PRECISION_FULL); + + /* dst = arg0 * tmp */ + brw_MUL(p, dst, arg0, tmp); + + release_tmp(c, tmp); +} + + /* TODO: relative addressing! */ static struct brw_reg get_reg( struct brw_vs_compile *c, @@ -1019,6 +1044,12 @@ void brw_vs_emit(struct brw_vs_compile *c ) case OPCODE_DPH: brw_DPH(p, dst, args[0], args[1]); break; + case OPCODE_NRM3: + emit_nrm(c, dst, args[0], 3); + break; + case OPCODE_NRM4: + emit_nrm(c, dst, args[0], 4); + break; case OPCODE_DST: unalias2(c, dst, args[0], args[1], emit_dst_noalias); break; @@ -1145,11 +1176,10 @@ void brw_vs_emit(struct brw_vs_compile *c ) /* no-op instructions */ break; default: - _mesa_printf("Unsupported opcode %i (%s) in vertex shader\n", - inst->Opcode, inst->Opcode < MAX_OPCODE ? + _mesa_problem(NULL, "Unsupported opcode %i (%s) in vertex shader", + inst->Opcode, inst->Opcode < MAX_OPCODE ? _mesa_opcode_string(inst->Opcode) : "unknown"); - break; } if ((inst->DstReg.File == PROGRAM_OUTPUT) -- cgit v1.2.3 From 914fcbafdb166603da408d58a0a0f381d9c08e9f Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 31 Dec 2008 17:01:44 -0700 Subject: i965: indentation and formatting fixes --- src/mesa/drivers/dri/i965/brw_wm_emit.c | 81 +++++++++++++++------------------ 1 file changed, 36 insertions(+), 45 deletions(-) (limited to 'src/mesa') diff --git a/src/mesa/drivers/dri/i965/brw_wm_emit.c b/src/mesa/drivers/dri/i965/brw_wm_emit.c index 58c78c4b2c..b5050a3e40 100644 --- a/src/mesa/drivers/dri/i965/brw_wm_emit.c +++ b/src/mesa/drivers/dri/i965/brw_wm_emit.c @@ -194,7 +194,7 @@ static void emit_linterp( struct brw_compile *p, interp[2] = brw_vec1_grf(nr+1, 0); interp[3] = brw_vec1_grf(nr+1, 4); - for(i = 0; i < 4; i++ ) { + for (i = 0; i < 4; i++) { if (mask & (1<key.runtime_check_aads_emit) { if (c->key.aa_dest_stencil_reg) emit_aa(c, arg1, 2); @@ -996,8 +994,6 @@ static void emit_fb_write( struct brw_wm_compile *c, } - - /* Post-fragment-program processing. Send the results to the * framebuffer. */ @@ -1022,6 +1018,7 @@ static void emit_spill( struct brw_wm_compile *c, slot); } + static void emit_unspill( struct brw_wm_compile *c, struct brw_reg reg, GLuint slot ) @@ -1047,7 +1044,6 @@ static void emit_unspill( struct brw_wm_compile *c, } - /** * Retrieve upto 4 GEN4 register pairs for the given wm reg: */ @@ -1073,6 +1069,7 @@ static void get_argument_regs( struct brw_wm_compile *c, } } + static void spill_values( struct brw_wm_compile *c, struct brw_wm_value *values, GLuint nr ) @@ -1085,7 +1082,6 @@ static void spill_values( struct brw_wm_compile *c, } - /* Emit the fragment program instructions here. */ void brw_wm_emit( struct brw_wm_compile *c ) @@ -1176,7 +1172,7 @@ void brw_wm_emit( struct brw_wm_compile *c ) emit_alu1(p, brw_RNDD, dst, dst_flags, args[0]); break; - case OPCODE_DP3: /* */ + case OPCODE_DP3: emit_dp3(p, dst, dst_flags, args[0], args[1]); break; @@ -1188,7 +1184,7 @@ void brw_wm_emit( struct brw_wm_compile *c ) emit_dph(p, dst, dst_flags, args[0], args[1]); break; - case OPCODE_LRP: /* */ + case OPCODE_LRP: emit_lrp(p, dst, dst_flags, args[0], args[1], args[2]); break; @@ -1315,8 +1311,3 @@ void brw_wm_emit( struct brw_wm_compile *c ) inst->dst[i]->spill_slot); } } - - - - - -- cgit v1.2.3 From e262da804014d57156346ff487904ce220974832 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 31 Dec 2008 17:16:27 -0700 Subject: i965: fix comment --- src/mesa/drivers/dri/i965/brw_vs_emit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/mesa') diff --git a/src/mesa/drivers/dri/i965/brw_vs_emit.c b/src/mesa/drivers/dri/i965/brw_vs_emit.c index 10f3e28190..80ff7437ba 100644 --- a/src/mesa/drivers/dri/i965/brw_vs_emit.c +++ b/src/mesa/drivers/dri/i965/brw_vs_emit.c @@ -606,7 +606,7 @@ static void emit_nrm( struct brw_vs_compile *c, else brw_DP4(p, tmp, arg0, arg0); - /* tmp = 1 / tmp */ + /* tmp = 1 / sqrt(tmp) */ emit_math1(c, BRW_MATH_FUNCTION_RSQ, tmp, tmp, BRW_MATH_PRECISION_FULL); /* dst = arg0 * tmp */ -- cgit v1.2.3 From 32e03c4a2ff5ef07de892dcd26f6be3b82ab3ba1 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 31 Dec 2008 17:16:44 -0700 Subject: i965: added OPCODE_NRM3/4 --- src/mesa/drivers/dri/i965/brw_wm.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/mesa') diff --git a/src/mesa/drivers/dri/i965/brw_wm.c b/src/mesa/drivers/dri/i965/brw_wm.c index bad76793af..5b4ee20ecb 100644 --- a/src/mesa/drivers/dri/i965/brw_wm.c +++ b/src/mesa/drivers/dri/i965/brw_wm.c @@ -36,6 +36,7 @@ #include "brw_state.h" +/** Return number of src args for given instruction */ GLuint brw_wm_nr_args( GLuint opcode ) { switch (opcode) { @@ -58,6 +59,8 @@ GLuint brw_wm_nr_args( GLuint opcode ) case OPCODE_TXP: case OPCODE_KIL: case OPCODE_LIT: + case OPCODE_NRM3: + case OPCODE_NRM4: case WM_CINTERP: case WM_WPOSXY: return 1; -- cgit v1.2.3 From 3b891a502b030f2ce8cd7a1aba93df11595f5c95 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 1 Jan 2009 12:03:07 -0700 Subject: i965: comments, clean-ups, re-order some functions --- src/mesa/drivers/dri/i965/brw_eu.h | 88 +++++++++++++++++++++++--------------- 1 file changed, 54 insertions(+), 34 deletions(-) (limited to 'src/mesa') diff --git a/src/mesa/drivers/dri/i965/brw_eu.h b/src/mesa/drivers/dri/i965/brw_eu.h index 49b422ee2f..31e9ceb42e 100644 --- a/src/mesa/drivers/dri/i965/brw_eu.h +++ b/src/mesa/drivers/dri/i965/brw_eu.h @@ -129,17 +129,28 @@ static INLINE int type_sz( GLuint type ) } } +/** + * Construct a brw_reg. + * \param file one of the BRW_x_REGISTER_FILE values + * \param nr register number/index + * \param subnr register sub number + * \param type one of BRW_REGISTER_TYPE_x + * \param vstride one of BRW_VERTICAL_STRIDE_x + * \param width one of BRW_WIDTH_x + * \param hstride one of BRW_HORIZONTAL_STRIDE_x + * \param swizzle one of BRW_SWIZZLE_x + * \param writemask WRITEMASK_X/Y/Z/W bitfield + */ static INLINE struct brw_reg brw_reg( GLuint file, - GLuint nr, - GLuint subnr, - GLuint type, - GLuint vstride, - GLuint width, - GLuint hstride, - GLuint swizzle, - GLuint writemask) -{ - + GLuint nr, + GLuint subnr, + GLuint type, + GLuint vstride, + GLuint width, + GLuint hstride, + GLuint swizzle, + GLuint writemask ) +{ struct brw_reg reg; reg.type = type; reg.file = file; @@ -166,6 +177,7 @@ static INLINE struct brw_reg brw_reg( GLuint file, return reg; } +/** Construct float[16] register */ static INLINE struct brw_reg brw_vec16_reg( GLuint file, GLuint nr, GLuint subnr ) @@ -181,6 +193,7 @@ static INLINE struct brw_reg brw_vec16_reg( GLuint file, WRITEMASK_XYZW); } +/** Construct float[8] register */ static INLINE struct brw_reg brw_vec8_reg( GLuint file, GLuint nr, GLuint subnr ) @@ -196,7 +209,7 @@ static INLINE struct brw_reg brw_vec8_reg( GLuint file, WRITEMASK_XYZW); } - +/** Construct float[4] register */ static INLINE struct brw_reg brw_vec4_reg( GLuint file, GLuint nr, GLuint subnr ) @@ -212,7 +225,7 @@ static INLINE struct brw_reg brw_vec4_reg( GLuint file, WRITEMASK_XYZW); } - +/** Construct float[2] register */ static INLINE struct brw_reg brw_vec2_reg( GLuint file, GLuint nr, GLuint subnr ) @@ -228,6 +241,7 @@ static INLINE struct brw_reg brw_vec2_reg( GLuint file, WRITEMASK_XY); } +/** Construct float[1] register */ static INLINE struct brw_reg brw_vec1_reg( GLuint file, GLuint nr, GLuint subnr ) @@ -277,6 +291,7 @@ static INLINE struct brw_reg byte_offset( struct brw_reg reg, } +/** Construct unsigned word[16] register */ static INLINE struct brw_reg brw_uw16_reg( GLuint file, GLuint nr, GLuint subnr ) @@ -284,6 +299,7 @@ static INLINE struct brw_reg brw_uw16_reg( GLuint file, return suboffset(retype(brw_vec16_reg(file, nr, 0), BRW_REGISTER_TYPE_UW), subnr); } +/** Construct unsigned word[8] register */ static INLINE struct brw_reg brw_uw8_reg( GLuint file, GLuint nr, GLuint subnr ) @@ -291,6 +307,7 @@ static INLINE struct brw_reg brw_uw8_reg( GLuint file, return suboffset(retype(brw_vec8_reg(file, nr, 0), BRW_REGISTER_TYPE_UW), subnr); } +/** Construct unsigned word[1] register */ static INLINE struct brw_reg brw_uw1_reg( GLuint file, GLuint nr, GLuint subnr ) @@ -311,6 +328,7 @@ static INLINE struct brw_reg brw_imm_reg( GLuint type ) 0); } +/** Construct float immediate register */ static INLINE struct brw_reg brw_imm_f( GLfloat f ) { struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_F); @@ -318,6 +336,7 @@ static INLINE struct brw_reg brw_imm_f( GLfloat f ) return imm; } +/** Construct integer immediate register */ static INLINE struct brw_reg brw_imm_d( GLint d ) { struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_D); @@ -325,6 +344,7 @@ static INLINE struct brw_reg brw_imm_d( GLint d ) return imm; } +/** Construct uint immediate register */ static INLINE struct brw_reg brw_imm_ud( GLuint ud ) { struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_UD); @@ -332,6 +352,7 @@ static INLINE struct brw_reg brw_imm_ud( GLuint ud ) return imm; } +/** Construct ushort immediate register */ static INLINE struct brw_reg brw_imm_uw( GLushort uw ) { struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_UW); @@ -339,6 +360,7 @@ static INLINE struct brw_reg brw_imm_uw( GLushort uw ) return imm; } +/** Construct short immediate register */ static INLINE struct brw_reg brw_imm_w( GLshort w ) { struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_W); @@ -350,8 +372,7 @@ static INLINE struct brw_reg brw_imm_w( GLshort w ) * numbers alias with _V and _VF below: */ -/* Vector of eight signed half-byte values: - */ +/** Construct vector of eight signed half-byte values */ static INLINE struct brw_reg brw_imm_v( GLuint v ) { struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_V); @@ -362,8 +383,7 @@ static INLINE struct brw_reg brw_imm_v( GLuint v ) return imm; } -/* Vector of four 8-bit float values: - */ +/** Construct vector of four 8-bit float values */ static INLINE struct brw_reg brw_imm_vf( GLuint v ) { struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_VF); @@ -400,44 +420,43 @@ static INLINE struct brw_reg brw_address( struct brw_reg reg ) return brw_imm_uw(reg.nr * REG_SIZE + reg.subnr); } - -static INLINE struct brw_reg brw_vec1_grf( GLuint nr, - GLuint subnr ) +/** Construct float[1] general-purpose register */ +static INLINE struct brw_reg brw_vec1_grf( GLuint nr, GLuint subnr ) { return brw_vec1_reg(BRW_GENERAL_REGISTER_FILE, nr, subnr); } -static INLINE struct brw_reg brw_vec8_grf( GLuint nr, - GLuint subnr ) +/** Construct float[2] general-purpose register */ +static INLINE struct brw_reg brw_vec2_grf( GLuint nr, GLuint subnr ) { - return brw_vec8_reg(BRW_GENERAL_REGISTER_FILE, nr, subnr); + return brw_vec2_reg(BRW_GENERAL_REGISTER_FILE, nr, subnr); } -static INLINE struct brw_reg brw_vec4_grf( GLuint nr, - GLuint subnr ) +/** Construct float[4] general-purpose register */ +static INLINE struct brw_reg brw_vec4_grf( GLuint nr, GLuint subnr ) { return brw_vec4_reg(BRW_GENERAL_REGISTER_FILE, nr, subnr); } - -static INLINE struct brw_reg brw_vec2_grf( GLuint nr, - GLuint subnr ) +/** Construct float[8] general-purpose register */ +static INLINE struct brw_reg brw_vec8_grf( GLuint nr, GLuint subnr ) { - return brw_vec2_reg(BRW_GENERAL_REGISTER_FILE, nr, subnr); + return brw_vec8_reg(BRW_GENERAL_REGISTER_FILE, nr, subnr); } -static INLINE struct brw_reg brw_uw8_grf( GLuint nr, - GLuint subnr ) + +static INLINE struct brw_reg brw_uw8_grf( GLuint nr, GLuint subnr ) { return brw_uw8_reg(BRW_GENERAL_REGISTER_FILE, nr, subnr); } -static INLINE struct brw_reg brw_uw16_grf( GLuint nr, - GLuint subnr ) +static INLINE struct brw_reg brw_uw16_grf( GLuint nr, GLuint subnr ) { return brw_uw16_reg(BRW_GENERAL_REGISTER_FILE, nr, subnr); } + +/** Construct null register (usually used for setting condition codes) */ static INLINE struct brw_reg brw_null_reg( void ) { return brw_vec8_reg(BRW_ARCHITECTURE_REGISTER_FILE, @@ -524,13 +543,13 @@ static INLINE struct brw_reg stride( struct brw_reg reg, GLuint width, GLuint hstride ) { - reg.vstride = cvt(vstride); reg.width = cvt(width) - 1; reg.hstride = cvt(hstride); return reg; } + static INLINE struct brw_reg vec16( struct brw_reg reg ) { return stride(reg, 16,16,1); @@ -556,6 +575,7 @@ static INLINE struct brw_reg vec1( struct brw_reg reg ) return stride(reg, 0,1,0); } + static INLINE struct brw_reg get_element( struct brw_reg reg, GLuint elt ) { return vec1(suboffset(reg, elt)); @@ -687,7 +707,7 @@ static INLINE struct brw_indirect brw_indirect( GLuint addr_subnr, GLint offset static INLINE struct brw_instruction *current_insn( struct brw_compile *p) { - return &p->store[p->nr_insn]; + return &p->store[p->nr_insn]; } void brw_pop_insn_state( struct brw_compile *p ); -- cgit v1.2.3 From 4a6ad999ea312f0af85de621c8b6a15a3d3b7ffd Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 1 Jan 2009 14:04:57 -0700 Subject: i965: increase number of texture samplers to 16 This lets GLSL shaders use up to 16 samplers. Fixed function is still limited to 8 textures. Tested with progs/glsl/samplers.c --- src/mesa/drivers/dri/i965/brw_context.c | 6 ++++-- src/mesa/drivers/dri/i965/brw_context.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'src/mesa') diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c index 1d6ac2cea6..a415e378ff 100644 --- a/src/mesa/drivers/dri/i965/brw_context.c +++ b/src/mesa/drivers/dri/i965/brw_context.c @@ -32,6 +32,7 @@ #include "main/imports.h" #include "main/api_noop.h" +#include "main/macros.h" #include "main/vtxfmt.h" #include "main/simple_list.h" #include "shader/shader_api.h" @@ -128,9 +129,10 @@ GLboolean brwCreateContext( const __GLcontextModes *mesaVis, TNL_CONTEXT(ctx)->Driver.RunPipeline = _tnl_run_pipeline; - ctx->Const.MaxTextureUnits = BRW_MAX_TEX_UNIT; ctx->Const.MaxTextureImageUnits = BRW_MAX_TEX_UNIT; - ctx->Const.MaxTextureCoordUnits = BRW_MAX_TEX_UNIT; + ctx->Const.MaxTextureCoordUnits = 8; /* Mesa limit */ + ctx->Const.MaxTextureUnits = MIN2(ctx->Const.MaxTextureCoordUnits, + ctx->Const.MaxTextureImageUnits); ctx->Const.MaxVertexTextureImageUnits = 0; /* no vertex shader textures */ /* Advertise the full hardware capabilities. The new memory diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h index 77980109cd..5d3f99e025 100644 --- a/src/mesa/drivers/dri/i965/brw_context.h +++ b/src/mesa/drivers/dri/i965/brw_context.h @@ -238,7 +238,7 @@ struct brw_vs_ouput_sizes { }; -#define BRW_MAX_TEX_UNIT 8 +#define BRW_MAX_TEX_UNIT 16 #define BRW_WM_MAX_SURF BRW_MAX_TEX_UNIT + MAX_DRAW_BUFFERS enum brw_cache_id { -- cgit v1.2.3 From 1fad6ccb756ae33ca3115f59c99ca8abbeb0321e Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 2 Jan 2009 12:26:15 -0700 Subject: mesa: fix another "out of samplers" problem Now only the samplers that are actually used by texture() functions are saved in the uniform variable list. Before, we could run out of samplers if too many were declared while only some of them were actually used. --- src/mesa/shader/prog_parameter.c | 3 +- src/mesa/shader/slang/slang_emit.c | 8 +++++- src/mesa/shader/slang/slang_link.c | 57 +++++++++++++++++++++++++++----------- 3 files changed, 50 insertions(+), 18 deletions(-) (limited to 'src/mesa') diff --git a/src/mesa/shader/prog_parameter.c b/src/mesa/shader/prog_parameter.c index c0602ad2c9..dc48e84ab2 100644 --- a/src/mesa/shader/prog_parameter.c +++ b/src/mesa/shader/prog_parameter.c @@ -290,7 +290,8 @@ _mesa_use_uniform(struct gl_program_parameter_list *paramList, GLuint i; for (i = 0; i < paramList->NumParameters; i++) { struct gl_program_parameter *p = paramList->Parameters + i; - if (p->Type == PROGRAM_UNIFORM && _mesa_strcmp(p->Name, name) == 0) { + if ((p->Type == PROGRAM_UNIFORM || p->Type == PROGRAM_SAMPLER) && + _mesa_strcmp(p->Name, name) == 0) { p->Used = GL_TRUE; /* Note that large uniforms may occupy several slots so we're * not done searching yet. diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c index 500112b6f6..b7a3cfb617 100644 --- a/src/mesa/shader/slang/slang_emit.c +++ b/src/mesa/shader/slang/slang_emit.c @@ -1290,6 +1290,7 @@ emit_tex(slang_emit_info *emitInfo, slang_ir_node *n) /* Child[0] is the sampler (a uniform which'll indicate the texture unit) */ assert(n->Children[0]->Store); + assert(n->Children[0]->Store->File == PROGRAM_SAMPLER); /* Store->Index is the sampler index */ assert(n->Children[0]->Store->Index >= 0); /* Store->Size is the texture target */ @@ -1299,6 +1300,10 @@ emit_tex(slang_emit_info *emitInfo, slang_ir_node *n) inst->TexSrcTarget = n->Children[0]->Store->Size; inst->TexSrcUnit = n->Children[0]->Store->Index; /* i.e. uniform's index */ + /* mark the sampler as being used */ + _mesa_use_uniform(emitInfo->prog->Parameters, + (char *) n->Children[0]->Var->a_name); + return inst; } @@ -2104,7 +2109,8 @@ emit_var_ref(slang_emit_info *emitInfo, slang_ir_node *n) n->Store->Index = index; } - else if (n->Store->File == PROGRAM_UNIFORM) { + else if (n->Store->File == PROGRAM_UNIFORM || + n->Store->File == PROGRAM_SAMPLER) { /* mark var as used */ _mesa_use_uniform(emitInfo->prog->Parameters, (char *) n->Var->a_name); } diff --git a/src/mesa/shader/slang/slang_link.c b/src/mesa/shader/slang/slang_link.c index b49fd0e99d..b2fd9554a6 100644 --- a/src/mesa/shader/slang/slang_link.c +++ b/src/mesa/shader/slang/slang_link.c @@ -1,8 +1,9 @@ /* * Mesa 3-D graphics library - * Version: 7.2 + * Version: 7.3 * * Copyright (C) 2008 Brian Paul All Rights Reserved. + * Copyright (C) 2009 VMware, Inc. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -206,6 +207,19 @@ link_varying_vars(struct gl_shader_program *shProg, struct gl_program *prog) * Build the shProg->Uniforms list. * This is basically a list/index of all uniforms found in either/both of * the vertex and fragment shaders. + * + * About uniforms: + * Each uniform has two indexes, one that points into the vertex + * program's parameter array and another that points into the fragment + * program's parameter array. When the user changes a uniform's value + * we have to change the value in the vertex and/or fragment program's + * parameter array. + * + * This function will be called twice to set up the two uniform->parameter + * mappings. + * + * If a uniform is only present in the vertex program OR fragment program + * then the fragment/vertex parameter index, respectively, will be -1. */ static GLboolean link_uniform_vars(GLcontext *ctx, @@ -213,7 +227,7 @@ link_uniform_vars(GLcontext *ctx, struct gl_program *prog, GLuint *numSamplers) { - GLuint samplerMap[MAX_SAMPLERS]; + GLuint samplerMap[200]; /* max number of samplers declared, not used */ GLuint i; for (i = 0; i < prog->Parameters->NumParameters; i++) { @@ -228,33 +242,41 @@ link_uniform_vars(GLcontext *ctx, * Furthermore, we'll need to fix the state-var's size/datatype info. */ - if ((p->Type == PROGRAM_UNIFORM && p->Used) || - p->Type == PROGRAM_SAMPLER) { + if ((p->Type == PROGRAM_UNIFORM || p->Type == PROGRAM_SAMPLER) + && p->Used) { + /* add this uniform, indexing into the target's Parameters list */ struct gl_uniform *uniform = _mesa_append_uniform(shProg->Uniforms, p->Name, prog->Target, i); if (uniform) uniform->Initialized = p->Initialized; } - if (p->Type == PROGRAM_SAMPLER) { + /* The samplerMap[] table we build here is used to remap/re-index + * sampler references by TEX instructions. + */ + if (p->Type == PROGRAM_SAMPLER && p->Used) { /* Allocate a new sampler index */ - GLuint sampNum = *numSamplers; GLuint oldSampNum = (GLuint) prog->Parameters->ParameterValues[i][0]; - if (oldSampNum >= ctx->Const.MaxTextureImageUnits) { + GLuint newSampNum = *numSamplers; + if (newSampNum >= ctx->Const.MaxTextureImageUnits) { char s[100]; sprintf(s, "Too many texture samplers (%u, max is %u)", - oldSampNum + 1, ctx->Const.MaxTextureImageUnits); + newSampNum, ctx->Const.MaxTextureImageUnits); link_error(shProg, s); return GL_FALSE; } - samplerMap[oldSampNum] = sampNum; + /* save old->new mapping in the table */ + if (oldSampNum < Elements(samplerMap)) + samplerMap[oldSampNum] = newSampNum; + /* update parameter's sampler index */ + prog->Parameters->ParameterValues[i][0] = (GLfloat) newSampNum; (*numSamplers)++; } } - - /* OK, now scan the program/shader instructions looking for sampler vars, - * replacing the old index with the new index. + /* OK, now scan the program/shader instructions looking for texture + * instructions using sampler vars. Replace old sampler indexes with + * new ones. */ prog->SamplersUsed = 0x0; for (i = 0; i < prog->NumInstructions; i++) { @@ -265,10 +287,13 @@ link_uniform_vars(GLcontext *ctx, inst->Sampler, map[ inst->Sampler ]); */ /* here, texUnit is really samplerUnit */ - assert(inst->TexSrcUnit < MAX_SAMPLERS); - inst->TexSrcUnit = samplerMap[inst->TexSrcUnit]; - prog->SamplerTargets[inst->TexSrcUnit] = inst->TexSrcTarget; - prog->SamplersUsed |= (1 << inst->TexSrcUnit); + const GLint oldSampNum = inst->TexSrcUnit; + if (oldSampNum < Elements(samplerMap)) { + const GLuint newSampNum = samplerMap[oldSampNum]; + inst->TexSrcUnit = newSampNum; + prog->SamplerTargets[newSampNum] = inst->TexSrcTarget; + prog->SamplersUsed |= (1 << newSampNum); + } } } -- cgit v1.2.3