diff options
author | Brian Paul <brianp@vmware.com> | 2008-12-30 18:01:15 -0700 |
---|---|---|
committer | Brian Paul <brianp@vmware.com> | 2008-12-30 18:01:15 -0700 |
commit | c789bd376f09c3b61617aeef6f5adbba2c541178 (patch) | |
tree | b50aba807e609ef6084e52d814370a2cc761f1c8 | |
parent | 369115e4c7a2985d880951fd8248deefa92025dd (diff) | |
parent | e8d7db31e2a6784c765911233cb3d888f612837f (diff) |
Merge commit 'origin/master' into gallium-0.2
Conflicts:
src/mesa/main/config.h
23 files changed, 479 insertions, 218 deletions
diff --git a/docs/contents.html b/docs/contents.html index 257b13f68a..b348d3d17f 100644 --- a/docs/contents.html +++ b/docs/contents.html @@ -37,8 +37,8 @@ a:visited { <b>Download / Install</b> <ul> -<li><a href="download.html" target="MainFrame">Downloading/Unpacking</a> -<li><a href="install.html" target="MainFrame">Compilation/Installation</a> +<li><a href="download.html" target="MainFrame">Downloading / Unpacking</a> +<li><a href="install.html" target="MainFrame">Compiling / Installing</a> <li><a href="glu.html" target="MainFrame">SGI's GLU</a> <li><a href="precompiled.html" target="MainFrame">Precompiled Libraries</a> </ul> diff --git a/docs/install.html b/docs/install.html index 16ef013688..2d72506f67 100644 --- a/docs/install.html +++ b/docs/install.html @@ -1,58 +1,72 @@ <HTML> -<TITLE>Compilation and Installation</TITLE> +<TITLE>Compiling and Installing</TITLE> <link rel="stylesheet" type="text/css" href="mesa.css"></head> <BODY> -<H1>Compilation and Installation</H1> +<H1>Compiling and Installing</H1> <ol> <li><a href="#unix-x11">Unix / X11</a> + <ul> + <li><a href="#prereq">Prerequisites for DRI and hardware acceleration</a> + <li><a href="#autoconf">Building with autoconf</a> + <li><a href="#traditional">Building with traditional Makefiles</a> + <li><a href="#libs">The Libraries</a> + <li><a href="#demos">Running the demos + <li><a href="#install">Installing the header and library files + <li><a href="#pkg-config">Building OpenGL programs with pkg-config + </ul> <li><a href="#windows">Windows</a> -<li><a href="#vms">VMS</a> <li><a href="#other">Other</a> </ol> - +<br> <a name="unix-x11"> <H2>1. Unix/X11 Compilation and Installation</H1> -<h3>1.1 Prerequisites for DRI and Hardware Acceleration</h3> +<a name="prereq"> +<h3>1.1 Prerequisites for DRI and hardware acceleration</h3> <p> -To build Mesa 7.1 with DRI-based hardware acceleration you must first have -the <a href="http://dri.freedesktop.org/libdrm/" target="_parent">DRM version 2.3.1</a>. +The following are required for DRI-based hardware acceleration with Mesa 7.3: </p> -<p> -You should also be using the Xorg server version 1.4 or 1.5. +<ul> +<li><a href="http://xorg.freedesktop.org/releases/individual/proto/">driproto2</a> version 1.99.3 or later +<li><a href="http://dri.freedesktop.org/libdrm/" target="_parent">DRM</a> +version 2.4.3 or later +<li>Xorg server version 1.4 or 1.5. +</ul> </p> - -<h3>1.2 Autoconf Compilation</h3> +<a name="autoconf"> +<h3>1.2 Building with Autoconf</h3> <p> Mesa may be <a href="autoconf.html">built using autoconf</a>. This should work well on most GNU-based systems. -When that fails, the traditional Mesa build system is available. +If that fails the traditional Mesa build system is available. -<h3>1.3 Traditional Compilation</h3> +<a name="traditional"> +<h3>1.3 Building with traditional Makefiles</h3> <p> The traditional Mesa build system is based on a collection of pre-defined system configurations. </p> <p> -To see the list of configurations, type <b>make</b> alone. -Then choose a configuration from the list and type <b>make configname</b>. +To see the list of configurations, just type <code>make</code>. +Then choose a configuration from the list and type <code>make</code> +<em>configname</em>. </p> <p> @@ -66,7 +80,7 @@ allow you to run OpenGL/GLX applications on any X server (regardless of whether it supports the GLX X server extension). You will <em>not</em> be able to use hardware 3D acceleration. <p> -To compile stand-alone Mesa type <b>make</b> in the top-level directory. +To compile stand-alone Mesa type <code>make</code> in the top-level directory. You'll see a list of supported system configurations. Choose one from the list (such as linux-x86), and type: </p> @@ -109,6 +123,7 @@ Later, if you want to rebuild for a different configuration run </p> +<a name="libs"> <h3>1.4 The libraries</h3> <p> @@ -169,6 +184,7 @@ If you built the DRI hardware drivers, you'll also see the DRI drivers: </pre> +<a name="demos"> <h3>1.5 Running the demos</h3> <p> @@ -244,6 +260,7 @@ Retrace your steps if this doesn't look right. </p> +<a name="install"> <H3>1.6 Installing the header and library files</H3> <p> @@ -284,7 +301,8 @@ This is a handy way to compare multiple OpenGL implementations. </p> -<H3>1.7 Building OpenGL Programs With pkg-config</H3> +<a name="pkg-config"> +<H3>1.7 Building OpenGL programs with pkg-config</H3> <p> Running <code>make install</code> will install package configuration files @@ -314,25 +332,15 @@ Please see the <a href="README.WIN32">README.WIN32</a> file. - -<a name="vms"> -<H2>3. VMS Compilation and Installation</H1> - -<p> -Please see the <a href="README.VMS">README.VMS</a> file. -</p> - - - - <a name="other"> -<H2>4. Other systems</H1> +<H2>3. Other systems</H1> <p> Documentation for other environments (some may be very out of date): </p> <UL> +<li><A HREF="README.VMS">README.VMS</A> - VMS <LI><A HREF="README.GGI">README.GGI</A> - GGI <LI><A HREF="README.3DFX">README.3DFX</A> - 3Dfx/Glide driver <LI><A HREF="README.AMIWIN">README.AMIWIN</A> - Amiga Amiwin diff --git a/progs/glsl/twoside.c b/progs/glsl/twoside.c index 672a00491e..06488bd175 100644 --- a/progs/glsl/twoside.c +++ b/progs/glsl/twoside.c @@ -26,27 +26,39 @@ static GLuint fragShader; static GLuint vertShader; static GLuint program; static GLint win = 0; -static GLboolean anim = 0*GL_TRUE; -static GLboolean DetermineInFragProg = GL_TRUE; -static GLfloat Xrot = 30.0f; +static GLboolean anim; +static GLboolean DetermineFacingInFragProg; +static GLfloat Xrot; static GLint u_fragface; -static GLenum FrontWinding = GL_CCW; +static GLenum FrontWinding; static int prevTime = 0; -static const GLfloat Red[4] = {1, 0, 0, 0}; +static const GLfloat Red[4] = {1, 0, 0, 1}; static const GLfloat Green[4] = {0, 1, 0, 0}; static void +SetDefaults(void) +{ + DetermineFacingInFragProg = GL_TRUE; + FrontWinding = GL_CCW; + Xrot = 30; + anim = 0; + glutIdleFunc(NULL); +} + + +static void Redisplay(void) { + const int sections = 20; int i; float radius = 2; glFrontFace(FrontWinding); - if (DetermineInFragProg) { + if (DetermineFacingInFragProg) { glUniform1i_func(u_fragface, 1); glDisable(GL_VERTEX_PROGRAM_TWO_SIDE); } @@ -64,8 +76,8 @@ Redisplay(void) glBegin(GL_TRIANGLE_STRIP); glColor4fv(Red); glSecondaryColor3fv_func(Green); - for (i = 0; i < 20; i++) { - float a = i / 19.0 * M_PI * 2.0; + for (i = 0; i <= sections; i++) { + float a = (float) i / (sections) * M_PI * 2.0; float x = radius * cos(a); float y = radius * sin(a); glVertex3f(x, -1, y); @@ -139,17 +151,15 @@ Key(unsigned char key, int x, int y) break; case 'f': printf("Using frag shader gl_FrontFacing\n"); - DetermineInFragProg = GL_TRUE; + DetermineFacingInFragProg = GL_TRUE; break; case 'v': printf("Using vert shader Two-sided lighting\n"); - DetermineInFragProg = GL_FALSE; + DetermineFacingInFragProg = GL_FALSE; break; case 'r': /* reset */ - Xrot = 30; - anim = 0; - glutIdleFunc(NULL); + SetDefaults(); break; case 's': Xrot += 5; @@ -182,14 +192,16 @@ Init(void) static const char *fragShaderText = "uniform bool fragface; \n" "void main() { \n" -#if 0 +#if 1 " if (!fragface || gl_FrontFacing) { \n" " gl_FragColor = gl_Color; \n" " } \n" " else { \n" + " // note: dim green to help debug \n" " gl_FragColor = 0.8 * gl_SecondaryColor; \n" " } \n" #else + /* DEBUG CODE */ " bool f = gl_FrontFacing; \n" " if (f) { \n" " gl_FragColor = vec4(1.0, 0.0, 0.0, 0.0); \n" @@ -197,8 +209,6 @@ Init(void) " else { \n" " gl_FragColor = vec4(0.0, 1.0, 0.0, 0.0); \n" " } \n" - " //float g = float(gl_FrontFacing) * 0.5 + 0.5; \n" - " //gl_FragColor = vec4(g); \n" #endif "} \n"; static const char *vertShaderText = @@ -241,6 +251,8 @@ Init(void) assert(glIsShader_func(vertShader)); glEnable(GL_DEPTH_TEST); + + SetDefaults(); } diff --git a/src/mesa/drivers/dri/common/vblank.c b/src/mesa/drivers/dri/common/vblank.c index d610253fe6..12aeaa108f 100644 --- a/src/mesa/drivers/dri/common/vblank.c +++ b/src/mesa/drivers/dri/common/vblank.c @@ -130,9 +130,8 @@ int driWaitForMSC32( __DRIdrawablePrivate *priv, if ( divisor != 0 ) { - unsigned int target = (unsigned int)target_msc; - unsigned int next = target; - unsigned int r; + int64_t next = target_msc; + int64_t r; int dont_wait = (target_msc == 0); do { @@ -154,9 +153,9 @@ int driWaitForMSC32( __DRIdrawablePrivate *priv, *msc = vblank_to_msc(priv, vbl.reply.sequence); - dont_wait = 0; - if (target_msc != 0 && *msc == target) + if (!dont_wait && *msc == next) break; + dont_wait = 0; /* Assuming the wait-done test fails, the next refresh to wait for * will be one that satisfies (MSC % divisor) == remainder. The @@ -165,11 +164,12 @@ int driWaitForMSC32( __DRIdrawablePrivate *priv, * If this refresh has already happened, we add divisor to obtain * the next refresh after the current one that will satisfy it. */ - r = (*msc % (unsigned int)divisor); - next = (*msc - r + (unsigned int)remainder); - if (next <= *msc) next += (unsigned int)divisor; + r = ((uint64_t)*msc % divisor); + next = (*msc - r + remainder); + if (next <= *msc) + next += divisor; - } while ( r != (unsigned int)remainder ); + } while (r != remainder); } else { /* If the \c divisor is zero, just wait until the MSC is greater diff --git a/src/mesa/drivers/dri/i915/i915_context.c b/src/mesa/drivers/dri/i915/i915_context.c index e0ddc7fd61..9bff74294d 100644 --- a/src/mesa/drivers/dri/i915/i915_context.c +++ b/src/mesa/drivers/dri/i915/i915_context.c @@ -55,6 +55,7 @@ static const struct dri_extension i915_extensions[] = { {"GL_ARB_fragment_program", NULL}, {"GL_ARB_shadow", NULL}, {"GL_ARB_texture_non_power_of_two", NULL}, + {"GL_ATI_texture_env_combine3", NULL}, {"GL_EXT_shadow_funcs", NULL}, {NULL, NULL} }; diff --git a/src/mesa/drivers/dri/i915/i915_fragprog.c b/src/mesa/drivers/dri/i915/i915_fragprog.c index 8bd761ec6a..4760906a7e 100644 --- a/src/mesa/drivers/dri/i915/i915_fragprog.c +++ b/src/mesa/drivers/dri/i915/i915_fragprog.c @@ -1105,30 +1105,14 @@ i915ValidateFragmentProgram(struct i915_context *i915) EMIT_ATTR(_TNL_ATTRIB_COLOR0, EMIT_4UB_4F_BGRA, S4_VFMT_COLOR, 4); } - if ((inputsRead & (FRAG_BIT_COL1 | FRAG_BIT_FOGC)) || - i915->vertex_fog != I915_FOG_NONE) { - - if (inputsRead & FRAG_BIT_COL1) { - intel->specoffset = offset / 4; - EMIT_ATTR(_TNL_ATTRIB_COLOR1, EMIT_3UB_3F_BGR, S4_VFMT_SPEC_FOG, 3); - } - else - EMIT_PAD(3); - - if ((inputsRead & FRAG_BIT_FOGC) || i915->vertex_fog != I915_FOG_NONE) - EMIT_ATTR(_TNL_ATTRIB_FOG, EMIT_1UB_1F, S4_VFMT_SPEC_FOG, 1); - else - EMIT_PAD(1); + if (inputsRead & FRAG_BIT_COL1) { + intel->specoffset = offset / 4; + EMIT_ATTR(_TNL_ATTRIB_COLOR1, EMIT_4UB_4F_BGRA, S4_VFMT_SPEC_FOG, 4); } - /* XXX this was disabled, but enabling this code helped fix the Glean - * tfragprog1 fog tests. - */ -#if 1 if ((inputsRead & FRAG_BIT_FOGC) || i915->vertex_fog != I915_FOG_NONE) { EMIT_ATTR(_TNL_ATTRIB_FOG, EMIT_1F, S4_VFMT_FOG_PARAM, 4); } -#endif for (i = 0; i < p->ctx->Const.MaxTextureCoordUnits; i++) { if (inputsRead & FRAG_BIT_TEX(i)) { diff --git a/src/mesa/drivers/dri/intel/intel_buffers.c b/src/mesa/drivers/dri/intel/intel_buffers.c index f8f009c6a3..4d036dee42 100644 --- a/src/mesa/drivers/dri/intel/intel_buffers.c +++ b/src/mesa/drivers/dri/intel/intel_buffers.c @@ -181,7 +181,7 @@ intelUpdatePageFlipping(struct intel_context *intel, intel_fb->pf_current_page = (intel->sarea->pf_current_page >> (intel_fb->pf_planes & 0x2)) & 0x3; - intel_fb->pf_num_pages = intel->intelScreen->third.handle ? 3 : 2; + intel_fb->pf_num_pages = 2; pf_active = pf_planes && (pf_planes & intel->sarea->pf_active) == pf_planes; diff --git a/src/mesa/drivers/dri/intel/intel_context.c b/src/mesa/drivers/dri/intel/intel_context.c index 6c625b428c..44b276a123 100644 --- a/src/mesa/drivers/dri/intel/intel_context.c +++ b/src/mesa/drivers/dri/intel/intel_context.c @@ -412,6 +412,7 @@ static const struct dri_extension brw_extensions[] = { { "GL_EXT_shadow_funcs", NULL }, { "GL_EXT_texture_sRGB", NULL }, { "GL_ATI_separate_stencil", GL_ATI_separate_stencil_functions }, + { "GL_ATI_texture_env_combine3", NULL }, { NULL, NULL } }; @@ -775,7 +776,6 @@ intelDestroyContext(__DRIcontextPrivate * driContextPriv) intel_region_release(&intel->front_region); intel_region_release(&intel->back_region); - intel_region_release(&intel->third_region); intel_region_release(&intel->depth_region); driDestroyOptionCache(&intel->optionCache); @@ -825,12 +825,7 @@ intelMakeCurrent(__DRIcontextPrivate * driContextPriv, intel_renderbuffer_set_region(intel_fb->color_rb[1], intel->back_region); } -#if 0 - if (intel_fb->color_rb[2]) { - intel_renderbuffer_set_region(intel_fb->color_rb[2], - intel->third_region); - } -#endif + if (irbDepth) { intel_renderbuffer_set_region(irbDepth, intel->depth_region); } @@ -867,7 +862,7 @@ intelMakeCurrent(__DRIcontextPrivate * driContextPriv, driDrawableInitVBlank(driDrawPriv); intel_fb->vbl_waited = driDrawPriv->vblSeq; - for (i = 0; i < (intel->intelScreen->third.handle ? 3 : 2); i++) { + for (i = 0; i < 2; i++) { if (intel_fb->color_rb[i]) intel_fb->color_rb[i]->vbl_pending = driDrawPriv->vblSeq; } diff --git a/src/mesa/drivers/dri/intel/intel_context.h b/src/mesa/drivers/dri/intel/intel_context.h index ee43ed7e83..ac08117bb4 100644 --- a/src/mesa/drivers/dri/intel/intel_context.h +++ b/src/mesa/drivers/dri/intel/intel_context.h @@ -166,7 +166,6 @@ struct intel_context struct intel_region *front_region; struct intel_region *back_region; - struct intel_region *third_region; struct intel_region *depth_region; /** diff --git a/src/mesa/drivers/dri/intel/intel_pixel_bitmap.c b/src/mesa/drivers/dri/intel/intel_pixel_bitmap.c index fb1a051cdc..5e0e0d29ca 100644 --- a/src/mesa/drivers/dri/intel/intel_pixel_bitmap.c +++ b/src/mesa/drivers/dri/intel/intel_pixel_bitmap.c @@ -244,8 +244,8 @@ do_blit_bitmap( GLcontext *ctx, /* Clip to drawable cliprect */ if (!_mesa_clip_to_region(cliprects[i].x1, cliprects[i].y1, - cliprects[i].x2 - cliprects[i].x1, - cliprects[i].y2 - cliprects[i].y1, + cliprects[i].x2, + cliprects[i].y2, &box_x, &box_y, &box_w, &box_h)) continue; diff --git a/src/mesa/drivers/dri/intel/intel_regions.c b/src/mesa/drivers/dri/intel/intel_regions.c index 8dbcc3050e..51ce32a967 100644 --- a/src/mesa/drivers/dri/intel/intel_regions.c +++ b/src/mesa/drivers/dri/intel/intel_regions.c @@ -550,15 +550,6 @@ intel_recreate_static_regions(struct intel_context *intel) intel->back_region, &intelScreen->back); -#ifdef I915 - if (intelScreen->third.handle) { - intel->third_region = - intel_recreate_static(intel, "third", - intel->third_region, - &intelScreen->third); - } -#endif /* I915 */ - /* Still assumes front.cpp == depth.cpp. We can kill this when we move to * private buffers. */ diff --git a/src/mesa/drivers/dri/intel/intel_screen.c b/src/mesa/drivers/dri/intel/intel_screen.c index 61b55b97b5..fc4e82b56c 100644 --- a/src/mesa/drivers/dri/intel/intel_screen.c +++ b/src/mesa/drivers/dri/intel/intel_screen.c @@ -177,13 +177,6 @@ intelUpdateScreenFromSAREA(intelScreenPrivate * intelScreen, intelScreen->back.size = sarea->back_size; intelScreen->back.tiled = sarea->back_tiled; - if (intelScreen->driScrnPriv->ddx_version.minor >= 8) { - intelScreen->third.offset = sarea->third_offset; - intelScreen->third.handle = sarea->third_handle; - intelScreen->third.size = sarea->third_size; - intelScreen->third.tiled = sarea->third_tiled; - } - intelScreen->depth.offset = sarea->depth_offset; intelScreen->depth.handle = sarea->depth_handle; intelScreen->depth.size = sarea->depth_size; @@ -192,12 +185,10 @@ intelUpdateScreenFromSAREA(intelScreenPrivate * intelScreen, if (intelScreen->driScrnPriv->ddx_version.minor >= 9) { intelScreen->front.bo_handle = sarea->front_bo_handle; intelScreen->back.bo_handle = sarea->back_bo_handle; - intelScreen->third.bo_handle = sarea->third_bo_handle; intelScreen->depth.bo_handle = sarea->depth_bo_handle; } else { intelScreen->front.bo_handle = -1; intelScreen->back.bo_handle = -1; - intelScreen->third.bo_handle = -1; intelScreen->depth.bo_handle = -1; } @@ -353,12 +344,6 @@ intelCreateBuffer(__DRIscreenPrivate * driScrnPriv, _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_BACK_LEFT, &intel_fb->color_rb[1]->Base); - if (screen->third.handle) { - struct gl_renderbuffer *tmp_rb = NULL; - - intel_fb->color_rb[2] = intel_create_renderbuffer(rgbFormat); - _mesa_reference_renderbuffer(&tmp_rb, &intel_fb->color_rb[2]->Base); - } } if (mesaVis->depthBits == 24) { diff --git a/src/mesa/drivers/dri/intel/intel_screen.h b/src/mesa/drivers/dri/intel/intel_screen.h index 91f0d6d1ae..cf5359baae 100644 --- a/src/mesa/drivers/dri/intel/intel_screen.h +++ b/src/mesa/drivers/dri/intel/intel_screen.h @@ -56,7 +56,6 @@ typedef struct { intelRegion front; intelRegion back; - intelRegion third; intelRegion depth; intelRegion tex; diff --git a/src/mesa/drivers/dri/r300/r300_reg.h b/src/mesa/drivers/dri/r300/r300_reg.h index 778db96cc1..7c6485ef60 100644 --- a/src/mesa/drivers/dri/r300/r300_reg.h +++ b/src/mesa/drivers/dri/r300/r300_reg.h @@ -64,7 +64,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. #define R300_SE_VPORT_ZSCALE 0x1DA8 #define R300_SE_VPORT_ZOFFSET 0x1DAC - +#define R300_VAP_PORT_IDX0 0x2040 /* * Vertex Array Processing (VAP) Control */ @@ -3201,9 +3201,9 @@ enum { #define R300_PACKET3_3D_LOAD_VBPNTR 0x00002F00 #define R300_PACKET3_INDX_BUFFER 0x00003300 -# define R300_EB_UNK1_SHIFT 24 -# define R300_EB_UNK1 (0x80<<24) -# define R300_EB_UNK2 0x0810 +# define R300_INDX_BUFFER_DST_SHIFT 0 +# define R300_INDX_BUFFER_SKIP_SHIFT 16 +# define R300_INDX_BUFFER_ONE_REG_WR (1<<31) /* Same as R300_PACKET3_3D_DRAW_VBUF but without VAP_VTX_FMT */ #define R300_PACKET3_3D_DRAW_VBUF_2 0x00003400 diff --git a/src/mesa/drivers/dri/r300/r300_render.c b/src/mesa/drivers/dri/r300/r300_render.c index 292f87a2b1..f9266e44c1 100644 --- a/src/mesa/drivers/dri/r300/r300_render.c +++ b/src/mesa/drivers/dri/r300/r300_render.c @@ -208,7 +208,8 @@ static void r300FireEB(r300ContextPtr rmesa, unsigned long addr, e32(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (vertex_count << 16) | type | R300_VAP_VF_CNTL__INDEX_SIZE_32bit); start_packet3(CP_PACKET3(R300_PACKET3_INDX_BUFFER, 2), 2); - e32(R300_EB_UNK1 | (0 << 16) | R300_EB_UNK2); + e32(R300_INDX_BUFFER_ONE_REG_WR | (0 << R300_INDX_BUFFER_SKIP_SHIFT) | + (R300_VAP_PORT_IDX0 >> 2)); e32(addr); e32(vertex_count); } diff --git a/src/mesa/main/config.h b/src/mesa/main/config.h index e29964a1e8..ec7e156ebd 100644 --- a/src/mesa/main/config.h +++ b/src/mesa/main/config.h @@ -181,14 +181,14 @@ /** For any program target/extension */ /*@{*/ #define MAX_PROGRAM_INSTRUCTIONS (16 * 1024) -#define MAX_PROGRAM_LOCAL_PARAMS 128 /* KW: power of two */ +#define MAX_PROGRAM_LOCAL_PARAMS 256 /**< per-program constants (power of two) */ #define MAX_PROGRAM_ENV_PARAMS 128 #define MAX_PROGRAM_MATRICES 8 #define MAX_PROGRAM_MATRIX_STACK_DEPTH 4 #define MAX_PROGRAM_CALL_DEPTH 8 #define MAX_PROGRAM_TEMPS 128 #define MAX_PROGRAM_ADDRESS_REGS 2 -#define MAX_UNIFORMS 128 /**< number of float components */ +#define MAX_UNIFORMS 256 /**< number of vec4 uniforms */ #define MAX_VARYING 8 /**< number of float[4] vectors */ #define MAX_SAMPLERS 8 #define MAX_PROGRAM_INPUTS 32 diff --git a/src/mesa/shader/prog_statevars.h b/src/mesa/shader/prog_statevars.h index 72e51f4031..d5358a1d04 100644 --- a/src/mesa/shader/prog_statevars.h +++ b/src/mesa/shader/prog_statevars.h @@ -79,10 +79,10 @@ typedef enum gl_state_index_ { STATE_SHININESS, STATE_HALF_VECTOR, - STATE_POSITION, - STATE_ATTENUATION, - STATE_SPOT_DIRECTION, - STATE_SPOT_CUTOFF, + STATE_POSITION, /**< xyzw = position */ + STATE_ATTENUATION, /**< xyz = attenuation, w = spot exponent */ + STATE_SPOT_DIRECTION, /**< xyz = direction, w = cos(cutoff) */ + STATE_SPOT_CUTOFF, /**< x = cutoff, yzw = undefined */ STATE_TEXGEN_EYE_S, STATE_TEXGEN_EYE_T, diff --git a/src/mesa/shader/slang/library/slang_common_builtin.gc b/src/mesa/shader/slang/library/slang_common_builtin.gc index a051c53eea..3e03b101b8 100644 --- a/src/mesa/shader/slang/library/slang_common_builtin.gc +++ b/src/mesa/shader/slang/library/slang_common_builtin.gc @@ -1,8 +1,9 @@ /* * Mesa 3-D graphics library - * Version: 6.5 + * Version: 7.3 * * Copyright (C) 2006 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"), @@ -98,6 +99,9 @@ struct gl_MaterialParameters { uniform gl_MaterialParameters gl_FrontMaterial; uniform gl_MaterialParameters gl_BackMaterial; +/* NOTE: the order of these fields is significant! + * See the definition of the lighting state vars such as STATE_SPOT_DIRECTION. + */ struct gl_LightSourceParameters { vec4 ambient; vec4 diffuse; @@ -105,12 +109,14 @@ struct gl_LightSourceParameters { vec4 position; vec4 halfVector; vec3 spotDirection; - float spotExponent; - float spotCutoff; float spotCosCutoff; + float constantAttenuation; float linearAttenuation; float quadraticAttenuation; + float spotExponent; + + float spotCutoff; }; uniform gl_LightSourceParameters gl_LightSource[gl_MaxLights]; diff --git a/src/mesa/shader/slang/library/slang_common_builtin_gc.h b/src/mesa/shader/slang/library/slang_common_builtin_gc.h index 4663201081..759bf247d8 100644 --- a/src/mesa/shader/slang/library/slang_common_builtin_gc.h +++ b/src/mesa/shader/slang/library/slang_common_builtin_gc.h @@ -66,58 +66,58 @@ 116,83,111,117,114,99,101,80,97,114,97,109,101,116,101,114,115,0,12,0,97,109,98,105,101,110,116,0, 0,0,1,12,0,100,105,102,102,117,115,101,0,0,0,1,12,0,115,112,101,99,117,108,97,114,0,0,0,1,12,0,112, 111,115,105,116,105,111,110,0,0,0,1,12,0,104,97,108,102,86,101,99,116,111,114,0,0,0,1,11,0,115,112, -111,116,68,105,114,101,99,116,105,111,110,0,0,0,1,9,0,115,112,111,116,69,120,112,111,110,101,110, -116,0,0,0,1,9,0,115,112,111,116,67,117,116,111,102,102,0,0,0,1,9,0,115,112,111,116,67,111,115,67, -117,116,111,102,102,0,0,0,1,9,0,99,111,110,115,116,97,110,116,65,116,116,101,110,117,97,116,105, -111,110,0,0,0,1,9,0,108,105,110,101,97,114,65,116,116,101,110,117,97,116,105,111,110,0,0,0,1,9,0, -113,117,97,100,114,97,116,105,99,65,116,116,101,110,117,97,116,105,111,110,0,0,0,0,0,0,0,2,2,90,95, -4,0,25,103,108,95,76,105,103,104,116,83,111,117,114,99,101,80,97,114,97,109,101,116,101,114,115,0, -0,1,103,108,95,76,105,103,104,116,83,111,117,114,99,101,0,3,18,103,108,95,77,97,120,76,105,103,104, -116,115,0,0,0,2,2,90,95,0,0,24,103,108,95,76,105,103,104,116,77,111,100,101,108,80,97,114,97,109, -101,116,101,114,115,0,12,0,97,109,98,105,101,110,116,0,0,0,0,0,0,0,2,2,90,95,4,0,25,103,108,95,76, -105,103,104,116,77,111,100,101,108,80,97,114,97,109,101,116,101,114,115,0,0,1,103,108,95,76,105, -103,104,116,77,111,100,101,108,0,0,0,2,2,90,95,0,0,24,103,108,95,76,105,103,104,116,77,111,100,101, -108,80,114,111,100,117,99,116,115,0,12,0,115,99,101,110,101,67,111,108,111,114,0,0,0,0,0,0,0,2,2, -90,95,4,0,25,103,108,95,76,105,103,104,116,77,111,100,101,108,80,114,111,100,117,99,116,115,0,0,1, -103,108,95,70,114,111,110,116,76,105,103,104,116,77,111,100,101,108,80,114,111,100,117,99,116,0,0, -0,2,2,90,95,4,0,25,103,108,95,76,105,103,104,116,77,111,100,101,108,80,114,111,100,117,99,116,115, -0,0,1,103,108,95,66,97,99,107,76,105,103,104,116,77,111,100,101,108,80,114,111,100,117,99,116,0,0, -0,2,2,90,95,0,0,24,103,108,95,76,105,103,104,116,80,114,111,100,117,99,116,115,0,12,0,97,109,98, -105,101,110,116,0,0,0,1,12,0,100,105,102,102,117,115,101,0,0,0,1,12,0,115,112,101,99,117,108,97, -114,0,0,0,0,0,0,0,2,2,90,95,4,0,25,103,108,95,76,105,103,104,116,80,114,111,100,117,99,116,115,0,0, -1,103,108,95,70,114,111,110,116,76,105,103,104,116,80,114,111,100,117,99,116,0,3,18,103,108,95,77, -97,120,76,105,103,104,116,115,0,0,0,2,2,90,95,4,0,25,103,108,95,76,105,103,104,116,80,114,111,100, -117,99,116,115,0,0,1,103,108,95,66,97,99,107,76,105,103,104,116,80,114,111,100,117,99,116,0,3,18, -103,108,95,77,97,120,76,105,103,104,116,115,0,0,0,2,2,90,95,4,0,12,0,1,103,108,95,84,101,120,116, -117,114,101,69,110,118,67,111,108,111,114,0,3,18,103,108,95,77,97,120,84,101,120,116,117,114,101, -73,109,97,103,101,85,110,105,116,115,0,0,0,2,2,90,95,4,0,12,0,1,103,108,95,69,121,101,80,108,97, +111,116,68,105,114,101,99,116,105,111,110,0,0,0,1,9,0,115,112,111,116,67,111,115,67,117,116,111, +102,102,0,0,0,1,9,0,99,111,110,115,116,97,110,116,65,116,116,101,110,117,97,116,105,111,110,0,0,0, +1,9,0,108,105,110,101,97,114,65,116,116,101,110,117,97,116,105,111,110,0,0,0,1,9,0,113,117,97,100, +114,97,116,105,99,65,116,116,101,110,117,97,116,105,111,110,0,0,0,1,9,0,115,112,111,116,69,120,112, +111,110,101,110,116,0,0,0,1,9,0,115,112,111,116,67,117,116,111,102,102,0,0,0,0,0,0,0,2,2,90,95,4,0, +25,103,108,95,76,105,103,104,116,83,111,117,114,99,101,80,97,114,97,109,101,116,101,114,115,0,0,1, +103,108,95,76,105,103,104,116,83,111,117,114,99,101,0,3,18,103,108,95,77,97,120,76,105,103,104,116, +115,0,0,0,2,2,90,95,0,0,24,103,108,95,76,105,103,104,116,77,111,100,101,108,80,97,114,97,109,101, +116,101,114,115,0,12,0,97,109,98,105,101,110,116,0,0,0,0,0,0,0,2,2,90,95,4,0,25,103,108,95,76,105, +103,104,116,77,111,100,101,108,80,97,114,97,109,101,116,101,114,115,0,0,1,103,108,95,76,105,103, +104,116,77,111,100,101,108,0,0,0,2,2,90,95,0,0,24,103,108,95,76,105,103,104,116,77,111,100,101,108, +80,114,111,100,117,99,116,115,0,12,0,115,99,101,110,101,67,111,108,111,114,0,0,0,0,0,0,0,2,2,90,95, +4,0,25,103,108,95,76,105,103,104,116,77,111,100,101,108,80,114,111,100,117,99,116,115,0,0,1,103, +108,95,70,114,111,110,116,76,105,103,104,116,77,111,100,101,108,80,114,111,100,117,99,116,0,0,0,2, +2,90,95,4,0,25,103,108,95,76,105,103,104,116,77,111,100,101,108,80,114,111,100,117,99,116,115,0,0, +1,103,108,95,66,97,99,107,76,105,103,104,116,77,111,100,101,108,80,114,111,100,117,99,116,0,0,0,2, +2,90,95,0,0,24,103,108,95,76,105,103,104,116,80,114,111,100,117,99,116,115,0,12,0,97,109,98,105, +101,110,116,0,0,0,1,12,0,100,105,102,102,117,115,101,0,0,0,1,12,0,115,112,101,99,117,108,97,114,0, +0,0,0,0,0,0,2,2,90,95,4,0,25,103,108,95,76,105,103,104,116,80,114,111,100,117,99,116,115,0,0,1,103, +108,95,70,114,111,110,116,76,105,103,104,116,80,114,111,100,117,99,116,0,3,18,103,108,95,77,97,120, +76,105,103,104,116,115,0,0,0,2,2,90,95,4,0,25,103,108,95,76,105,103,104,116,80,114,111,100,117,99, +116,115,0,0,1,103,108,95,66,97,99,107,76,105,103,104,116,80,114,111,100,117,99,116,0,3,18,103,108, +95,77,97,120,76,105,103,104,116,115,0,0,0,2,2,90,95,4,0,12,0,1,103,108,95,84,101,120,116,117,114, +101,69,110,118,67,111,108,111,114,0,3,18,103,108,95,77,97,120,84,101,120,116,117,114,101,73,109,97, +103,101,85,110,105,116,115,0,0,0,2,2,90,95,4,0,12,0,1,103,108,95,69,121,101,80,108,97,110,101,83,0, +3,18,103,108,95,77,97,120,84,101,120,116,117,114,101,67,111,111,114,100,115,0,0,0,2,2,90,95,4,0,12, +0,1,103,108,95,69,121,101,80,108,97,110,101,84,0,3,18,103,108,95,77,97,120,84,101,120,116,117,114, +101,67,111,111,114,100,115,0,0,0,2,2,90,95,4,0,12,0,1,103,108,95,69,121,101,80,108,97,110,101,82,0, +3,18,103,108,95,77,97,120,84,101,120,116,117,114,101,67,111,111,114,100,115,0,0,0,2,2,90,95,4,0,12, +0,1,103,108,95,69,121,101,80,108,97,110,101,81,0,3,18,103,108,95,77,97,120,84,101,120,116,117,114, +101,67,111,111,114,100,115,0,0,0,2,2,90,95,4,0,12,0,1,103,108,95,79,98,106,101,99,116,80,108,97, 110,101,83,0,3,18,103,108,95,77,97,120,84,101,120,116,117,114,101,67,111,111,114,100,115,0,0,0,2,2, -90,95,4,0,12,0,1,103,108,95,69,121,101,80,108,97,110,101,84,0,3,18,103,108,95,77,97,120,84,101,120, -116,117,114,101,67,111,111,114,100,115,0,0,0,2,2,90,95,4,0,12,0,1,103,108,95,69,121,101,80,108,97, -110,101,82,0,3,18,103,108,95,77,97,120,84,101,120,116,117,114,101,67,111,111,114,100,115,0,0,0,2,2, -90,95,4,0,12,0,1,103,108,95,69,121,101,80,108,97,110,101,81,0,3,18,103,108,95,77,97,120,84,101,120, -116,117,114,101,67,111,111,114,100,115,0,0,0,2,2,90,95,4,0,12,0,1,103,108,95,79,98,106,101,99,116, -80,108,97,110,101,83,0,3,18,103,108,95,77,97,120,84,101,120,116,117,114,101,67,111,111,114,100,115, -0,0,0,2,2,90,95,4,0,12,0,1,103,108,95,79,98,106,101,99,116,80,108,97,110,101,84,0,3,18,103,108,95, -77,97,120,84,101,120,116,117,114,101,67,111,111,114,100,115,0,0,0,2,2,90,95,4,0,12,0,1,103,108,95, -79,98,106,101,99,116,80,108,97,110,101,82,0,3,18,103,108,95,77,97,120,84,101,120,116,117,114,101, -67,111,111,114,100,115,0,0,0,2,2,90,95,4,0,12,0,1,103,108,95,79,98,106,101,99,116,80,108,97,110, -101,81,0,3,18,103,108,95,77,97,120,84,101,120,116,117,114,101,67,111,111,114,100,115,0,0,0,2,2,90, -95,0,0,24,103,108,95,70,111,103,80,97,114,97,109,101,116,101,114,115,0,12,0,99,111,108,111,114,0,0, -0,1,9,0,100,101,110,115,105,116,121,0,0,0,1,9,0,115,116,97,114,116,0,0,0,1,9,0,101,110,100,0,0,0,1, -9,0,115,99,97,108,101,0,0,0,0,0,0,0,2,2,90,95,4,0,25,103,108,95,70,111,103,80,97,114,97,109,101, -116,101,114,115,0,0,1,103,108,95,70,111,103,0,0,0,1,90,95,0,0,9,0,0,114,97,100,105,97,110,115,0,1, -1,0,0,9,0,100,101,103,0,0,0,1,3,2,90,95,1,0,9,0,1,99,0,2,17,51,0,49,52,49,53,57,50,54,0,0,17,49,56, -48,0,48,0,0,49,0,0,4,118,101,99,52,95,109,117,108,116,105,112,108,121,0,18,95,95,114,101,116,86,97, -108,0,0,18,100,101,103,0,0,18,99,0,0,0,0,1,90,95,0,0,10,0,0,114,97,100,105,97,110,115,0,1,1,0,0,10, -0,100,101,103,0,0,0,1,3,2,90,95,1,0,9,0,1,99,0,2,17,51,0,49,52,49,53,57,50,54,0,0,17,49,56,48,0,48, -0,0,49,0,0,4,118,101,99,52,95,109,117,108,116,105,112,108,121,0,18,95,95,114,101,116,86,97,108,0, -59,120,121,0,0,18,100,101,103,0,59,120,121,0,0,18,99,0,59,120,120,0,0,0,0,1,90,95,0,0,11,0,0,114, -97,100,105,97,110,115,0,1,1,0,0,11,0,100,101,103,0,0,0,1,3,2,90,95,1,0,9,0,1,99,0,2,17,51,0,49,52, -49,53,57,50,54,0,0,17,49,56,48,0,48,0,0,49,0,0,4,118,101,99,52,95,109,117,108,116,105,112,108,121, -0,18,95,95,114,101,116,86,97,108,0,59,120,121,122,0,0,18,100,101,103,0,59,120,121,122,0,0,18,99,0, -59,120,120,120,0,0,0,0,1,90,95,0,0,12,0,0,114,97,100,105,97,110,115,0,1,1,0,0,12,0,100,101,103,0,0, -0,1,3,2,90,95,1,0,9,0,1,99,0,2,17,51,0,49,52,49,53,57,50,54,0,0,17,49,56,48,0,48,0,0,49,0,0,4,118, +90,95,4,0,12,0,1,103,108,95,79,98,106,101,99,116,80,108,97,110,101,84,0,3,18,103,108,95,77,97,120, +84,101,120,116,117,114,101,67,111,111,114,100,115,0,0,0,2,2,90,95,4,0,12,0,1,103,108,95,79,98,106, +101,99,116,80,108,97,110,101,82,0,3,18,103,108,95,77,97,120,84,101,120,116,117,114,101,67,111,111, +114,100,115,0,0,0,2,2,90,95,4,0,12,0,1,103,108,95,79,98,106,101,99,116,80,108,97,110,101,81,0,3,18, +103,108,95,77,97,120,84,101,120,116,117,114,101,67,111,111,114,100,115,0,0,0,2,2,90,95,0,0,24,103, +108,95,70,111,103,80,97,114,97,109,101,116,101,114,115,0,12,0,99,111,108,111,114,0,0,0,1,9,0,100, +101,110,115,105,116,121,0,0,0,1,9,0,115,116,97,114,116,0,0,0,1,9,0,101,110,100,0,0,0,1,9,0,115,99, +97,108,101,0,0,0,0,0,0,0,2,2,90,95,4,0,25,103,108,95,70,111,103,80,97,114,97,109,101,116,101,114, +115,0,0,1,103,108,95,70,111,103,0,0,0,1,90,95,0,0,9,0,0,114,97,100,105,97,110,115,0,1,1,0,0,9,0, +100,101,103,0,0,0,1,3,2,90,95,1,0,9,0,1,99,0,2,17,51,0,49,52,49,53,57,50,54,0,0,17,49,56,48,0,48,0, +0,49,0,0,4,118,101,99,52,95,109,117,108,116,105,112,108,121,0,18,95,95,114,101,116,86,97,108,0,0, +18,100,101,103,0,0,18,99,0,0,0,0,1,90,95,0,0,10,0,0,114,97,100,105,97,110,115,0,1,1,0,0,10,0,100, +101,103,0,0,0,1,3,2,90,95,1,0,9,0,1,99,0,2,17,51,0,49,52,49,53,57,50,54,0,0,17,49,56,48,0,48,0,0, +49,0,0,4,118,101,99,52,95,109,117,108,116,105,112,108,121,0,18,95,95,114,101,116,86,97,108,0,59, +120,121,0,0,18,100,101,103,0,59,120,121,0,0,18,99,0,59,120,120,0,0,0,0,1,90,95,0,0,11,0,0,114,97, +100,105,97,110,115,0,1,1,0,0,11,0,100,101,103,0,0,0,1,3,2,90,95,1,0,9,0,1,99,0,2,17,51,0,49,52,49, +53,57,50,54,0,0,17,49,56,48,0,48,0,0,49,0,0,4,118,101,99,52,95,109,117,108,116,105,112,108,121,0, +18,95,95,114,101,116,86,97,108,0,59,120,121,122,0,0,18,100,101,103,0,59,120,121,122,0,0,18,99,0,59, +120,120,120,0,0,0,0,1,90,95,0,0,12,0,0,114,97,100,105,97,110,115,0,1,1,0,0,12,0,100,101,103,0,0,0, +1,3,2,90,95,1,0,9,0,1,99,0,2,17,51,0,49,52,49,53,57,50,54,0,0,17,49,56,48,0,48,0,0,49,0,0,4,118, 101,99,52,95,109,117,108,116,105,112,108,121,0,18,95,95,114,101,116,86,97,108,0,0,18,100,101,103,0, 0,18,99,0,59,120,120,120,120,0,0,0,0,1,90,95,0,0,9,0,0,100,101,103,114,101,101,115,0,1,1,0,0,9,0, 114,97,100,0,0,0,1,3,2,90,95,1,0,9,0,1,99,0,2,17,49,56,48,0,48,0,0,17,51,0,49,52,49,53,57,50,54,0, diff --git a/src/mesa/shader/slang/slang_builtin.c b/src/mesa/shader/slang/slang_builtin.c index db00c54b8a..c0f4c79e13 100644 --- a/src/mesa/shader/slang/slang_builtin.c +++ b/src/mesa/shader/slang/slang_builtin.c @@ -1,8 +1,9 @@ /* * Mesa 3-D graphics library - * Version: 6.5.3 + * Version: 7.3 * * Copyright (C) 2005-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"), @@ -39,6 +40,10 @@ #include "shader/slang/slang_builtin.h" +/** special state token (see below) */ +#define STATE_ARRAY ((gl_state_index) 0xfffff) + + /** * Lookup GL state given a variable name, 0, 1 or 2 indexes and a field. * Allocate room for the state in the given param list and return position @@ -132,6 +137,8 @@ lookup_statevar(const char *var, GLint index1, GLint index2, const char *field, } } else if (strcmp(var, "gl_ClipPlane") == 0) { + if (index1 < 0) + return -1; tokens[0] = STATE_CLIPPLANE; tokens[1] = index1; } @@ -196,8 +203,12 @@ lookup_statevar(const char *var, GLint index1, GLint index2, const char *field, } } else if (strcmp(var, "gl_LightSource") == 0) { + if (!field || index1 < 0) + return -1; + tokens[0] = STATE_LIGHT; tokens[1] = index1; + if (strcmp(field, "ambient") == 0) { tokens[2] = STATE_AMBIENT; } @@ -272,6 +283,9 @@ lookup_statevar(const char *var, GLint index1, GLint index2, const char *field, } else if (strcmp(var, "gl_FrontLightProduct") == 0 || strcmp(var, "gl_BackLightProduct") == 0) { + if (index1 < 0 || !field) + return -1; + tokens[0] = STATE_LIGHTPROD; tokens[1] = index1; /* light number */ if (strcmp(var, "gl_FrontLightProduct") == 0) { @@ -294,45 +308,63 @@ lookup_statevar(const char *var, GLint index1, GLint index2, const char *field, } } else if (strcmp(var, "gl_TextureEnvColor") == 0) { + if (index1 < 0) + return -1; tokens[0] = STATE_TEXENV_COLOR; tokens[1] = index1; } else if (strcmp(var, "gl_EyePlaneS") == 0) { + if (index1 < 0) + return -1; tokens[0] = STATE_TEXGEN; tokens[1] = index1; /* tex unit */ tokens[2] = STATE_TEXGEN_EYE_S; } else if (strcmp(var, "gl_EyePlaneT") == 0) { + if (index1 < 0) + return -1; tokens[0] = STATE_TEXGEN; tokens[1] = index1; /* tex unit */ tokens[2] = STATE_TEXGEN_EYE_T; } else if (strcmp(var, "gl_EyePlaneR") == 0) { + if (index1 < 0) + return -1; tokens[0] = STATE_TEXGEN; tokens[1] = index1; /* tex unit */ tokens[2] = STATE_TEXGEN_EYE_R; } else if (strcmp(var, "gl_EyePlaneQ") == 0) { + if (index1 < 0) + return -1; tokens[0] = STATE_TEXGEN; tokens[1] = index1; /* tex unit */ tokens[2] = STATE_TEXGEN_EYE_Q; } else if (strcmp(var, "gl_ObjectPlaneS") == 0) { + if (index1 < 0) + return -1; tokens[0] = STATE_TEXGEN; tokens[1] = index1; /* tex unit */ tokens[2] = STATE_TEXGEN_OBJECT_S; } else if (strcmp(var, "gl_ObjectPlaneT") == 0) { + if (index1 < 0) + return -1; tokens[0] = STATE_TEXGEN; tokens[1] = index1; /* tex unit */ tokens[2] = STATE_TEXGEN_OBJECT_T; } else if (strcmp(var, "gl_ObjectPlaneR") == 0) { + if (index1 < 0) + return -1; tokens[0] = STATE_TEXGEN; tokens[1] = index1; /* tex unit */ tokens[2] = STATE_TEXGEN_OBJECT_R; } else if (strcmp(var, "gl_ObjectPlaneQ") == 0) { + if (index1 < 0) + return -1; tokens[0] = STATE_TEXGEN; tokens[1] = index1; /* tex unit */ tokens[2] = STATE_TEXGEN_OBJECT_Q; @@ -386,13 +418,222 @@ lookup_statevar(const char *var, GLint index1, GLint index2, const char *field, } + +/** + * Given a variable name and datatype, emit uniform/constant buffer + * entries which will store that state variable. + * For example, if name="gl_LightSource" we'll emit 64 state variable + * vectors/references and return position where that data starts. This will + * allow run-time array indexing into the light source array. + * + * Note that this is a recursive function. + * + * \return -1 if error, else index of start of data in the program parameter list + */ +static GLint +emit_statevars(const char *name, int array_len, + const slang_type_specifier *type, + gl_state_index tokens[STATE_LENGTH], + struct gl_program_parameter_list *paramList) +{ + if (type->type == SLANG_SPEC_ARRAY) { + GLint i, pos; + assert(array_len > 0); + if (strcmp(name, "gl_ClipPlane") == 0) { + tokens[0] = STATE_CLIPPLANE; + } + else if (strcmp(name, "gl_LightSource") == 0) { + tokens[0] = STATE_LIGHT; + } + else if (strcmp(name, "gl_FrontLightProduct") == 0) { + tokens[0] = STATE_LIGHTPROD; + tokens[2] = 0; /* front */ + } + else if (strcmp(name, "gl_BackLightProduct") == 0) { + tokens[0] = STATE_LIGHTPROD; + tokens[2] = 1; /* back */ + } + else if (strcmp(name, "gl_TextureEnvColor") == 0) { + tokens[0] = STATE_TEXENV_COLOR; + } + else if (strcmp(name, "gl_EyePlaneS") == 0) { + tokens[0] = STATE_TEXGEN_EYE_S; + } + else if (strcmp(name, "gl_EyePlaneT") == 0) { + tokens[0] = STATE_TEXGEN_EYE_T; + } + else if (strcmp(name, "gl_EyePlaneR") == 0) { + tokens[0] = STATE_TEXGEN_EYE_R; + } + else if (strcmp(name, "gl_EyePlaneQ") == 0) { + tokens[0] = STATE_TEXGEN_EYE_Q; + } + else if (strcmp(name, "gl_ObjectPlaneS") == 0) { + tokens[0] = STATE_TEXGEN_OBJECT_S; + } + else if (strcmp(name, "gl_ObjectPlaneT") == 0) { + tokens[0] = STATE_TEXGEN_OBJECT_T; + } + else if (strcmp(name, "gl_ObjectPlaneR") == 0) { + tokens[0] = STATE_TEXGEN_OBJECT_R; + } + else if (strcmp(name, "gl_ObjectPlaneQ") == 0) { + tokens[0] = STATE_TEXGEN_OBJECT_Q; + } + else { + return -1; /* invalid array name */ + } + for (i = 0; i < array_len; i++) { + GLint p; + tokens[1] = i; + p = emit_statevars(NULL, 0, type->_array, tokens, paramList); + if (i == 0) + pos = p; + } + return pos; + } + else if (type->type == SLANG_SPEC_STRUCT) { + const slang_variable_scope *fields = type->_struct->fields; + GLuint i, pos; + for (i = 0; i < fields->num_variables; i++) { + const slang_variable *var = fields->variables[i]; + GLint p = emit_statevars(var->a_name, 0, &var->type.specifier, + tokens, paramList); + if (i == 0) + pos = p; + } + return pos; + } + else { + GLint pos; + assert(type->type == SLANG_SPEC_VEC4 || + type->type == SLANG_SPEC_VEC3 || + type->type == SLANG_SPEC_VEC2 || + type->type == SLANG_SPEC_FLOAT || + type->type == SLANG_SPEC_IVEC4 || + type->type == SLANG_SPEC_IVEC3 || + type->type == SLANG_SPEC_IVEC2 || + type->type == SLANG_SPEC_INT); + if (name) { + GLint t; + + if (tokens[0] == STATE_LIGHT) + t = 2; + else if (tokens[0] == STATE_LIGHTPROD) + t = 3; + else + return -1; /* invalid array name */ + + if (strcmp(name, "ambient") == 0) { + tokens[t] = STATE_AMBIENT; + } + else if (strcmp(name, "diffuse") == 0) { + tokens[t] = STATE_DIFFUSE; + } + else if (strcmp(name, "specular") == 0) { + tokens[t] = STATE_SPECULAR; + } + else if (strcmp(name, "position") == 0) { + tokens[t] = STATE_POSITION; + } + else if (strcmp(name, "halfVector") == 0) { + tokens[t] = STATE_HALF_VECTOR; + } + else if (strcmp(name, "spotDirection") == 0) { + tokens[t] = STATE_SPOT_DIRECTION; /* xyz components */ + } + else if (strcmp(name, "spotCosCutoff") == 0) { + tokens[t] = STATE_SPOT_DIRECTION; /* w component */ + } + + else if (strcmp(name, "constantAttenuation") == 0) { + tokens[t] = STATE_ATTENUATION; /* x component */ + } + else if (strcmp(name, "linearAttenuation") == 0) { + tokens[t] = STATE_ATTENUATION; /* y component */ + } + else if (strcmp(name, "quadraticAttenuation") == 0) { + tokens[t] = STATE_ATTENUATION; /* z component */ + } + else if (strcmp(name, "spotExponent") == 0) { + tokens[t] = STATE_ATTENUATION; /* w = spot exponent */ + } + + else if (strcmp(name, "spotCutoff") == 0) { + tokens[t] = STATE_SPOT_CUTOFF; /* x component */ + } + + else { + return -1; /* invalid field name */ + } + } + + pos = _mesa_add_state_reference(paramList, tokens); + return pos; + } + + return 1; +} + + +/** + * Unroll the named built-in uniform variable into a sequence of state + * vars in the given parameter list. + */ +static GLint +alloc_state_var_array(const slang_variable *var, + struct gl_program_parameter_list *paramList) +{ + gl_state_index tokens[STATE_LENGTH]; + GLuint i; + GLint pos; + + /* Initialize the state tokens array. This is very important. + * When we call _mesa_add_state_reference() it'll searches the parameter + * list to see if the given statevar token sequence is already present. + * This is normally a good thing since it prevents redundant values in the + * constant buffer. + * + * But when we're building arrays of state this can be bad. For example, + * consider this fragment of GLSL code: + * foo = gl_LightSource[3].diffuse; + * ... + * bar = gl_LightSource[i].diffuse; + * + * When we unroll the gl_LightSource array (for "bar") we want to re-emit + * gl_LightSource[3].diffuse and not re-use the first instance (from "foo") + * since that would upset the array layout. We handle this situation by + * setting the last token in the state var token array to the special + * value STATE_ARRAY. + * This token will only be set for array state. We can hijack the last + * element in the array for this since it's never used for light, clipplane + * or texture env array state. + */ + for (i = 0; i < STATE_LENGTH; i++) + tokens[i] = 0; + tokens[STATE_LENGTH - 1] = STATE_ARRAY; + + pos = emit_statevars(var->a_name, var->array_len, &var->type.specifier, + tokens, paramList); + + return pos; +} + + + /** * Allocate storage for a pre-defined uniform (a GL state variable). * As a memory-saving optimization, we try to only allocate storage for * state vars that are actually used. - * For example, the "gl_LightSource" uniform is huge. If we only use - * a handful of gl_LightSource fields, we don't want to allocate storage - * for all of gl_LightSource. + * + * Arrays such as gl_LightSource are handled specially. For an expression + * like "gl_LightSource[2].diffuse", we can allocate a single uniform/constant + * slot and return the index. In this case, we return direct=TRUE. + * + * Buf for something like "gl_LightSource[i].diffuse" we don't know the value + * of 'i' at compile time so we need to "unroll" the gl_LightSource array + * into a consecutive sequence of uniform/constant slots so it can be indexed + * at runtime. In this case, we return direct=FALSE. * * Currently, all pre-defined uniforms are in one of these forms: * var @@ -401,52 +642,62 @@ lookup_statevar(const char *var, GLint index1, GLint index2, const char *field, * var[i].field * var[i][j] * - * \return -1 upon error, else position in paramList of the state var/data + * \return -1 upon error, else position in paramList of the state variable/data */ GLint _slang_alloc_statevar(slang_ir_node *n, - struct gl_program_parameter_list *paramList) + struct gl_program_parameter_list *paramList, + GLboolean *direct) { slang_ir_node *n0 = n; - const char *field = NULL, *var; - GLint index1 = -1, index2 = -1, pos; + const char *field = NULL; + GLint index1 = -1, index2 = -1; GLuint swizzle; + *direct = GL_TRUE; + if (n->Opcode == IR_FIELD) { field = n->Field; n = n->Children[0]; } if (n->Opcode == IR_ELEMENT) { - /* XXX can only handle constant indexes for now */ if (n->Children[1]->Opcode == IR_FLOAT) { index1 = (GLint) n->Children[1]->Value[0]; - n = n->Children[0]; } else { - return -1; + *direct = GL_FALSE; } + n = n->Children[0]; } if (n->Opcode == IR_ELEMENT) { /* XXX can only handle constant indexes for now */ - assert(n->Children[1]->Opcode == IR_FLOAT); - index2 = (GLint) n->Children[1]->Value[0]; + if (n->Children[1]->Opcode == IR_FLOAT) { + index2 = (GLint) n->Children[1]->Value[0]; + } + else { + *direct = GL_FALSE; + } n = n->Children[0]; } assert(n->Opcode == IR_VAR); - var = (char *) n->Var->a_name; - pos = lookup_statevar(var, index1, index2, field, &swizzle, paramList); - assert(pos >= 0); - if (pos >= 0) { - /* newly resolved storage for the statevar/constant/uniform */ - n0->Store->File = PROGRAM_STATE_VAR; - n0->Store->Index = pos; - n0->Store->Swizzle = swizzle; - n0->Store->Parent = NULL; + if (*direct) { + const char *var = (const char *) n->Var->a_name; + GLint pos = + lookup_statevar(var, index1, index2, field, &swizzle, paramList); + if (pos >= 0) { + /* newly resolved storage for the statevar/constant/uniform */ + n0->Store->File = PROGRAM_STATE_VAR; + n0->Store->Index = pos; + n0->Store->Swizzle = swizzle; + n0->Store->Parent = NULL; + return pos; + } } - return pos; -} + *direct = GL_FALSE; + return alloc_state_var_array(n->Var, paramList); +} diff --git a/src/mesa/shader/slang/slang_builtin.h b/src/mesa/shader/slang/slang_builtin.h index 58629f4f7f..7f6fe80fcc 100644 --- a/src/mesa/shader/slang/slang_builtin.h +++ b/src/mesa/shader/slang/slang_builtin.h @@ -33,7 +33,8 @@ extern GLint _slang_alloc_statevar(slang_ir_node *n, - struct gl_program_parameter_list *paramList); + struct gl_program_parameter_list *paramList, + GLboolean *direct); #endif /* SLANG_BUILTIN_H */ diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c index 6587f9cf27..500112b6f6 100644 --- a/src/mesa/shader/slang/slang_emit.c +++ b/src/mesa/shader/slang/slang_emit.c @@ -348,6 +348,10 @@ storage_to_src_reg(struct prog_src_register *src, const slang_ir_storage *st) assert(index >= 0); while (st->Parent) { st = st->Parent; + if (st->Index < 0) { + /* an error should have been reported already */ + return; + } assert(st->Index >= 0); index += st->Index; swizzle = _slang_swizzle_swizzle(fix_swizzle(st->Swizzle), swizzle); @@ -1841,9 +1845,17 @@ emit_array_element(slang_emit_info *emitInfo, slang_ir_node *n) root = root->Parent; if (root->File == PROGRAM_STATE_VAR) { - GLint index = _slang_alloc_statevar(n, emitInfo->prog->Parameters); - assert(n->Store->Index == index); - return NULL; + GLboolean direct; + GLint index = + _slang_alloc_statevar(n, emitInfo->prog->Parameters, &direct); + if (index < 0) { + /* error */ + return NULL; + } + if (direct) { + n->Store->Index = index; + return NULL; /* all done */ + } } } @@ -1967,28 +1979,30 @@ emit_struct_field(slang_emit_info *emitInfo, slang_ir_node *n) * space for the ones that we actually use! */ if (root->File == PROGRAM_STATE_VAR) { - root->Index = _slang_alloc_statevar(n, emitInfo->prog->Parameters); - if (root->Index < 0) { + GLboolean direct; + GLint index = _slang_alloc_statevar(n, emitInfo->prog->Parameters, &direct); + if (index < 0) { slang_info_log_error(emitInfo->log, "Error parsing state variable"); return NULL; } - return NULL; - } - else { - /* do codegen for struct */ - emit(emitInfo, n->Children[0]); - assert(n->Children[0]->Store->Index >= 0); + if (direct) { + root->Index = index; + return NULL; /* all done */ + } } + /* do codegen for struct */ + emit(emitInfo, n->Children[0]); + assert(n->Children[0]->Store->Index >= 0); + + fieldOffset = n->Store->Index; fieldSize = n->Store->Size; _slang_copy_ir_storage(n->Store, n->Children[0]->Store); n->Store->Index = n->Children[0]->Store->Index + fieldOffset / 4; - /* XXX test this: - n->Store->Index += fieldOffset / 4; - */ + n->Store->Size = fieldSize; switch (fieldSize) { case 1: @@ -2077,7 +2091,18 @@ emit_var_ref(slang_emit_info *emitInfo, slang_ir_node *n) assert(n->Store->File != PROGRAM_UNDEFINED); if (n->Store->File == PROGRAM_STATE_VAR && n->Store->Index < 0) { - n->Store->Index = _slang_alloc_statevar(n, emitInfo->prog->Parameters); + GLboolean direct; + GLint index = _slang_alloc_statevar(n, emitInfo->prog->Parameters, &direct); + if (index < 0) { + /* error */ + char s[100]; + snprintf(s, sizeof(s), "Undefined variable '%s'", + (char *) n->Var->a_name); + slang_info_log_error(emitInfo->log, s); + return NULL; + } + + n->Store->Index = index; } else if (n->Store->File == PROGRAM_UNIFORM) { /* mark var as used */ diff --git a/src/mesa/shader/slang/slang_link.c b/src/mesa/shader/slang/slang_link.c index 3e97c8672b..1b63659cfd 100644 --- a/src/mesa/shader/slang/slang_link.c +++ b/src/mesa/shader/slang/slang_link.c @@ -240,7 +240,10 @@ link_uniform_vars(struct gl_shader_program *shProg, GLuint sampNum = *numSamplers; GLuint oldSampNum = (GLuint) prog->Parameters->ParameterValues[i][0]; if (oldSampNum >= MAX_SAMPLERS) { - link_error(shProg, "Too many texture samplers"); + char s[100]; + sprintf(s, "Too many texture samplers (%u, max is %u)", + oldSampNum + 1, MAX_SAMPLERS); + link_error(shProg, s); return GL_FALSE; } samplerMap[oldSampNum] = sampNum; |