diff options
author | Alan Hourihane <[email protected]> | 2009-01-14 23:33:41 +0000 |
---|---|---|
committer | Alan Hourihane <[email protected]> | 2009-01-14 23:33:41 +0000 |
commit | 658b1bdb1cc5f9910be910dc156a2e81ed999756 (patch) | |
tree | 98d15bcf83b662dd8c7186dd423e3d8ebbd87f1c /src | |
parent | e82784559e00cb534993c01309ad1832e9b3e56b (diff) | |
parent | 03188b09e071ace9d9e21ccc56c01e90c0fa8639 (diff) |
Merge commit 'origin/master' into gallium-0.2
Conflicts:
docs/install.html
docs/relnotes-7.3.html
src/mesa/shader/slang/slang_codegen.c
src/mesa/shader/slang/slang_compile.c
src/mesa/shader/slang/slang_emit.c
src/mesa/shader/slang/slang_preprocess.c
src/mesa/shader/slang/slang_preprocess.h
Diffstat (limited to 'src')
48 files changed, 1255 insertions, 173 deletions
diff --git a/src/glx/x11/drisw_glx.c b/src/glx/x11/drisw_glx.c index fee45952b38..35bbd9151ca 100644 --- a/src/glx/x11/drisw_glx.c +++ b/src/glx/x11/drisw_glx.c @@ -113,7 +113,7 @@ swrastGetDrawableInfo(__DRIdrawable * draw, int *x, int *y, int *w, int *h, void *loaderPrivate) { __GLXDRIdrawablePrivate *pdp = loaderPrivate; - __GLXDRIdrawable *pdraw = &(pdp->base);; + __GLXDRIdrawable *pdraw = &(pdp->base); Display *dpy = pdraw->psc->dpy; Drawable drawable; @@ -141,7 +141,7 @@ swrastPutImage(__DRIdrawable * draw, int op, int x, int y, int w, int h, char *data, void *loaderPrivate) { __GLXDRIdrawablePrivate *pdp = loaderPrivate; - __GLXDRIdrawable *pdraw = &(pdp->base);; + __GLXDRIdrawable *pdraw = &(pdp->base); Display *dpy = pdraw->psc->dpy; Drawable drawable; XImage *ximage; @@ -176,7 +176,7 @@ swrastGetImage(__DRIdrawable * draw, int x, int y, int w, int h, char *data, void *loaderPrivate) { __GLXDRIdrawablePrivate *pdp = loaderPrivate; - __GLXDRIdrawable *pdraw = &(pdp->base);; + __GLXDRIdrawable *pdraw = &(pdp->base); Display *dpy = pdraw->psc->dpy; Drawable drawable; XImage *ximage; diff --git a/src/glx/x11/glx_pbuffer.c b/src/glx/x11/glx_pbuffer.c index c63d53439d5..a602cd28817 100644 --- a/src/glx/x11/glx_pbuffer.c +++ b/src/glx/x11/glx_pbuffer.c @@ -220,14 +220,14 @@ GetDrawableAttribute(Display * dpy, GLXDrawable drawable, unsigned int length; unsigned int i; unsigned int num_attributes; + GLboolean use_glx_1_3; if ((dpy == NULL) || (drawable == 0)) { return 0; } priv = __glXInitialize(dpy); - GLboolean use_glx_1_3 = ((priv->majorVersion > 1) - || (priv->minorVersion >= 3)); + use_glx_1_3 = ((priv->majorVersion > 1) || (priv->minorVersion >= 3)); *value = 0; diff --git a/src/glx/x11/glxcurrent.c b/src/glx/x11/glxcurrent.c index f3eb045d9f9..5af46cf0ba7 100644 --- a/src/glx/x11/glxcurrent.c +++ b/src/glx/x11/glxcurrent.c @@ -365,7 +365,7 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw, const CARD8 oldOpcode = ((gc == oldGC) || (oldGC == &dummyContext)) ? opcode : __glXSetupForCommand(oldGC->currentDpy); Bool bindReturnValue; - + __GLXattribute *state; if (!opcode || !oldOpcode) { return GL_FALSE; @@ -489,8 +489,7 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw, } while (0); #endif - __GLXattribute *state = - (__GLXattribute *) (gc->client_state_private); + state = (__GLXattribute *) (gc->client_state_private); gc->currentContextTag = reply.contextTag; if (state->array_state == NULL) { diff --git a/src/mesa/drivers/allegro/amesa.c b/src/mesa/drivers/allegro/amesa.c index ade62518489..a9d8f62f92d 100644 --- a/src/mesa/drivers/allegro/amesa.c +++ b/src/mesa/drivers/allegro/amesa.c @@ -26,7 +26,7 @@ #include "main/imports.h" #include "main/matrix.h" #include "main/mtypes.h" -#include "GL/amesa.h" +#include "amesa.h" struct amesa_visual diff --git a/src/mesa/drivers/allegro/amesa.h b/src/mesa/drivers/allegro/amesa.h new file mode 100644 index 00000000000..852d34cf4f5 --- /dev/null +++ b/src/mesa/drivers/allegro/amesa.h @@ -0,0 +1,65 @@ +/* + * Mesa 3-D graphics library + * Version: 3.3 + * + * Copyright (C) 1999-2000 Brian Paul 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +/* Allegro (DJGPP) driver by Bernhard Tschirren ([email protected]) */ + + +#ifndef AMESA_H +#define AMESA_H + + +#define AMESA_MAJOR_VERSION 3 +#define AMESA_MINOR_VERSION 3 + + +typedef struct amesa_visual *AMesaVisual; +typedef struct amesa_buffer *AMesaBuffer; +typedef struct amesa_context *AMesaContext; + + +extern AMesaVisual AMesaCreateVisual(GLboolean dbFlag, GLint depth, + GLint depthSize, + GLint stencilSize, + GLint accumSize); + +extern void AMesaDestroyVisual(AMesaVisual visual); + +extern AMesaBuffer AMesaCreateBuffer(AMesaVisual visual, + GLint width, GLint height); + +extern void AMesaDestroyBuffer(AMesaBuffer buffer); + + +extern AMesaContext AMesaCreateContext(AMesaVisual visual, + AMesaContext sharelist); + +extern void AMesaDestroyContext(AMesaContext context); + +extern GLboolean AMesaMakeCurrent(AMesaContext context, AMesaBuffer buffer); + +extern void AMesaSwapBuffers(AMesaBuffer buffer); + + +#endif /* AMESA_H */ diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c index a415e378fff..d7a2bd95ee2 100644 --- a/src/mesa/drivers/dri/i965/brw_context.c +++ b/src/mesa/drivers/dri/i965/brw_context.c @@ -143,6 +143,9 @@ GLboolean brwCreateContext( const __GLcontextModes *mesaVis, ctx->Const.MaxCubeTextureLevels = 12; ctx->Const.MaxTextureRectSize = (1<<11); + /* if conformance mode is set, swrast can handle any size AA point */ + ctx->Const.MaxPointSizeAA = 255.0; + /* ctx->Const.MaxNativeVertexProgramTemps = 32; */ brw_init_attribs( brw ); diff --git a/src/mesa/drivers/dri/i965/brw_program.c b/src/mesa/drivers/dri/i965/brw_program.c index a18dee85e80..0c86911044b 100644 --- a/src/mesa/drivers/dri/i965/brw_program.c +++ b/src/mesa/drivers/dri/i965/brw_program.c @@ -111,9 +111,15 @@ static void brwProgramStringNotify( GLcontext *ctx, struct gl_program *prog ) { if (target == GL_FRAGMENT_PROGRAM_ARB) { + struct gl_fragment_program *fprog = (struct gl_fragment_program *) prog; struct brw_context *brw = brw_context(ctx); struct brw_fragment_program *p = (struct brw_fragment_program *)prog; struct brw_fragment_program *fp = (struct brw_fragment_program *)brw->fragment_program; + if (fprog->FogOption) { + _mesa_append_fog_code(ctx, fprog); + fprog->FogOption = GL_NONE; + } + if (p == fp) brw->state.dirty.brw |= BRW_NEW_FRAGMENT_PROGRAM; p->id = brw->program_id++; diff --git a/src/mesa/drivers/dri/i965/brw_sf.c b/src/mesa/drivers/dri/i965/brw_sf.c index 9dce6cd8e6c..1a11d546210 100644 --- a/src/mesa/drivers/dri/i965/brw_sf.c +++ b/src/mesa/drivers/dri/i965/brw_sf.c @@ -73,10 +73,12 @@ static void compile_sf_prog( struct brw_context *brw, c.attr_to_idx[i] = idx; c.idx_to_attr[idx] = i; if (i >= VERT_RESULT_TEX0 && i <= VERT_RESULT_TEX7) { - c.point_attrs[i].CoordReplace = - brw->attribs.Point->CoordReplace[i - VERT_RESULT_TEX0]; - } else - c.point_attrs[i].CoordReplace = GL_FALSE; + c.point_attrs[i].CoordReplace = + brw->attribs.Point->CoordReplace[i - VERT_RESULT_TEX0]; + } + else { + c.point_attrs[i].CoordReplace = GL_FALSE; + } idx++; } @@ -106,7 +108,6 @@ static void compile_sf_prog( struct brw_context *brw, assert(0); return; } - /* get the program */ diff --git a/src/mesa/drivers/dri/i965/brw_sf_state.c b/src/mesa/drivers/dri/i965/brw_sf_state.c index 506126fcfb0..741a7c53c47 100644 --- a/src/mesa/drivers/dri/i965/brw_sf_state.c +++ b/src/mesa/drivers/dri/i965/brw_sf_state.c @@ -229,7 +229,7 @@ sf_unit_create_from_key(struct brw_context *brw, struct brw_sf_unit_key *key, /* XXX clamp max depends on AA vs. non-AA */ sf.sf7.sprite_point = key->point_sprite; - sf.sf7.point_size = CLAMP(nearbyint(key->point_size), 1, 255) * (1<<3); + sf.sf7.point_size = CLAMP(rint(key->point_size), 1, 255) * (1<<3); sf.sf7.use_point_size_state = !key->point_attenuated; sf.sf7.aa_line_distance_mode = 0; diff --git a/src/mesa/drivers/dri/i965/brw_wm_fp.c b/src/mesa/drivers/dri/i965/brw_wm_fp.c index f4583877aa5..1a00b698256 100644 --- a/src/mesa/drivers/dri/i965/brw_wm_fp.c +++ b/src/mesa/drivers/dri/i965/brw_wm_fp.c @@ -811,57 +811,6 @@ static void precalc_txp( struct brw_wm_compile *c, - - -/*********************************************************************** - * Add instructions to perform fog blending - */ - -static void fog_blend( struct brw_wm_compile *c, - struct prog_src_register fog_factor ) -{ - struct prog_dst_register outcolor = dst_reg(PROGRAM_OUTPUT, FRAG_RESULT_COLR); - struct prog_src_register fogcolor = search_or_add_param5( c, STATE_FOG_COLOR, 0,0,0,0 ); - - /* color.xyz = LRP fog_factor.xxxx, output_color, fog_color */ - - emit_op(c, - OPCODE_LRP, - dst_mask(outcolor, WRITEMASK_XYZ), - 0, 0, 0, - fog_factor, - src_reg_from_dst(outcolor), - fogcolor); -} - - - -/* This one is simple - just take the interpolated fog coordinate and - * use it as the fog blend factor. - */ -static void fog_interpolated( struct brw_wm_compile *c ) -{ - struct prog_src_register fogc = src_reg(PROGRAM_INPUT, FRAG_ATTRIB_FOGC); - - if (!(c->fp_interp_emitted & (1<<FRAG_ATTRIB_FOGC))) - emit_interp(c, FRAG_ATTRIB_FOGC); - - fog_blend( c, src_swizzle1(fogc, GET_SWZ(fogc.Swizzle,X))); -} - -static void emit_fog( struct brw_wm_compile *c ) -{ - if (!c->fp->program.FogOption) - return; - - if (1) - fog_interpolated( c ); - else { - /* TODO: per-pixel fog */ - assert(0); - } -} - static void emit_fb_write( struct brw_wm_compile *c ) { struct prog_src_register payload_r0_depth = src_reg(PROGRAM_PAYLOAD, PAYLOAD_DEPTH); @@ -1059,7 +1008,6 @@ void brw_wm_pass_fp( struct brw_wm_compile *c ) emit_ddy(c, inst); break; case OPCODE_END: - emit_fog(c); emit_fb_write(c); break; case OPCODE_PRINT: diff --git a/src/mesa/drivers/dri/i965/brw_wm_glsl.c b/src/mesa/drivers/dri/i965/brw_wm_glsl.c index 942ebe1ed4e..8fd776ac393 100644 --- a/src/mesa/drivers/dri/i965/brw_wm_glsl.c +++ b/src/mesa/drivers/dri/i965/brw_wm_glsl.c @@ -892,15 +892,19 @@ static void emit_lrp(struct brw_wm_compile *c, } } +/** + * For GLSL shaders, this KIL will be unconditional. + * It may be contained inside an IF/ENDIF structure of course. + */ static void emit_kil(struct brw_wm_compile *c) { - struct brw_compile *p = &c->func; - struct brw_reg depth = retype(brw_vec1_grf(0, 0), BRW_REGISTER_TYPE_UW); - brw_push_insn_state(p); - brw_set_mask_control(p, BRW_MASK_DISABLE); - brw_NOT(p, c->emit_mask_reg, brw_mask_reg(1)); //IMASK - brw_AND(p, depth, c->emit_mask_reg, depth); - brw_pop_insn_state(p); + struct brw_compile *p = &c->func; + struct brw_reg depth = retype(brw_vec1_grf(0, 0), BRW_REGISTER_TYPE_UW); + brw_push_insn_state(p); + brw_set_mask_control(p, BRW_MASK_DISABLE); + brw_NOT(p, c->emit_mask_reg, brw_mask_reg(1)); //IMASK + brw_AND(p, depth, c->emit_mask_reg, depth); + brw_pop_insn_state(p); } static void emit_mad(struct brw_wm_compile *c, diff --git a/src/mesa/drivers/dri/i965/brw_wm_sampler_state.c b/src/mesa/drivers/dri/i965/brw_wm_sampler_state.c index f12ef47a7d7..8c9cb789453 100644 --- a/src/mesa/drivers/dri/i965/brw_wm_sampler_state.c +++ b/src/mesa/drivers/dri/i965/brw_wm_sampler_state.c @@ -244,7 +244,7 @@ brw_wm_sampler_populate_key(struct brw_context *brw, entry->minfilter = texObj->MinFilter; entry->magfilter = texObj->MagFilter; entry->comparemode = texObj->CompareMode; - entry->comparefunc = texObj->CompareFunc; + entry->comparefunc = texObj->CompareFunc; dri_bo_unreference(brw->wm.sdc_bo[unit]); if (firstImage->_BaseFormat == GL_DEPTH_COMPONENT) { diff --git a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c index 63e14cc3900..06e71e6d694 100644 --- a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c +++ b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c @@ -192,21 +192,27 @@ brw_create_texture_surface( struct brw_context *brw, if (key->bo) surf.ss0.surface_format = translate_tex_format(key->format, key->depthmode); else { - switch(key->depth) { - case 32: surf.ss0.surface_format = BRW_SURFACEFORMAT_B8G8R8A8_UNORM; break; - default: - case 24: surf.ss0.surface_format = BRW_SURFACEFORMAT_B8G8R8X8_UNORM; break; - case 16: surf.ss0.surface_format = BRW_SURFACEFORMAT_B5G6R5_UNORM; break; - } + switch (key->depth) { + case 32: + surf.ss0.surface_format = BRW_SURFACEFORMAT_B8G8R8A8_UNORM; + break; + default: + case 24: + surf.ss0.surface_format = BRW_SURFACEFORMAT_B8G8R8X8_UNORM; + break; + case 16: + surf.ss0.surface_format = BRW_SURFACEFORMAT_B5G6R5_UNORM; + break; + } } /* This is ok for all textures with channel width 8bit or less: */ /* surf.ss0.data_return_format = BRW_SURFACERETURNFORMAT_S1; */ if (key->bo) - surf.ss1.base_addr = key->bo->offset; /* reloc */ + surf.ss1.base_addr = key->bo->offset; /* reloc */ else - surf.ss1.base_addr = key->offset; + surf.ss1.base_addr = key->offset; surf.ss2.mip_count = key->last_level - key->first_level; surf.ss2.width = key->width - 1; diff --git a/src/mesa/drivers/dri/intel/intel_context.c b/src/mesa/drivers/dri/intel/intel_context.c index 44b276a123e..7b7f7d8c145 100644 --- a/src/mesa/drivers/dri/intel/intel_context.c +++ b/src/mesa/drivers/dri/intel/intel_context.c @@ -95,7 +95,7 @@ int INTEL_DEBUG = (0); #include "extension_helper.h" -#define DRIVER_DATE "20080716" +#define DRIVER_DATE "20090114" #define DRIVER_DATE_GEM "GEM " DRIVER_DATE static const GLubyte * diff --git a/src/mesa/drivers/dri/intel/intel_pixel_bitmap.c b/src/mesa/drivers/dri/intel/intel_pixel_bitmap.c index 1d7f15f10a5..3a01f63dc72 100644 --- a/src/mesa/drivers/dri/intel/intel_pixel_bitmap.c +++ b/src/mesa/drivers/dri/intel/intel_pixel_bitmap.c @@ -204,6 +204,14 @@ do_blit_bitmap( GLcontext *ctx, /* Update draw buffer bounds */ _mesa_update_state(ctx); + if (ctx->Depth.Test) { + /* The blit path produces incorrect results when depth testing is on. + * It seems the blit Z coord is always 1.0 (the far plane) so fragments + * will likely be obscured by other, closer geometry. + */ + return GL_FALSE; + } + if (!dst) return GL_FALSE; @@ -357,6 +365,7 @@ intel_texture_bitmap(GLcontext * ctx, GLubyte *unpacked_bitmap; GLubyte *a8_bitmap; int x, y; + GLfloat dst_z; /* We need a fragment program for the KIL effect */ if (!ctx->Extensions.ARB_fragment_program || @@ -456,21 +465,24 @@ intel_texture_bitmap(GLcontext * ctx, intel_meta_set_passthrough_vertex_program(intel); intel_meta_set_passthrough_transform(intel); + /* convert rasterpos Z from [0,1] to NDC coord in [-1,1] */ + dst_z = -1.0 + 2.0 * ctx->Current.RasterPos[2]; + vertices[0][0] = dst_x; vertices[0][1] = dst_y; - vertices[0][2] = ctx->Current.RasterPos[2]; + vertices[0][2] = dst_z; 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][2] = dst_z; 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][2] = dst_z; 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][2] = dst_z; vertices[3][3] = 1.0; texcoords[0][0] = 0.0; diff --git a/src/mesa/drivers/dri/intel/intel_pixel_draw.c b/src/mesa/drivers/dri/intel/intel_pixel_draw.c index 2af839b8031..0e83afa6451 100644 --- a/src/mesa/drivers/dri/intel/intel_pixel_draw.c +++ b/src/mesa/drivers/dri/intel/intel_pixel_draw.c @@ -71,6 +71,7 @@ intel_texture_drawpixels(GLcontext * ctx, GLuint texname; GLfloat vertices[4][4]; GLfloat texcoords[4][2]; + GLfloat z; /* 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. @@ -140,6 +141,9 @@ intel_texture_drawpixels(GLcontext * ctx, intel_meta_set_passthrough_transform(intel); + /* convert rasterpos Z from [0,1] to NDC coord in [-1,1] */ + z = -1.0 + 2.0 * ctx->Current.RasterPos[2]; + /* 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. * We also apply the depth. However, the W component is already multiplied @@ -147,19 +151,19 @@ intel_texture_drawpixels(GLcontext * ctx, */ vertices[0][0] = x; vertices[0][1] = y; - vertices[0][2] = ctx->Current.RasterPos[2]; + vertices[0][2] = z; vertices[0][3] = 1.0; vertices[1][0] = x + width * ctx->Pixel.ZoomX; vertices[1][1] = y; - vertices[1][2] = ctx->Current.RasterPos[2]; + vertices[1][2] = z; vertices[1][3] = 1.0; vertices[2][0] = x + width * ctx->Pixel.ZoomX; vertices[2][1] = y + height * ctx->Pixel.ZoomY; - vertices[2][2] = ctx->Current.RasterPos[2]; + vertices[2][2] = z; vertices[2][3] = 1.0; vertices[3][0] = x; vertices[3][1] = y + height * ctx->Pixel.ZoomY; - vertices[3][2] = ctx->Current.RasterPos[2]; + vertices[3][2] = z; vertices[3][3] = 1.0; texcoords[0][0] = 0.0; diff --git a/src/mesa/drivers/dri/intel/intel_span.c b/src/mesa/drivers/dri/intel/intel_span.c index 8f4e681ffea..d9315043e6e 100644 --- a/src/mesa/drivers/dri/intel/intel_span.c +++ b/src/mesa/drivers/dri/intel/intel_span.c @@ -633,7 +633,7 @@ intelSpanRenderStart(GLcontext * ctx) intelFlush(&intel->ctx); LOCK_HARDWARE(intel); - for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) { + for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) { if (ctx->Texture.Unit[i]._ReallyEnabled) { struct gl_texture_object *texObj = ctx->Texture.Unit[i]._Current; intel_tex_map_images(intel, intel_texture_object(texObj)); @@ -655,7 +655,7 @@ intelSpanRenderFinish(GLcontext * ctx) _swrast_flush(ctx); - for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) { + for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) { if (ctx->Texture.Unit[i]._ReallyEnabled) { struct gl_texture_object *texObj = ctx->Texture.Unit[i]._Current; intel_tex_unmap_images(intel, intel_texture_object(texObj)); diff --git a/src/mesa/drivers/dri/mach64/mach64_context.h b/src/mesa/drivers/dri/mach64/mach64_context.h index 55e0618ff80..854751626d0 100644 --- a/src/mesa/drivers/dri/mach64/mach64_context.h +++ b/src/mesa/drivers/dri/mach64/mach64_context.h @@ -294,7 +294,13 @@ extern GLboolean mach64UnbindContext( __DRIcontextPrivate *driContextPriv ); #define LE32_OUT( x, y ) do { *(GLuint *)(x) = (y); } while (0) #define LE32_OUT_FLOAT( x, y ) do { *(GLfloat *)(x) = (y); } while (0) #else +#ifndef __OpenBSD__ #include <byteswap.h> +#else +#include <machine/endian.h> +#define bswap_32 bswap32 +#endif + #define LE32_IN( x ) bswap_32( *(GLuint *)(x) ) #define LE32_IN_FLOAT( x ) \ ({ \ diff --git a/src/mesa/drivers/dri/swrast/swrast.c b/src/mesa/drivers/dri/swrast/swrast.c index 49f1b8b9ee7..15b57244dcd 100644 --- a/src/mesa/drivers/dri/swrast/swrast.c +++ b/src/mesa/drivers/dri/swrast/swrast.c @@ -66,6 +66,7 @@ #define need_GL_ARB_vertex_program #define need_GL_APPLE_vertex_array_object #define need_GL_ATI_fragment_shader +#define need_GL_ATI_separate_stencil #define need_GL_EXT_depth_bounds_test #define need_GL_EXT_framebuffer_object #define need_GL_EXT_framebuffer_blit @@ -96,6 +97,7 @@ const struct dri_extension card_extensions[] = { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions }, { "GL_APPLE_vertex_array_object", GL_APPLE_vertex_array_object_functions }, { "GL_ATI_fragment_shader", GL_ATI_fragment_shader_functions }, + { "GL_ATI_separate_stencil", GL_ATI_separate_stencil_functions }, { "GL_EXT_depth_bounds_test", GL_EXT_depth_bounds_test_functions }, { "GL_EXT_framebuffer_object", GL_EXT_framebuffer_object_functions }, { "GL_EXT_framebuffer_blit", GL_EXT_framebuffer_blit_functions }, diff --git a/src/mesa/drivers/windows/gdi/wgl.c b/src/mesa/drivers/windows/gdi/wgl.c index 9f0bb9122a9..8d8087067f5 100644 --- a/src/mesa/drivers/windows/gdi/wgl.c +++ b/src/mesa/drivers/windows/gdi/wgl.c @@ -601,8 +601,9 @@ WINGDIAPI BOOL GLAPIENTRY wglCopyContext(HGLRC hglrcSrc, WINGDIAPI HGLRC GLAPIENTRY wglCreateLayerContext(HDC hdc, int iLayerPlane) { - (void) hdc; (void) iLayerPlane; SetLastError(0); + if (iLayerPlane == 0) + return wglCreateContext( hdc ); return(NULL); } diff --git a/src/mesa/drivers/x11/fakeglx.c b/src/mesa/drivers/x11/fakeglx.c index 827d39f9957..ea3585258d8 100644 --- a/src/mesa/drivers/x11/fakeglx.c +++ b/src/mesa/drivers/x11/fakeglx.c @@ -42,7 +42,6 @@ #include "glxheader.h" #include "glxapi.h" -#include "GL/xmesa.h" #include "main/context.h" #include "main/config.h" #include "main/macros.h" diff --git a/src/mesa/drivers/x11/fxmesa.h b/src/mesa/drivers/x11/fxmesa.h new file mode 100644 index 00000000000..f8e9661f9cc --- /dev/null +++ b/src/mesa/drivers/x11/fxmesa.h @@ -0,0 +1,103 @@ +/* + * Mesa 3-D graphics library + * Version: 4.0 + * Copyright (C) 1995-2001 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +/* + * FXMesa - 3Dfx Glide driver for Mesa. Contributed by David Bucciarelli + * + * NOTE: This version requires Glide3 (http://sourceforge.net/projects/glide) + */ + + +#ifndef FXMESA_H +#define FXMESA_H + + +#include <glide.h> + + +#ifdef __cplusplus +extern "C" { +#endif + + +#define FXMESA_MAJOR_VERSION 6 +#define FXMESA_MINOR_VERSION 3 + + +/* + * Values for attribList parameter to fxMesaCreateContext(): + */ +#define FXMESA_NONE 0 /* to terminate attribList */ +#define FXMESA_DOUBLEBUFFER 10 +#define FXMESA_ALPHA_SIZE 11 /* followed by an integer */ +#define FXMESA_DEPTH_SIZE 12 /* followed by an integer */ +#define FXMESA_STENCIL_SIZE 13 /* followed by an integer */ +#define FXMESA_ACCUM_SIZE 14 /* followed by an integer */ +#define FXMESA_COLORDEPTH 20 /* followed by an integer */ +#define FXMESA_SHARE_CONTEXT 990099 /* keep in sync with xmesa1.c! */ + + + +typedef struct tfxMesaContext *fxMesaContext; + + +#if defined (__BEOS__) +#pragma export on +#endif + + +GLAPI fxMesaContext GLAPIENTRY fxMesaCreateContext(GLuint win, GrScreenResolution_t, + GrScreenRefresh_t, + const GLint attribList[]); + +GLAPI fxMesaContext GLAPIENTRY fxMesaCreateBestContext(GLuint win, + GLint width, GLint height, + const GLint attribList[]); +GLAPI void GLAPIENTRY fxMesaDestroyContext(fxMesaContext ctx); + +GLAPI GLint GLAPIENTRY fxMesaSelectCurrentBoard(int n); + +GLAPI void GLAPIENTRY fxMesaMakeCurrent(fxMesaContext ctx); + +GLAPI fxMesaContext GLAPIENTRY fxMesaGetCurrentContext(void); + +GLAPI void GLAPIENTRY fxMesaSwapBuffers(void); + +GLAPI void GLAPIENTRY fxMesaSetNearFar(GLfloat nearVal, GLfloat farVal); + +GLAPI void GLAPIENTRY fxMesaUpdateScreenSize(fxMesaContext ctx); + +GLAPI void GLAPIENTRY fxCloseHardware(void); + +GLAPI void GLAPIENTRY fxGetScreenGeometry (GLint *w, GLint *h); + + +#if defined (__BEOS__) +#pragma export off +#endif + + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/src/mesa/drivers/x11/xm_api.c b/src/mesa/drivers/x11/xm_api.c index c9009bad031..18aa8bcc096 100644 --- a/src/mesa/drivers/x11/xm_api.c +++ b/src/mesa/drivers/x11/xm_api.c @@ -63,7 +63,6 @@ #endif #include "glxheader.h" -#include "GL/xmesa.h" #include "xmesaP.h" #include "main/context.h" #include "main/extensions.h" diff --git a/src/mesa/drivers/x11/xm_buffer.c b/src/mesa/drivers/x11/xm_buffer.c index f104d44d051..7ad67bc34da 100644 --- a/src/mesa/drivers/x11/xm_buffer.c +++ b/src/mesa/drivers/x11/xm_buffer.c @@ -30,7 +30,6 @@ #include "glxheader.h" -#include "GL/xmesa.h" #include "xmesaP.h" #include "main/imports.h" #include "main/framebuffer.h" diff --git a/src/mesa/drivers/x11/xmesa.h b/src/mesa/drivers/x11/xmesa.h new file mode 100644 index 00000000000..98139af8336 --- /dev/null +++ b/src/mesa/drivers/x11/xmesa.h @@ -0,0 +1,424 @@ +/* + * Mesa 3-D graphics library + * Version: 7.1 + * + * Copyright (C) 1999-2007 Brian Paul 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +/* + * Mesa/X11 interface. This header file serves as the documentation for + * the Mesa/X11 interface functions. + * + * Note: this interface isn't intended for user programs. It's primarily + * just for implementing the pseudo-GLX interface. + */ + + +/* Sample Usage: + +In addition to the usual X calls to select a visual, create a colormap +and create a window, you must do the following to use the X/Mesa interface: + +1. Call XMesaCreateVisual() to make an XMesaVisual from an XVisualInfo. + +2. Call XMesaCreateContext() to create an X/Mesa rendering context, given + the XMesaVisual. + +3. Call XMesaCreateWindowBuffer() to create an XMesaBuffer from an X window + and XMesaVisual. + +4. Call XMesaMakeCurrent() to bind the XMesaBuffer to an XMesaContext and + to make the context the current one. + +5. Make gl* calls to render your graphics. + +6. Use XMesaSwapBuffers() when double buffering to swap front/back buffers. + +7. Before the X window is destroyed, call XMesaDestroyBuffer(). + +8. Before exiting, call XMesaDestroyVisual and XMesaDestroyContext. + +*/ + + + + +#ifndef XMESA_H +#define XMESA_H + +#ifdef __VMS +#include <GL/vms_x_fix.h> +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef XFree86Server +#include "xmesa_xf86.h" +#else +#include <X11/Xlib.h> +#include <X11/Xutil.h> +#include "xmesa_x.h" +#endif +#include "GL/gl.h" + +#ifdef AMIWIN +#include <pragmas/xlib_pragmas.h> +extern struct Library *XLibBase; +#endif + + +#define XMESA_MAJOR_VERSION 6 +#define XMESA_MINOR_VERSION 3 + + + +/* + * Values passed to XMesaGetString: + */ +#define XMESA_VERSION 1 +#define XMESA_EXTENSIONS 2 + + +/* + * Values passed to XMesaSetFXmode: + */ +#define XMESA_FX_WINDOW 1 +#define XMESA_FX_FULLSCREEN 2 + + + +typedef struct xmesa_context *XMesaContext; + +typedef struct xmesa_visual *XMesaVisual; + +typedef struct xmesa_buffer *XMesaBuffer; + + + +/* + * Create a new X/Mesa visual. + * Input: display - X11 display + * visinfo - an XVisualInfo pointer + * rgb_flag - GL_TRUE = RGB mode, + * GL_FALSE = color index mode + * alpha_flag - alpha buffer requested? + * db_flag - GL_TRUE = double-buffered, + * GL_FALSE = single buffered + * stereo_flag - stereo visual? + * ximage_flag - GL_TRUE = use an XImage for back buffer, + * GL_FALSE = use an off-screen pixmap for back buffer + * depth_size - requested bits/depth values, or zero + * stencil_size - requested bits/stencil values, or zero + * accum_red_size - requested bits/red accum values, or zero + * accum_green_size - requested bits/green accum values, or zero + * accum_blue_size - requested bits/blue accum values, or zero + * accum_alpha_size - requested bits/alpha accum values, or zero + * num_samples - number of samples/pixel if multisampling, or zero + * level - visual level, usually 0 + * visualCaveat - ala the GLX extension, usually GLX_NONE_EXT + * Return; a new XMesaVisual or 0 if error. + */ +extern XMesaVisual XMesaCreateVisual( XMesaDisplay *display, + XMesaVisualInfo visinfo, + GLboolean rgb_flag, + GLboolean alpha_flag, + GLboolean db_flag, + GLboolean stereo_flag, + GLboolean ximage_flag, + GLint depth_size, + GLint stencil_size, + GLint accum_red_size, + GLint accum_green_size, + GLint accum_blue_size, + GLint accum_alpha_size, + GLint num_samples, + GLint level, + GLint visualCaveat ); + +/* + * Destroy an XMesaVisual, but not the associated XVisualInfo. + */ +extern void XMesaDestroyVisual( XMesaVisual v ); + + + +/* + * Create a new XMesaContext for rendering into an X11 window. + * + * Input: visual - an XMesaVisual + * share_list - another XMesaContext with which to share display + * lists or NULL if no sharing is wanted. + * Return: an XMesaContext or NULL if error. + */ +extern XMesaContext XMesaCreateContext( XMesaVisual v, + XMesaContext share_list ); + + +/* + * Destroy a rendering context as returned by XMesaCreateContext() + */ +extern void XMesaDestroyContext( XMesaContext c ); + + +#ifdef XFree86Server +/* + * These are the extra routines required for integration with XFree86. + * None of these routines should be user visible. -KEM + */ +extern GLboolean XMesaForceCurrent( XMesaContext c ); + +extern GLboolean XMesaLoseCurrent( XMesaContext c ); + +extern GLboolean XMesaCopyContext( XMesaContext src, + XMesaContext dst, + GLuint mask ); +#endif /* XFree86Server */ + + +/* + * Create an XMesaBuffer from an X window. + */ +extern XMesaBuffer XMesaCreateWindowBuffer( XMesaVisual v, XMesaWindow w ); + + +/* + * Create an XMesaBuffer from an X pixmap. + */ +extern XMesaBuffer XMesaCreatePixmapBuffer( XMesaVisual v, + XMesaPixmap p, + XMesaColormap cmap ); + + +/* + * Destroy an XMesaBuffer, but not the corresponding window or pixmap. + */ +extern void XMesaDestroyBuffer( XMesaBuffer b ); + + +/* + * Return the XMesaBuffer handle which corresponds to an X drawable, if any. + * + * New in Mesa 2.3. + */ +extern XMesaBuffer XMesaFindBuffer( XMesaDisplay *dpy, + XMesaDrawable d ); + + + +/* + * Bind a buffer to a context and make the context the current one. + */ +extern GLboolean XMesaMakeCurrent( XMesaContext c, + XMesaBuffer b ); + + +/* + * Bind two buffers (read and draw) to a context and make the + * context the current one. + * New in Mesa 3.3 + */ +extern GLboolean XMesaMakeCurrent2( XMesaContext c, + XMesaBuffer drawBuffer, + XMesaBuffer readBuffer ); + + +/* + * Unbind the current context from its buffer. + */ +extern GLboolean XMesaUnbindContext( XMesaContext c ); + + +/* + * Return a handle to the current context. + */ +extern XMesaContext XMesaGetCurrentContext( void ); + + +/* + * Return handle to the current (draw) buffer. + */ +extern XMesaBuffer XMesaGetCurrentBuffer( void ); + + +/* + * Return handle to the current read buffer. + * New in Mesa 3.3 + */ +extern XMesaBuffer XMesaGetCurrentReadBuffer( void ); + + +/* + * Swap the front and back buffers for the given buffer. No action is + * taken if the buffer is not double buffered. + */ +extern void XMesaSwapBuffers( XMesaBuffer b ); + + +/* + * Copy a sub-region of the back buffer to the front buffer. + * + * New in Mesa 2.6 + */ +extern void XMesaCopySubBuffer( XMesaBuffer b, + int x, + int y, + int width, + int height ); + + +/* + * Return a pointer to the the Pixmap or XImage being used as the back + * color buffer of an XMesaBuffer. This function is a way to get "under + * the hood" of X/Mesa so one can manipulate the back buffer directly. + * Input: b - the XMesaBuffer + * Output: pixmap - pointer to back buffer's Pixmap, or 0 + * ximage - pointer to back buffer's XImage, or NULL + * Return: GL_TRUE = context is double buffered + * GL_FALSE = context is single buffered + */ +extern GLboolean XMesaGetBackBuffer( XMesaBuffer b, + XMesaPixmap *pixmap, + XMesaImage **ximage ); + + + +/* + * Return the depth buffer associated with an XMesaBuffer. + * Input: b - the XMesa buffer handle + * Output: width, height - size of buffer in pixels + * bytesPerValue - bytes per depth value (2 or 4) + * buffer - pointer to depth buffer values + * Return: GL_TRUE or GL_FALSE to indicate success or failure. + * + * New in Mesa 2.4. + */ +extern GLboolean XMesaGetDepthBuffer( XMesaBuffer b, + GLint *width, + GLint *height, + GLint *bytesPerValue, + void **buffer ); + + + +/* + * Flush/sync a context + */ +extern void XMesaFlush( XMesaContext c ); + + + +/* + * Get an X/Mesa-specific string. + * Input: name - either XMESA_VERSION or XMESA_EXTENSIONS + */ +extern const char *XMesaGetString( XMesaContext c, int name ); + + + +/* + * Scan for XMesaBuffers whose window/pixmap has been destroyed, then free + * any memory used by that buffer. + * + * New in Mesa 2.3. + */ +extern void XMesaGarbageCollect( void ); + + + +/* + * Return a dithered pixel value. + * Input: c - XMesaContext + * x, y - window coordinate + * red, green, blue, alpha - color components in [0,1] + * Return: pixel value + * + * New in Mesa 2.3. + */ +extern unsigned long XMesaDitherColor( XMesaContext xmesa, + GLint x, + GLint y, + GLfloat red, + GLfloat green, + GLfloat blue, + GLfloat alpha ); + + + +/* + * 3Dfx Glide driver only! + * Set 3Dfx/Glide full-screen or window rendering mode. + * Input: mode - either XMESA_FX_WINDOW (window rendering mode) or + * XMESA_FX_FULLSCREEN (full-screen rendering mode) + * Return: GL_TRUE if success + * GL_FALSE if invalid mode or if not using 3Dfx driver + * + * New in Mesa 2.6. + */ +extern GLboolean XMesaSetFXmode( GLint mode ); + + + +/* + * Reallocate the back/depth/stencil/accum/etc/ buffers associated with + * buffer <b> if its size has changed. + * + * New in Mesa 4.0.2 + */ +extern void XMesaResizeBuffers( XMesaBuffer b ); + + + +/* + * Create a pbuffer. + * New in Mesa 4.1 + */ +extern XMesaBuffer XMesaCreatePBuffer(XMesaVisual v, XMesaColormap cmap, + unsigned int width, unsigned int height); + + + +/* + * Texture from Pixmap + * New in Mesa 7.1 + */ +extern void +XMesaBindTexImage(XMesaDisplay *dpy, XMesaBuffer drawable, int buffer, + const int *attrib_list); + +extern void +XMesaReleaseTexImage(XMesaDisplay *dpy, XMesaBuffer drawable, int buffer); + + +extern XMesaBuffer +XMesaCreatePixmapTextureBuffer(XMesaVisual v, XMesaPixmap p, + XMesaColormap cmap, + int format, int target, int mipmap); + + + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/src/mesa/drivers/x11/xmesaP.h b/src/mesa/drivers/x11/xmesaP.h index 98867ac7106..65e747d7b9d 100644 --- a/src/mesa/drivers/x11/xmesaP.h +++ b/src/mesa/drivers/x11/xmesaP.h @@ -27,10 +27,10 @@ #define XMESAP_H -#include "GL/xmesa.h" +#include "xmesa.h" #include "main/mtypes.h" #if defined(FX) -#include "GL/fxmesa.h" +#include "fxmesa.h" #include "xm_glide.h" #endif #ifdef XFree86Server diff --git a/src/mesa/drivers/x11/xmesa_x.h b/src/mesa/drivers/x11/xmesa_x.h new file mode 100644 index 00000000000..865bab4313b --- /dev/null +++ b/src/mesa/drivers/x11/xmesa_x.h @@ -0,0 +1,86 @@ + +/************************************************************************** + +Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. +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"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sub license, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice (including the +next paragraph) shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. +IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +**************************************************************************/ + +/* + * Authors: + * Kevin E. Martin <[email protected]> + * + * When we're building the XMesa driver for stand-alone Mesa we + * include this file when building the xm_*.c files. + * We need to define some types and macros differently when building + * in the Xserver vs. stand-alone Mesa. + */ + +#ifndef _XMESA_X_H_ +#define _XMESA_X_H_ + +typedef Display XMesaDisplay; +typedef Pixmap XMesaPixmap; +typedef Colormap XMesaColormap; +typedef Drawable XMesaDrawable; +typedef Window XMesaWindow; +typedef GC XMesaGC; +typedef XVisualInfo *XMesaVisualInfo; +typedef XImage XMesaImage; +typedef XPoint XMesaPoint; +typedef XColor XMesaColor; + +#define XMesaDestroyImage XDestroyImage + +#define XMesaPutPixel XPutPixel +#define XMesaGetPixel XGetPixel + +#define XMesaSetForeground XSetForeground +#define XMesaSetBackground XSetBackground +#define XMesaSetPlaneMask XSetPlaneMask +#define XMesaSetFunction XSetFunction +#define XMesaSetFillStyle XSetFillStyle +#define XMesaSetTile XSetTile + +#define XMesaDrawPoint XDrawPoint +#define XMesaDrawPoints XDrawPoints +#define XMesaDrawLine XDrawLine +#define XMesaFillRectangle XFillRectangle +#define XMesaGetImage XGetImage +#define XMesaPutImage XPutImage +#define XMesaCopyArea XCopyArea + +#define XMesaCreatePixmap XCreatePixmap +#define XMesaFreePixmap XFreePixmap +#define XMesaFreeGC XFreeGC + +#define GET_COLORMAP_SIZE(__v) __v->visinfo->colormap_size +#define GET_REDMASK(__v) __v->mesa_visual.redMask +#define GET_GREENMASK(__v) __v->mesa_visual.greenMask +#define GET_BLUEMASK(__v) __v->mesa_visual.blueMask +#define GET_VISUAL_DEPTH(__v) __v->visinfo->depth +#define GET_BLACK_PIXEL(__v) BlackPixel(__v->display, __v->mesa_visual.screen) +#define CHECK_BYTE_ORDER(__v) host_byte_order()==ImageByteOrder(__v->display) +#define CHECK_FOR_HPCR(__v) XInternAtom(__v->display, "_HP_RGB_SMOOTH_MAP_LIST", True) + +#endif diff --git a/src/mesa/drivers/x11/xmesa_xf86.h b/src/mesa/drivers/x11/xmesa_xf86.h new file mode 100644 index 00000000000..10f93c3ab62 --- /dev/null +++ b/src/mesa/drivers/x11/xmesa_xf86.h @@ -0,0 +1,198 @@ + +/************************************************************************** + +Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. +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"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sub license, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice (including the +next paragraph) shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. +IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +**************************************************************************/ + +/* + * Authors: + * Kevin E. Martin <[email protected]> + * + * When we're building the XMesa driver for use in the X server (as the + * indirect render) we include this file when building the xm_*.c files. + * We need to define some types and macros differently when building + * in the Xserver vs. stand-alone Mesa. + */ + +#ifndef _XMESA_XF86_H_ +#define _XMESA_XF86_H_ + +#include "GL/glxtokens.h" +#include "scrnintstr.h" +#include "pixmapstr.h" +#include "gcstruct.h" +#include "servermd.h" + + +typedef struct _XMesaImageRec { + int width, height; + char *data; + int bytes_per_line; /* Padded to 32 bits */ + int bits_per_pixel; +} XMesaImage; + +typedef ScreenRec XMesaDisplay; +typedef PixmapPtr XMesaPixmap; +typedef ColormapPtr XMesaColormap; +typedef DrawablePtr XMesaDrawable; +typedef WindowPtr XMesaWindow; +typedef GCPtr XMesaGC; +typedef VisualPtr XMesaVisualInfo; +typedef DDXPointRec XMesaPoint; +typedef xColorItem XMesaColor; + +#define XMesaSetGeneric(__d,__gc,__val,__mask) \ +do { \ + CARD32 __v[1]; \ + (void) __d; \ + __v[0] = __val; \ + dixChangeGC(NullClient, __gc, __mask, __v, NULL); \ +} while (0) + +#define XMesaSetGenericPtr(__d,__gc,__pval,__mask) \ +do { \ + ChangeGCVal __v[1]; \ + (void) __d; \ + __v[0].ptr = __pval; \ + dixChangeGC(NullClient, __gc, __mask, NULL, __v); \ +} while (0) + +#define XMesaSetForeground(d,gc,v) XMesaSetGeneric(d,gc,v,GCForeground) +#define XMesaSetBackground(d,gc,v) XMesaSetGeneric(d,gc,v,GCBackground) +#define XMesaSetPlaneMask(d,gc,v) XMesaSetGeneric(d,gc,v,GCPlaneMask) +#define XMesaSetFunction(d,gc,v) XMesaSetGeneric(d,gc,v,GCFunction) +#define XMesaSetFillStyle(d,gc,v) XMesaSetGeneric(d,gc,v,GCFillStyle) + +#define XMesaSetTile(d,gc,v) XMesaSetGenericPtr(d,gc,v,GCTile) + +#define XMesaDrawPoint(__d,__b,__gc,__x,__y) \ +do { \ + XMesaPoint __p[1]; \ + (void) __d; \ + __p[0].x = __x; \ + __p[0].y = __y; \ + ValidateGC(__b, __gc); \ + (*gc->ops->PolyPoint)(__b, __gc, CoordModeOrigin, 1, __p); \ +} while (0) + +#define XMesaDrawPoints(__d,__b,__gc,__p,__n,__m) \ +do { \ + (void) __d; \ + ValidateGC(__b, __gc); \ + (*gc->ops->PolyPoint)(__b, __gc, __m, __n, __p); \ +} while (0) + +#define XMesaDrawLine(__d, __b, __gc, __x0, __y0, __x1, __y1) \ +do { \ + XMesaPoint __p[2]; \ + (void) __d; \ + __p[0].x = __x0; \ + __p[0].y = __y0; \ + __p[1].x = __x1; \ + __p[1].y = __y1; \ + ValidateGC(__b, __gc); \ + (*gc->ops->PolyLines)(__b, __gc, CoordModeOrigin, 2, __p); \ +} while (0) + +#define XMesaFillRectangle(__d,__b,__gc,__x,__y,__w,__h) \ +do { \ + xRectangle __r[1]; \ + (void) __d; \ + ValidateGC((DrawablePtr)__b, __gc); \ + __r[0].x = __x; \ + __r[0].y = __y; \ + __r[0].width = __w; \ + __r[0].height = __h; \ + (*__gc->ops->PolyFillRect)((DrawablePtr)__b, __gc, 1, __r); \ +} while (0) + +static _X_INLINE XMesaImage *XMesaGetImage(XMesaDisplay *dpy, PixmapPtr p, int x, + int y, unsigned int width, + unsigned int height, + unsigned long plane_mask, int format) +{ + XMesaImage *img = Xcalloc(sizeof(*img)); + + img->width = p->drawable.width; + img->height = p->drawable.height; + img->bits_per_pixel = p->drawable.bitsPerPixel; + img->bytes_per_line = PixmapBytePad(width, p->drawable.depth); + img->data = malloc(height * img->bytes_per_line); + + /* Assumes: Images are always in ZPixmap format */ + (*p->drawable.pScreen->GetImage)(&p->drawable, x, y, width, height, + plane_mask, ZPixmap, img->data); + + return img; +} + +#define XMesaPutImage(__d,__b,__gc,__i,__sx,__sy,__x,__y,__w,__h) \ +do { \ + /* Assumes: Images are always in ZPixmap format */ \ + (void) __d; \ + ASSERT(!__sx && !__sy); /* The SubImage case */ \ + ValidateGC(__b, __gc); \ + (*__gc->ops->PutImage)(__b, __gc, ((XMesaDrawable)(__b))->depth, \ + __x, __y, __w, __h, 0, ZPixmap, \ + ((XMesaImage *)(__i))->data); \ +} while (0) + +#define XMesaCopyArea(__d,__sb,__db,__gc,__sx,__sy,__w,__h,__x,__y) \ +do { \ + (void) __d; \ + ValidateGC(__db, __gc); \ + (*__gc->ops->CopyArea)((DrawablePtr)__sb, __db, __gc, \ + __sx, __sy, __w, __h, __x, __y); \ +} while (0) + + +/* CreatePixmap returns a PixmapPtr; so, it cannot be inside braces */ +#ifdef CREATE_PIXMAP_USAGE_SCRATCH +#define XMesaCreatePixmap(__d,__b,__w,__h,__depth) \ + (*__d->CreatePixmap)(__d, __w, __h, __depth, 0) +#else +#define XMesaCreatePixmap(__d,__b,__w,__h,__depth) \ + (*__d->CreatePixmap)(__d, __w, __h, __depth) +#endif + +#define XMesaFreePixmap(__d,__b) \ + (*__d->DestroyPixmap)(__b) + +#define XMesaFreeGC(__d,__gc) \ +do { \ + (void) __d; \ + FreeScratchGC(__gc); \ +} while (0) + +#define GET_COLORMAP_SIZE(__v) __v->ColormapEntries +#define GET_REDMASK(__v) __v->mesa_visual.redMask +#define GET_GREENMASK(__v) __v->mesa_visual.greenMask +#define GET_BLUEMASK(__v) __v->mesa_visual.blueMask +#define GET_VISUAL_DEPTH(__v) __v->nplanes +#define GET_BLACK_PIXEL(__v) __v->display->blackPixel +#define CHECK_BYTE_ORDER(__v) GL_TRUE +#define CHECK_FOR_HPCR(__v) GL_FALSE + +#endif diff --git a/src/mesa/glapi/glthread.h b/src/mesa/glapi/glthread.h index ad2a63584b7..ae2f79f37dd 100644 --- a/src/mesa/glapi/glthread.h +++ b/src/mesa/glapi/glthread.h @@ -338,6 +338,10 @@ _glthread_GetTSD(_glthread_TSD *); extern void _glthread_SetTSD(_glthread_TSD *, void *); +#if !defined __GNUC__ || __GNUC__ < 3 +# define __builtin_expect(x, y) x +#endif + #if defined(GLX_USE_TLS) extern __thread struct _glapi_table * _glapi_tls_Dispatch diff --git a/src/mesa/main/glheader.h b/src/mesa/main/glheader.h index d69c7bbb21d..5657976711e 100644 --- a/src/mesa/main/glheader.h +++ b/src/mesa/main/glheader.h @@ -157,7 +157,8 @@ #include <byteswap.h> #define CPU_TO_LE32( x ) bswap_32( x ) #else /*__linux__*/ -#define CPU_TO_LE32( x ) ( x ) /* fix me for non-Linux big-endian! */ +#include <sys/endian.h> +#define CPU_TO_LE32( x ) bswap32( x ) #endif /*__linux__*/ #define MESA_BIG_ENDIAN 1 #else diff --git a/src/mesa/main/light.c b/src/mesa/main/light.c index d4db960f1b9..a15c1f0be05 100644 --- a/src/mesa/main/light.c +++ b/src/mesa/main/light.c @@ -208,7 +208,8 @@ _mesa_Lightfv( GLenum light, GLenum pname, const GLfloat *params ) if (_math_matrix_is_dirty(ctx->ModelviewMatrixStack.Top)) { _math_matrix_analyse(ctx->ModelviewMatrixStack.Top); } - TRANSFORM_NORMAL(temp, params, ctx->ModelviewMatrixStack.Top->inv); + TRANSFORM_DIRECTION(temp, params, ctx->ModelviewMatrixStack.Top->m); + NORMALIZE_3FV(temp); params = temp; break; case GL_SPOT_EXPONENT: diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 25dee52ad07..a61f970685c 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -2097,6 +2097,13 @@ struct gl_query_state }; +/** Set by #pragma directives */ +struct gl_sl_pragmas +{ + GLboolean Optimize; /**< defaults on */ + GLboolean Debug; /**< defaults off */ +}; + /** * A GLSL vertex or fragment shader object. @@ -2107,12 +2114,12 @@ struct gl_shader GLuint Name; /**< AKA the handle */ GLint RefCount; /**< Reference count */ GLboolean DeletePending; - - const GLchar *Source; /**< Source code string */ GLboolean CompileStatus; + GLboolean Main; /**< shader defines main() */ + const GLchar *Source; /**< Source code string */ struct gl_program *Program; /**< Post-compile assembly code */ GLchar *InfoLog; - GLboolean Main; /**< shader defines main() */ + struct gl_sl_pragmas Pragmas; }; diff --git a/src/mesa/math/m_matrix.h b/src/mesa/math/m_matrix.h index e8303f3ac5c..a8d9000e89b 100644 --- a/src/mesa/math/m_matrix.h +++ b/src/mesa/math/m_matrix.h @@ -189,6 +189,18 @@ do { \ } while (0) +/** + * Transform a direction by a matrix. + */ +#define TRANSFORM_DIRECTION( TO, DIR, MAT ) \ +do { \ + TO[0] = DIR[0] * MAT[0] + DIR[1] * MAT[4] + DIR[2] * MAT[8]; \ + TO[1] = DIR[0] * MAT[1] + DIR[1] * MAT[5] + DIR[2] * MAT[9]; \ + TO[2] = DIR[0] * MAT[2] + DIR[1] * MAT[6] + DIR[2] * MAT[10];\ +} while (0) + + + /*@}*/ diff --git a/src/mesa/shader/arbprogparse.c b/src/mesa/shader/arbprogparse.c index 536404bf978..5b80d99d49c 100644 --- a/src/mesa/shader/arbprogparse.c +++ b/src/mesa/shader/arbprogparse.c @@ -979,6 +979,8 @@ parse_output_color_num (GLcontext * ctx, const GLubyte ** inst, /** + * Validate the index of a texture coordinate + * * \param coord The texture unit index * \return 0 on sucess, 1 on error */ @@ -988,8 +990,30 @@ parse_texcoord_num (GLcontext * ctx, const GLubyte ** inst, { GLint i = parse_integer (inst, Program); - if ((i < 0) || (i >= (int)ctx->Const.MaxTextureUnits)) { - program_error(ctx, Program->Position, "Invalid texture unit index"); + if ((i < 0) || (i >= (int)ctx->Const.MaxTextureCoordUnits)) { + program_error(ctx, Program->Position, "Invalid texture coordinate index"); + return 1; + } + + *coord = (GLuint) i; + return 0; +} + + +/** + * Validate the index of a texture image unit + * + * \param coord The texture unit index + * \return 0 on sucess, 1 on error + */ +static GLuint +parse_teximage_num (GLcontext * ctx, const GLubyte ** inst, + struct arb_program *Program, GLuint * coord) +{ + GLint i = parse_integer (inst, Program); + + if ((i < 0) || (i >= (int)ctx->Const.MaxTextureImageUnits)) { + program_error(ctx, Program->Position, "Invalid texture image index"); return 1; } @@ -997,6 +1021,7 @@ parse_texcoord_num (GLcontext * ctx, const GLubyte ** inst, return 0; } + /** * \param coord The weight index * \return 0 on sucess, 1 on error @@ -3035,7 +3060,7 @@ parse_fp_instruction (GLcontext * ctx, const GLubyte ** inst, return 1; /* texImageUnit */ - if (parse_texcoord_num (ctx, inst, Program, &texcoord)) + if (parse_teximage_num (ctx, inst, Program, &texcoord)) return 1; fp->TexSrcUnit = texcoord; diff --git a/src/mesa/shader/prog_instruction.c b/src/mesa/shader/prog_instruction.c index f5c0a498fb0..4a6d0d670ac 100644 --- a/src/mesa/shader/prog_instruction.c +++ b/src/mesa/shader/prog_instruction.c @@ -1,8 +1,9 @@ /* * Mesa 3-D graphics library - * Version: 6.5.3 + * Version: 7.3 * - * Copyright (C) 1999-2005 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. + * Copyright (C) 1999-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"), @@ -157,7 +158,7 @@ static const struct instruction_info InstInfo[MAX_OPCODE] = { { OPCODE_AND, "AND", 2, 1 }, { OPCODE_ARA, "ARA", 1, 1 }, { OPCODE_ARL, "ARL", 1, 1 }, - { OPCODE_ARL_NV, "ARL", 1, 1 }, + { OPCODE_ARL_NV, "ARL_NV", 1, 1 }, { OPCODE_ARR, "ARL", 1, 1 }, { OPCODE_BGNLOOP,"BGNLOOP", 0, 0 }, { OPCODE_BGNSUB, "BGNSUB", 0, 0 }, @@ -186,7 +187,7 @@ static const struct instruction_info InstInfo[MAX_OPCODE] = { { OPCODE_FRC, "FRC", 1, 1 }, { OPCODE_IF, "IF", 1, 0 }, { OPCODE_KIL, "KIL", 1, 0 }, - { OPCODE_KIL_NV, "KIL", 0, 0 }, + { OPCODE_KIL_NV, "KIL_NV", 0, 0 }, { OPCODE_LG2, "LG2", 1, 1 }, { OPCODE_LIT, "LIT", 1, 1 }, { OPCODE_LOG, "LOG", 1, 1 }, @@ -235,7 +236,7 @@ static const struct instruction_info InstInfo[MAX_OPCODE] = { { OPCODE_TXD, "TXD", 3, 1 }, { OPCODE_TXL, "TXL", 1, 1 }, { OPCODE_TXP, "TXP", 1, 1 }, - { OPCODE_TXP_NV, "TXP", 1, 1 }, + { OPCODE_TXP_NV, "TXP_NV", 1, 1 }, { OPCODE_TRUNC, "TRUNC", 1, 1 }, { OPCODE_UP2H, "UP2H", 1, 1 }, { OPCODE_UP2US, "UP2US", 1, 1 }, diff --git a/src/mesa/shader/slang/library/slang_pp_directives.syn b/src/mesa/shader/slang/library/slang_pp_directives.syn index d4a321034d1..b51d168cc03 100644 --- a/src/mesa/shader/slang/library/slang_pp_directives.syn +++ b/src/mesa/shader/slang/library/slang_pp_directives.syn @@ -79,6 +79,12 @@ .emtcode BEHAVIOR_WARN 3 .emtcode BEHAVIOR_DISABLE 4 +/* + * The PRAGMA_* symbols follow TOKEN_PRAGMA + */ +.emtcode PRAGMA_NO_PARAM 0 +.emtcode PRAGMA_PARAM 1 + source optional_directive .and .loop source_element .and '\0' .emit ESCAPE_TOKEN .emit TOKEN_END; @@ -153,6 +159,7 @@ directive dir_elif .emit TOKEN_ELIF .or dir_endif .emit TOKEN_ENDIF .or dir_ext .emit TOKEN_EXTENSION .or + dir_pragma .emit TOKEN_PRAGMA .or dir_line .emit TOKEN_LINE; dir_define @@ -187,6 +194,19 @@ dir_ext dir_line optional_space .and '#' .and optional_space .and "line" .and expression; +dir_pragma + optional_space .and '#' .and optional_space .and "pragma" .and symbol .and opt_pragma_param; + + +opt_pragma_param + pragma_param .or .true .emit PRAGMA_NO_PARAM; + +pragma_param + optional_space .and '(' .emit PRAGMA_PARAM .and optional_space .and symbol_no_space .and optional_space .and ')'; + +symbol_no_space + symbol_character .emit * .and .loop symbol_character2 .emit * .and .true .emit '\0'; + symbol space .and symbol_character .emit * .and .loop symbol_character2 .emit * .and .true .emit '\0'; diff --git a/src/mesa/shader/slang/library/slang_pp_directives_syn.h b/src/mesa/shader/slang/library/slang_pp_directives_syn.h index 35e7bc27616..430f8d8217c 100644 --- a/src/mesa/shader/slang/library/slang_pp_directives_syn.h +++ b/src/mesa/shader/slang/library/slang_pp_directives_syn.h @@ -20,6 +20,8 @@ ".emtcode BEHAVIOR_ENABLE 2\n" ".emtcode BEHAVIOR_WARN 3\n" ".emtcode BEHAVIOR_DISABLE 4\n" +".emtcode PRAGMA_NO_PARAM 0\n" +".emtcode PRAGMA_PARAM 1\n" "source\n" " optional_directive .and .loop source_element .and '\\0' .emit ESCAPE_TOKEN .emit TOKEN_END;\n" "source_element\n" @@ -76,6 +78,7 @@ " dir_elif .emit TOKEN_ELIF .or\n" " dir_endif .emit TOKEN_ENDIF .or\n" " dir_ext .emit TOKEN_EXTENSION .or\n" +" dir_pragma .emit TOKEN_PRAGMA .or\n" " dir_line .emit TOKEN_LINE;\n" "dir_define\n" " optional_space .and '#' .and optional_space .and \"define\" .and symbol .and opt_parameters .and\n" @@ -99,6 +102,14 @@ " optional_space .and ':' .and optional_space .and extension_behavior;\n" "dir_line\n" " optional_space .and '#' .and optional_space .and \"line\" .and expression;\n" +"dir_pragma\n" +" optional_space .and '#' .and optional_space .and \"pragma\" .and symbol .and opt_pragma_param;\n" +"opt_pragma_param\n" +" pragma_param .or .true .emit PRAGMA_NO_PARAM;\n" +"pragma_param\n" +" optional_space .and '(' .emit PRAGMA_PARAM .and optional_space .and symbol_no_space .and optional_space .and ')';\n" +"symbol_no_space\n" +" symbol_character .emit * .and .loop symbol_character2 .emit * .and .true .emit '\\0';\n" "symbol\n" " space .and symbol_character .emit * .and .loop symbol_character2 .emit * .and .true .emit '\\0';\n" "opt_parameters\n" diff --git a/src/mesa/shader/slang/library/slang_shader.syn b/src/mesa/shader/slang/library/slang_shader.syn index 0ad4a1cba62..cc5c70a02f8 100644 --- a/src/mesa/shader/slang/library/slang_shader.syn +++ b/src/mesa/shader/slang/library/slang_shader.syn @@ -1162,13 +1162,6 @@ compound_statement_3 lbrace .and statement_list .and rbrace; /* - * <statement_no_new_scope> ::= <compound_statement_no_new_scope> - * | <simple_statement> - */ -statement_no_new_scope - compound_statement_no_new_scope .or simple_statement; - -/* * <compound_statement_no_new_scope> ::= "{" "}" * | "{" <statement_list> "}" */ @@ -1181,6 +1174,7 @@ compound_statement_no_new_scope_2 compound_statement_no_new_scope_3 lbrace .and statement_list .and rbrace; + /* * <statement_list> ::= <statement> * | <statement_list> <statement> @@ -1242,8 +1236,7 @@ condition_3 /* * <iteration_statement> ::= "while" "(" <condition> ")" <statement> * | "do" <statement> "while" "(" <expression> ")" ";" - * | "for" "(" <for_init_statement> <for_rest_statement> ")" - * <statement_no_new_scope> + * | "for" "(" <for_init_statement> <for_rest_statement> ")" <statement> */ iteration_statement iteration_statement_1 .or iteration_statement_2 .or iteration_statement_3; @@ -1255,7 +1248,7 @@ iteration_statement_2 expression .and rparen .error RPAREN_EXPECTED .emit OP_END .and semicolon; iteration_statement_3 "for" .emit OP_FOR .and lparen .error LPAREN_EXPECTED .and for_init_statement .and - for_rest_statement .and rparen .error RPAREN_EXPECTED .and statement_no_new_scope; + for_rest_statement .and rparen .error RPAREN_EXPECTED .and statement; /* * <for_init_statement> ::= <expression_statement> diff --git a/src/mesa/shader/slang/library/slang_shader_syn.h b/src/mesa/shader/slang/library/slang_shader_syn.h index e1705dfe193..6a382970e1a 100644 --- a/src/mesa/shader/slang/library/slang_shader_syn.h +++ b/src/mesa/shader/slang/library/slang_shader_syn.h @@ -566,8 +566,6 @@ " lbrace .and rbrace;\n" "compound_statement_3\n" " lbrace .and statement_list .and rbrace;\n" -"statement_no_new_scope\n" -" compound_statement_no_new_scope .or simple_statement;\n" "compound_statement_no_new_scope\n" " compound_statement_no_new_scope_1 .emit OP_BLOCK_BEGIN_NO_NEW_SCOPE .and .true .emit OP_END;\n" "compound_statement_no_new_scope_1\n" @@ -617,7 +615,7 @@ " expression .and rparen .error RPAREN_EXPECTED .emit OP_END .and semicolon;\n" "iteration_statement_3\n" " \"for\" .emit OP_FOR .and lparen .error LPAREN_EXPECTED .and for_init_statement .and\n" -" for_rest_statement .and rparen .error RPAREN_EXPECTED .and statement_no_new_scope;\n" +" for_rest_statement .and rparen .error RPAREN_EXPECTED .and statement;\n" "for_init_statement\n" " expression_statement .emit OP_EXPRESSION .or declaration_statement .emit OP_DECLARE;\n" "conditionopt\n" diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index 5cb472bed0f..51eb4c9c112 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -228,7 +228,14 @@ _slang_sizeof_type_specifier(const slang_type_specifier *spec) break; case SLANG_SPEC_STRUCT: sz = _slang_field_offset(spec, 0); /* special use */ - if (sz > 4) { + if (sz == 1) { + /* 1-float structs are actually troublesome to deal with since they + * might get placed at R.x, R.y, R.z or R.z. Return size=2 to + * ensure the object is placed at R.x + */ + sz = 2; + } + else if (sz > 4) { sz = (sz + 3) & ~0x3; /* round up to multiple of four */ } break; @@ -4286,7 +4293,7 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var, #endif { GLint sampNum = _mesa_add_sampler(prog->Parameters, varName, datatype); - store = _slang_new_ir_storage(PROGRAM_SAMPLER, sampNum, texIndex); + store = _slang_new_ir_storage_sampler(sampNum, texIndex, totalSize); /* If we have a sampler array, then we need to allocate the * additional samplers to ensure we don't allocate them elsewhere. @@ -4486,7 +4493,7 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var, n = _slang_gen_var_decl(A, var, var->initializer); /* emit GPU instructions */ - success = _slang_emit_code(n, A->vartable, A->program, GL_FALSE, A->log); + success = _slang_emit_code(n, A->vartable, A->program, A->pragmas, GL_FALSE, A->log); _slang_free_ir_tree(n); } @@ -4596,7 +4603,7 @@ _slang_codegen_function(slang_assemble_ctx * A, slang_function * fun) #endif /* Emit program instructions */ - success = _slang_emit_code(n, A->vartable, A->program, GL_TRUE, A->log); + success = _slang_emit_code(n, A->vartable, A->program, A->pragmas, GL_TRUE, A->log); _slang_free_ir_tree(n); /* free codegen context */ diff --git a/src/mesa/shader/slang/slang_codegen.h b/src/mesa/shader/slang/slang_codegen.h index 9489033d7b8..f2daa034e4f 100644 --- a/src/mesa/shader/slang/slang_codegen.h +++ b/src/mesa/shader/slang/slang_codegen.h @@ -36,6 +36,7 @@ typedef struct slang_assemble_ctx_ slang_atom_pool *atoms; slang_name_space space; struct gl_program *program; + struct gl_sl_pragmas *pragmas; slang_var_table *vartable; slang_info_log *log; struct slang_label_ *curFuncEndLabel; diff --git a/src/mesa/shader/slang/slang_compile.c b/src/mesa/shader/slang/slang_compile.c index 0a527f32206..6667138cddd 100644 --- a/src/mesa/shader/slang/slang_compile.c +++ b/src/mesa/shader/slang/slang_compile.c @@ -144,6 +144,7 @@ typedef struct slang_output_ctx_ slang_function_scope *funs; slang_struct_scope *structs; struct gl_program *program; + struct gl_sl_pragmas *pragmas; slang_var_table *vartable; GLuint default_precision[TYPE_SPECIFIER_COUNT]; GLboolean allow_precision; @@ -1005,7 +1006,7 @@ parse_statement(slang_parse_ctx * C, slang_output_ctx * O, /* parse child statements, do not create new variable scope */ oper->type = SLANG_OPER_BLOCK_NO_NEW_SCOPE; while (*C->I != OP_END) - if (!parse_child_operation(C, O, oper, 1)) + if (!parse_child_operation(C, O, oper, GL_TRUE)) RETURN0; C->I++; break; @@ -1017,7 +1018,7 @@ parse_statement(slang_parse_ctx * C, slang_output_ctx * O, oper->type = SLANG_OPER_BLOCK_NEW_SCOPE; o.vars = oper->locals; while (*C->I != OP_END) - if (!parse_child_operation(C, &o, oper, 1)) + if (!parse_child_operation(C, &o, oper, GL_TRUE)) RETURN0; C->I++; } @@ -1074,7 +1075,7 @@ parse_statement(slang_parse_ctx * C, slang_output_ctx * O, if (oper->a_id == SLANG_ATOM_NULL) RETURN0; while (*C->I != OP_END) { - if (!parse_child_operation(C, O, oper, 0)) + if (!parse_child_operation(C, O, oper, GL_FALSE)) RETURN0; } C->I++; @@ -1090,21 +1091,21 @@ parse_statement(slang_parse_ctx * C, slang_output_ctx * O, break; case OP_RETURN: oper->type = SLANG_OPER_RETURN; - if (!parse_child_operation(C, O, oper, 0)) + if (!parse_child_operation(C, O, oper, GL_FALSE)) RETURN0; break; case OP_EXPRESSION: oper->type = SLANG_OPER_EXPRESSION; - if (!parse_child_operation(C, O, oper, 0)) + if (!parse_child_operation(C, O, oper, GL_FALSE)) RETURN0; break; case OP_IF: oper->type = SLANG_OPER_IF; - if (!parse_child_operation(C, O, oper, 0)) + if (!parse_child_operation(C, O, oper, GL_FALSE)) RETURN0; - if (!parse_child_operation(C, O, oper, 1)) + if (!parse_child_operation(C, O, oper, GL_TRUE)) RETURN0; - if (!parse_child_operation(C, O, oper, 1)) + if (!parse_child_operation(C, O, oper, GL_TRUE)) RETURN0; break; case OP_WHILE: @@ -1113,17 +1114,17 @@ parse_statement(slang_parse_ctx * C, slang_output_ctx * O, oper->type = SLANG_OPER_WHILE; o.vars = oper->locals; - if (!parse_child_operation(C, &o, oper, 1)) + if (!parse_child_operation(C, &o, oper, GL_TRUE)) RETURN0; - if (!parse_child_operation(C, &o, oper, 1)) + if (!parse_child_operation(C, &o, oper, GL_TRUE)) RETURN0; } break; case OP_DO: oper->type = SLANG_OPER_DO; - if (!parse_child_operation(C, O, oper, 1)) + if (!parse_child_operation(C, O, oper, GL_TRUE)) RETURN0; - if (!parse_child_operation(C, O, oper, 0)) + if (!parse_child_operation(C, O, oper, GL_FALSE)) RETURN0; break; case OP_FOR: @@ -1132,13 +1133,13 @@ parse_statement(slang_parse_ctx * C, slang_output_ctx * O, oper->type = SLANG_OPER_FOR; o.vars = oper->locals; - if (!parse_child_operation(C, &o, oper, 1)) + if (!parse_child_operation(C, &o, oper, GL_TRUE)) RETURN0; - if (!parse_child_operation(C, &o, oper, 1)) + if (!parse_child_operation(C, &o, oper, GL_TRUE)) RETURN0; - if (!parse_child_operation(C, &o, oper, 0)) + if (!parse_child_operation(C, &o, oper, GL_FALSE)) RETURN0; - if (!parse_child_operation(C, &o, oper, 1)) + if (!parse_child_operation(C, &o, oper, GL_TRUE)) RETURN0; } break; @@ -1429,7 +1430,7 @@ parse_expression(slang_parse_ctx * C, slang_output_ctx * O, C->I++; while (*C->I != OP_END) - if (!parse_child_operation(C, O, op, 0)) + if (!parse_child_operation(C, O, op, GL_FALSE)) RETURN0; C->I++; #if 0 @@ -1494,7 +1495,7 @@ parse_expression(slang_parse_ctx * C, slang_output_ctx * O, RETURN0; } while (*C->I != OP_END) - if (!parse_child_operation(C, O, op, 0)) + if (!parse_child_operation(C, O, op, GL_FALSE)) RETURN0; C->I++; @@ -2059,6 +2060,7 @@ parse_init_declarator(slang_parse_ctx * C, slang_output_ctx * O, A.space.structs = O->structs; A.space.vars = O->vars; A.program = O->program; + A.pragmas = O->pragmas; A.vartable = O->vartable; A.log = C->L; A.curFuncEndLabel = NULL; @@ -2349,6 +2351,7 @@ parse_code_unit(slang_parse_ctx * C, slang_code_unit * unit, o.structs = &unit->structs; o.vars = &unit->vars; o.program = shader ? shader->Program : NULL; + o.pragmas = shader ? &shader->Pragmas : NULL; o.vartable = _slang_new_var_table(maxRegs); _slang_push_var_table(o.vartable); @@ -2417,6 +2420,7 @@ parse_code_unit(slang_parse_ctx * C, slang_code_unit * unit, A.space.structs = o.structs; A.space.vars = o.vars; A.program = o.program; + A.pragmas = &shader->Pragmas; A.vartable = o.vartable; A.log = C->L; @@ -2475,7 +2479,8 @@ compile_with_grammar(grammar id, const char *source, slang_code_unit * unit, slang_unit_type type, slang_info_log * infolog, slang_code_unit * builtin, struct gl_shader *shader, - const struct gl_extensions *extensions) + const struct gl_extensions *extensions, + struct gl_sl_pragmas *pragmas) { byte *prod; GLuint size, start, version; @@ -2504,7 +2509,7 @@ compile_with_grammar(grammar id, const char *source, slang_code_unit * unit, /* Now preprocess the source string. */ slang_string_init(&preprocessed); if (!_slang_preprocess_directives(&preprocessed, &source[start], - infolog, extensions)) { + infolog, extensions, pragmas)) { slang_string_free(&preprocessed); slang_info_log_error(infolog, "failed to preprocess the source."); return GL_FALSE; @@ -2578,7 +2583,8 @@ static GLboolean compile_object(grammar * id, const char *source, slang_code_object * object, slang_unit_type type, slang_info_log * infolog, struct gl_shader *shader, - const struct gl_extensions *extensions) + const struct gl_extensions *extensions, + struct gl_sl_pragmas *pragmas) { slang_code_unit *builtins = NULL; GLuint base_version = 110; @@ -2677,7 +2683,7 @@ compile_object(grammar * id, const char *source, slang_code_object * object, /* compile the actual shader - pass-in built-in library for external shader */ return compile_with_grammar(*id, source, &object->unit, type, infolog, - builtins, shader, extensions); + builtins, shader, extensions, pragmas); } @@ -2701,7 +2707,7 @@ compile_shader(GLcontext *ctx, slang_code_object * object, _slang_code_object_ctr(object); success = compile_object(&id, shader->Source, object, type, infolog, shader, - &ctx->Extensions); + &ctx->Extensions, &shader->Pragmas); if (id != 0) grammar_destroy(id); if (!success) diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c index 08b7d519a57..6b744d72c82 100644 --- a/src/mesa/shader/slang/slang_emit.c +++ b/src/mesa/shader/slang/slang_emit.c @@ -1300,14 +1300,10 @@ emit_tex(slang_emit_info *emitInfo, slang_ir_node *n) NULL, NULL); - /* Store->Index is the sampler index */ + /* Store->Index is the uniform/sampler index */ assert(n->Children[0]->Store->Index >= 0); - /* Store->Size is the texture target */ - assert(n->Children[0]->Store->Size >= TEXTURE_1D_INDEX); - assert(n->Children[0]->Store->Size <= TEXTURE_RECT_INDEX); - - inst->TexSrcTarget = n->Children[0]->Store->Size; - inst->TexSrcUnit = n->Children[0]->Store->Index; /* i.e. uniform's index */ + inst->TexSrcUnit = n->Children[0]->Store->Index; + inst->TexSrcTarget = n->Children[0]->Store->TexTarget; /* mark the sampler as being used */ _mesa_use_uniform(emitInfo->prog->Parameters, @@ -2381,10 +2377,20 @@ _slang_resolve_subroutines(slang_emit_info *emitInfo) - +/** + * Convert the IR tree into GPU instructions. + * \param n root of IR tree + * \param vt variable table + * \param prog program to put GPU instructions into + * \param pragmas controls codegen options + * \param withEnd if true, emit END opcode at end + * \param log log for emitting errors/warnings/info + */ GLboolean _slang_emit_code(slang_ir_node *n, slang_var_table *vt, - struct gl_program *prog, GLboolean withEnd, + struct gl_program *prog, + const struct gl_sl_pragmas *pragmas, + GLboolean withEnd, slang_info_log *log) { GET_CURRENT_CONTEXT(ctx); @@ -2401,7 +2407,7 @@ _slang_emit_code(slang_ir_node *n, slang_var_table *vt, emitInfo.EmitHighLevelInstructions = ctx->Shader.EmitHighLevelInstructions; emitInfo.EmitCondCodes = ctx->Shader.EmitCondCodes; - emitInfo.EmitComments = ctx->Shader.EmitComments; + emitInfo.EmitComments = ctx->Shader.EmitComments || pragmas->Debug; emitInfo.EmitBeginEndSub = GL_TRUE; if (!emitInfo.EmitCondCodes) { diff --git a/src/mesa/shader/slang/slang_emit.h b/src/mesa/shader/slang/slang_emit.h index 59fb2fa890d..8ff52bf605d 100644 --- a/src/mesa/shader/slang/slang_emit.h +++ b/src/mesa/shader/slang/slang_emit.h @@ -46,7 +46,9 @@ _slang_var_swizzle(GLint size, GLint comp); extern GLboolean _slang_emit_code(slang_ir_node *n, slang_var_table *vartable, - struct gl_program *prog, GLboolean withEnd, + struct gl_program *prog, + const struct gl_sl_pragmas *pragmas, + GLboolean withEnd, slang_info_log *log); diff --git a/src/mesa/shader/slang/slang_ir.c b/src/mesa/shader/slang/slang_ir.c index c33c80da999..e4c6e0ea516 100644 --- a/src/mesa/shader/slang/slang_ir.c +++ b/src/mesa/shader/slang/slang_ir.c @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 7.1 * * Copyright (C) 2005-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"), @@ -216,6 +216,26 @@ _slang_new_ir_storage_indirect(enum register_file file, } +/** + * Allocate IR storage for a texture sampler. + * \param sampNum the sampler number/index + * \param texTarget one of TEXTURE_x_INDEX values + * \param size number of samplers (in case of sampler array) + */ +slang_ir_storage * +_slang_new_ir_storage_sampler(GLint sampNum, GLuint texTarget, GLint size) +{ + slang_ir_storage *st; + assert(texTarget < NUM_TEXTURE_TARGETS); + st = _slang_new_ir_storage(PROGRAM_SAMPLER, sampNum, size); + if (st) { + st->TexTarget = texTarget; + } + return st; +} + + + /* XXX temporary function */ void _slang_copy_ir_storage(slang_ir_storage *dst, const slang_ir_storage *src) diff --git a/src/mesa/shader/slang/slang_ir.h b/src/mesa/shader/slang/slang_ir.h index a258e92e06f..644269d491c 100644 --- a/src/mesa/shader/slang/slang_ir.h +++ b/src/mesa/shader/slang/slang_ir.h @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 6.5.3 * - * Copyright (C) 2005-2007 Brian Paul All Rights Reserved. + * Copyright (C) 2005-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"), @@ -168,8 +168,8 @@ typedef enum struct slang_ir_storage_ { enum register_file File; /**< PROGRAM_TEMPORARY, PROGRAM_INPUT, etc */ - GLint Index; /**< -1 means unallocated */ - GLint Size; /**< number of floats */ + GLint Index; /**< -1 means unallocated */ + GLint Size; /**< number of floats or ints */ GLuint Swizzle; /**< Swizzle AND writemask info */ GLint RefCount; /**< Used during IR tree delete */ @@ -179,6 +179,7 @@ struct slang_ir_storage_ enum register_file IndirectFile; GLint IndirectIndex; GLuint IndirectSwizzle; + GLuint TexTarget; /**< If File==PROGRAM_SAMPLER, one of TEXTURE_x_INDEX */ /** If Parent is non-null, Index is relative to parent. * The other fields are ignored. @@ -254,6 +255,10 @@ _slang_new_ir_storage_indirect(enum register_file file, GLint indirectIndex, GLuint indirectSwizzle); +extern slang_ir_storage * +_slang_new_ir_storage_sampler(GLint sampNum, GLuint texTarget, GLint size); + + extern void _slang_copy_ir_storage(slang_ir_storage *dst, const slang_ir_storage *src); diff --git a/src/mesa/shader/slang/slang_preprocess.c b/src/mesa/shader/slang/slang_preprocess.c index 76e757cb381..d6b52535119 100644 --- a/src/mesa/shader/slang/slang_preprocess.c +++ b/src/mesa/shader/slang/slang_preprocess.c @@ -51,6 +51,9 @@ grammar_error_to_log (slang_info_log *log) GLint pos; grammar_get_last_error ((byte *) (buf), sizeof (buf), &pos); + if (buf[0] == 0) { + _mesa_snprintf(buf, sizeof(buf), "Preprocessor error"); + } slang_info_log_error (log, buf); } @@ -528,6 +531,56 @@ pp_ext_set(pp_ext *self, const char *name, GLboolean enable) } +static void +pp_pragmas_init(struct gl_sl_pragmas *pragmas) +{ + pragmas->Optimize = GL_TRUE; + pragmas->Debug = GL_FALSE; +} + + +/** + * Called in response to #pragma. For example, "#pragma debug(on)" would + * call this function as pp_pragma("debug", "on"). + * \return GL_TRUE if pragma is valid, GL_FALSE if invalid + */ +static GLboolean +pp_pragma(struct gl_sl_pragmas *pragmas, const char *pragma, const char *param) +{ +#if 0 + printf("#pragma %s %s\n", pragma, param); +#endif + if (_mesa_strcmp(pragma, "optimize") == 0) { + if (!param) + return GL_FALSE; /* missing required param */ + if (_mesa_strcmp(param, "on") == 0) { + pragmas->Optimize = GL_TRUE; + } + else if (_mesa_strcmp(param, "off") == 0) { + pragmas->Optimize = GL_FALSE; + } + else { + return GL_FALSE; /* invalid param */ + } + } + else if (_mesa_strcmp(pragma, "debug") == 0) { + if (!param) + return GL_FALSE; /* missing required param */ + if (_mesa_strcmp(param, "on") == 0) { + pragmas->Debug = GL_TRUE; + } + else if (_mesa_strcmp(param, "off") == 0) { + pragmas->Debug = GL_FALSE; + } + else { + return GL_FALSE; /* invalid param */ + } + } + /* all other pragmas are silently ignored */ + return GL_TRUE; +} + + /** * The state of preprocessor: current line, file and version number, list * of all defined macros and the #if/#endif context. @@ -862,11 +915,20 @@ parse_if (slang_string *output, const byte *prod, GLuint *pi, GLint *result, pp_ #define BEHAVIOR_WARN 3 #define BEHAVIOR_DISABLE 4 +#define PRAGMA_NO_PARAM 0 +#define PRAGMA_PARAM 1 + + static GLboolean preprocess_source (slang_string *output, const char *source, grammar pid, grammar eid, slang_info_log *elog, +<<<<<<< HEAD:src/mesa/shader/slang/slang_preprocess.c const struct gl_extensions *extensions) +======= + const struct gl_extensions *extensions, + struct gl_sl_pragmas *pragmas) +>>>>>>> origin/master:src/mesa/shader/slang/slang_preprocess.c { static const char *predefined[] = { "__FILE__", @@ -888,6 +950,10 @@ preprocess_source (slang_string *output, const char *source, } pp_state_init (&state, elog, extensions); +<<<<<<< HEAD:src/mesa/shader/slang/slang_preprocess.c +======= + pp_pragmas_init (pragmas); +>>>>>>> origin/master:src/mesa/shader/slang/slang_preprocess.c /* add the predefined symbols to the symbol table */ for (i = 0; predefined[i]; i++) { @@ -940,9 +1006,11 @@ preprocess_source (slang_string *output, const char *source, else { const char *id; GLuint idlen; + GLubyte token; i++; - switch (prod[i++]) { + token = prod[i++]; + switch (token) { case TOKEN_END: /* End of source string. @@ -1159,6 +1227,25 @@ preprocess_source (slang_string *output, const char *source, } break; + case TOKEN_PRAGMA: + { + GLint have_param; + const char *pragma, *param; + + pragma = (const char *) (&prod[i]); + i += _mesa_strlen(pragma) + 1; + have_param = (prod[i++] == PRAGMA_PARAM); + if (have_param) { + param = (const char *) (&prod[i]); + i += _mesa_strlen(param) + 1; + } + else { + param = NULL; + } + pp_pragma(pragmas, pragma, param); + } + break; + case TOKEN_LINE: id = (const char *) (&prod[i]); i += _mesa_strlen (id) + 1; @@ -1223,7 +1310,12 @@ GLboolean _slang_preprocess_directives(slang_string *output, const char *input, slang_info_log *elog, +<<<<<<< HEAD:src/mesa/shader/slang/slang_preprocess.c const struct gl_extensions *extensions) +======= + const struct gl_extensions *extensions, + struct gl_sl_pragmas *pragmas) +>>>>>>> origin/master:src/mesa/shader/slang/slang_preprocess.c { grammar pid, eid; GLboolean success; @@ -1239,7 +1331,11 @@ _slang_preprocess_directives(slang_string *output, grammar_destroy (pid); return GL_FALSE; } +<<<<<<< HEAD:src/mesa/shader/slang/slang_preprocess.c success = preprocess_source (output, input, pid, eid, elog, extensions); +======= + success = preprocess_source (output, input, pid, eid, elog, extensions, pragmas); +>>>>>>> origin/master:src/mesa/shader/slang/slang_preprocess.c grammar_destroy (eid); grammar_destroy (pid); return success; diff --git a/src/mesa/shader/slang/slang_preprocess.h b/src/mesa/shader/slang/slang_preprocess.h index dd996a6314b..f344820daef 100644 --- a/src/mesa/shader/slang/slang_preprocess.h +++ b/src/mesa/shader/slang/slang_preprocess.h @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 6.5.3 * - * Copyright (C) 2005-2007 Brian Paul All Rights Reserved. + * Copyright (C) 2005-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"), @@ -35,6 +35,7 @@ _slang_preprocess_version (const char *, GLuint *, GLuint *, slang_info_log *); extern GLboolean _slang_preprocess_directives(slang_string *output, const char *input, slang_info_log *, - const struct gl_extensions *extensions); + const struct gl_extensions *extensions, + struct gl_sl_pragmas *pragmas); #endif /* SLANG_PREPROCESS_H */ |