i965: Fix regs read for FS_OPCODE_INTERP_PER_SLOT_OFFSET
[mesa.git] / src / mesa / drivers / dri / nouveau / nv20_state_tnl.c
index 28745849d43051f5a30ab50160cbe10abfb8acd1..f0acbed8560f5a7aa9aa6a5a990f704583a3fdc1 100644 (file)
@@ -88,12 +88,11 @@ get_material_bitmask(unsigned m)
 void
 nv20_emit_color_material(struct gl_context *ctx, int emit)
 {
-       struct nouveau_channel *chan = context_chan(ctx);
-       struct nouveau_grobj *kelvin = context_eng3d(ctx);
-       unsigned mask = get_material_bitmask(ctx->Light.ColorMaterialBitmask);
+       struct nouveau_pushbuf *push = context_push(ctx);
+       unsigned mask = get_material_bitmask(ctx->Light._ColorMaterialBitmask);
 
-       BEGIN_RING(chan, kelvin, NV20_3D_COLOR_MATERIAL, 1);
-       OUT_RING(chan, ctx->Light.ColorMaterialEnabled ? mask : 0);
+       BEGIN_NV04(push, NV20_3D(COLOR_MATERIAL), 1);
+       PUSH_DATA (push, ctx->Light.ColorMaterialEnabled ? mask : 0);
 }
 
 static unsigned
@@ -127,13 +126,22 @@ get_fog_mode_unsigned(unsigned mode)
 }
 
 static unsigned
-get_fog_source(unsigned source)
+get_fog_source(unsigned source, unsigned distance_mode)
 {
        switch (source) {
        case GL_FOG_COORDINATE_EXT:
                return NV20_3D_FOG_COORD_FOG;
        case GL_FRAGMENT_DEPTH_EXT:
-               return NV20_3D_FOG_COORD_DIST_ORTHOGONAL_ABS;
+               switch (distance_mode) {
+               case GL_EYE_PLANE_ABSOLUTE_NV:
+                       return NV20_3D_FOG_COORD_DIST_ORTHOGONAL_ABS;
+               case GL_EYE_PLANE:
+                       return NV20_3D_FOG_COORD_DIST_ORTHOGONAL;
+               case GL_EYE_RADIAL_NV:
+                       return NV20_3D_FOG_COORD_DIST_RADIAL;
+               default:
+                       assert(0);
+               }
        default:
                assert(0);
        }
@@ -143,8 +151,7 @@ void
 nv20_emit_fog(struct gl_context *ctx, int emit)
 {
        struct nouveau_context *nctx = to_nouveau_context(ctx);
-       struct nouveau_channel *chan = context_chan(ctx);
-       struct nouveau_grobj *kelvin = context_eng3d(ctx);
+       struct nouveau_pushbuf *push = context_push(ctx);
        struct gl_fog_attrib *f = &ctx->Fog;
        unsigned source = nctx->fallback == HWTNL ?
                f->FogCoordinateSource : GL_FOG_COORDINATE_EXT;
@@ -152,63 +159,62 @@ nv20_emit_fog(struct gl_context *ctx, int emit)
 
        nv10_get_fog_coeff(ctx, k);
 
-       BEGIN_RING(chan, kelvin, NV20_3D_FOG_MODE, 4);
-       OUT_RING(chan, (source == GL_FOG_COORDINATE_EXT ?
-                       get_fog_mode_signed(f->Mode) :
-                       get_fog_mode_unsigned(f->Mode)));
-       OUT_RING(chan, get_fog_source(source));
-       OUT_RING(chan, f->Enabled ? 1 : 0);
-       OUT_RING(chan, pack_rgba_f(MESA_FORMAT_RGBA8888_REV, f->Color));
-
-       BEGIN_RING(chan, kelvin, NV20_3D_FOG_COEFF(0), 3);
-       OUT_RINGp(chan, k, 3);
+       BEGIN_NV04(push, NV20_3D(FOG_MODE), 4);
+       PUSH_DATA (push, ((source == GL_FRAGMENT_DEPTH_EXT &&
+                        f->FogDistanceMode == GL_EYE_PLANE_ABSOLUTE_NV) ?
+                       get_fog_mode_unsigned(f->Mode) :
+                       get_fog_mode_signed(f->Mode)));
+       PUSH_DATA (push, get_fog_source(source, f->FogDistanceMode));
+       PUSH_DATAb(push, f->Enabled);
+       PUSH_DATA (push, pack_rgba_f(MESA_FORMAT_R8G8B8A8_UNORM, f->Color));
+
+       BEGIN_NV04(push, NV20_3D(FOG_COEFF(0)), 3);
+       PUSH_DATAp(push, k, 3);
 }
 
 void
 nv20_emit_light_model(struct gl_context *ctx, int emit)
 {
-       struct nouveau_channel *chan = context_chan(ctx);
-       struct nouveau_grobj *kelvin = context_eng3d(ctx);
+       struct nouveau_pushbuf *push = context_push(ctx);
        struct gl_lightmodel *m = &ctx->Light.Model;
 
-       BEGIN_RING(chan, kelvin, NV20_3D_SEPARATE_SPECULAR_ENABLE, 1);
-       OUT_RING(chan, m->ColorControl == GL_SEPARATE_SPECULAR_COLOR ? 1 : 0);
+       BEGIN_NV04(push, NV20_3D(SEPARATE_SPECULAR_ENABLE), 1);
+       PUSH_DATAb(push, m->ColorControl == GL_SEPARATE_SPECULAR_COLOR);
 
-       BEGIN_RING(chan, kelvin, NV20_3D_LIGHT_MODEL, 1);
-       OUT_RING(chan, ((m->LocalViewer ?
+       BEGIN_NV04(push, NV20_3D(LIGHT_MODEL), 1);
+       PUSH_DATA (push, ((m->LocalViewer ?
                         NV20_3D_LIGHT_MODEL_VIEWER_LOCAL :
                         NV20_3D_LIGHT_MODEL_VIEWER_NONLOCAL) |
-                       (NEED_SECONDARY_COLOR(ctx) ?
+                       (_mesa_need_secondary_color(ctx) ?
                         NV20_3D_LIGHT_MODEL_SEPARATE_SPECULAR :
                         0)));
 
-       BEGIN_RING(chan, kelvin, NV20_3D_LIGHT_MODEL_TWO_SIDE_ENABLE, 1);
-       OUT_RING(chan, ctx->Light.Model.TwoSide ? 1 : 0);
+       BEGIN_NV04(push, NV20_3D(LIGHT_MODEL_TWO_SIDE_ENABLE), 1);
+       PUSH_DATAb(push, ctx->Light.Model.TwoSide);
 }
 
 void
 nv20_emit_light_source(struct gl_context *ctx, int emit)
 {
        const int i = emit - NOUVEAU_STATE_LIGHT_SOURCE0;
-       struct nouveau_channel *chan = context_chan(ctx);
-       struct nouveau_grobj *kelvin = context_eng3d(ctx);
+       struct nouveau_pushbuf *push = context_push(ctx);
        struct gl_light *l = &ctx->Light.Light[i];
 
        if (l->_Flags & LIGHT_POSITIONAL) {
-               BEGIN_RING(chan, kelvin, NV20_3D_LIGHT_POSITION_X(i), 3);
-               OUT_RINGp(chan, l->_Position, 3);
+               BEGIN_NV04(push, NV20_3D(LIGHT_POSITION_X(i)), 3);
+               PUSH_DATAp(push, l->_Position, 3);
 
-               BEGIN_RING(chan, kelvin, NV20_3D_LIGHT_ATTENUATION_CONSTANT(i), 3);
-               OUT_RINGf(chan, l->ConstantAttenuation);
-               OUT_RINGf(chan, l->LinearAttenuation);
-               OUT_RINGf(chan, l->QuadraticAttenuation);
+               BEGIN_NV04(push, NV20_3D(LIGHT_ATTENUATION_CONSTANT(i)), 3);
+               PUSH_DATAf(push, l->ConstantAttenuation);
+               PUSH_DATAf(push, l->LinearAttenuation);
+               PUSH_DATAf(push, l->QuadraticAttenuation);
 
        } else {
-               BEGIN_RING(chan, kelvin, NV20_3D_LIGHT_DIRECTION_X(i), 3);
-               OUT_RINGp(chan, l->_VP_inf_norm, 3);
+               BEGIN_NV04(push, NV20_3D(LIGHT_DIRECTION_X(i)), 3);
+               PUSH_DATAp(push, l->_VP_inf_norm, 3);
 
-               BEGIN_RING(chan, kelvin, NV20_3D_LIGHT_HALF_VECTOR_X(i), 3);
-               OUT_RINGp(chan, l->_h_inf_norm, 3);
+               BEGIN_NV04(push, NV20_3D(LIGHT_HALF_VECTOR_X(i)), 3);
+               PUSH_DATAp(push, l->_h_inf_norm, 3);
        }
 
        if (l->_Flags & LIGHT_SPOT) {
@@ -216,21 +222,20 @@ nv20_emit_light_source(struct gl_context *ctx, int emit)
 
                nv10_get_spot_coeff(l, k);
 
-               BEGIN_RING(chan, kelvin, NV20_3D_LIGHT_SPOT_CUTOFF(i, 0), 7);
-               OUT_RINGp(chan, k, 7);
+               BEGIN_NV04(push, NV20_3D(LIGHT_SPOT_CUTOFF(i, 0)), 7);
+               PUSH_DATAp(push, k, 7);
        }
 }
 
 #define USE_COLOR_MATERIAL(attr, side)                                 \
        (ctx->Light.ColorMaterialEnabled &&                             \
-        ctx->Light.ColorMaterialBitmask & (1 << MAT_ATTRIB_##attr(side)))
+        ctx->Light._ColorMaterialBitmask & (1 << MAT_ATTRIB_##attr(side)))
 
 void
 nv20_emit_material_ambient(struct gl_context *ctx, int emit)
 {
        const int side = emit - NOUVEAU_STATE_MATERIAL_FRONT_AMBIENT;
-       struct nouveau_channel *chan = context_chan(ctx);
-       struct nouveau_grobj *kelvin = context_eng3d(ctx);
+       struct nouveau_pushbuf *push = context_push(ctx);
        float (*mat)[4] = ctx->Light.Material.Attrib;
        float c_scene[3], c_factor[3];
        struct gl_light *l;
@@ -249,12 +254,12 @@ nv20_emit_material_ambient(struct gl_context *ctx, int emit)
                ZERO_3V(c_factor);
        }
 
-       BEGIN_RING(chan, kelvin, LIGHT_MODEL_AMBIENT_R(side), 3);
-       OUT_RINGp(chan, c_scene, 3);
+       BEGIN_NV04(push, SUBC_3D(LIGHT_MODEL_AMBIENT_R(side)), 3);
+       PUSH_DATAp(push, c_scene, 3);
 
        if (ctx->Light.ColorMaterialEnabled) {
-               BEGIN_RING(chan, kelvin, MATERIAL_FACTOR_R(side), 3);
-               OUT_RINGp(chan, c_factor, 3);
+               BEGIN_NV04(push, SUBC_3D(MATERIAL_FACTOR_R(side)), 3);
+               PUSH_DATAp(push, c_factor, 3);
        }
 
        foreach(l, &ctx->Light.EnabledList) {
@@ -263,8 +268,8 @@ nv20_emit_material_ambient(struct gl_context *ctx, int emit)
                                  l->Ambient :
                                  l->_MatAmbient[side]);
 
-               BEGIN_RING(chan, kelvin, LIGHT_AMBIENT_R(side, i), 3);
-               OUT_RINGp(chan, c_light, 3);
+               BEGIN_NV04(push, SUBC_3D(LIGHT_AMBIENT_R(side, i)), 3);
+               PUSH_DATAp(push, c_light, 3);
        }
 }
 
@@ -272,13 +277,12 @@ void
 nv20_emit_material_diffuse(struct gl_context *ctx, int emit)
 {
        const int side = emit - NOUVEAU_STATE_MATERIAL_FRONT_DIFFUSE;
-       struct nouveau_channel *chan = context_chan(ctx);
-       struct nouveau_grobj *kelvin = context_eng3d(ctx);
+       struct nouveau_pushbuf *push = context_push(ctx);
        GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
        struct gl_light *l;
 
-       BEGIN_RING(chan, kelvin, MATERIAL_FACTOR_A(side), 1);
-       OUT_RINGf(chan, mat[MAT_ATTRIB_DIFFUSE(side)][3]);
+       BEGIN_NV04(push, SUBC_3D(MATERIAL_FACTOR_A(side)), 1);
+       PUSH_DATAf(push, mat[MAT_ATTRIB_DIFFUSE(side)][3]);
 
        foreach(l, &ctx->Light.EnabledList) {
                const int i = l - ctx->Light.Light;
@@ -286,8 +290,8 @@ nv20_emit_material_diffuse(struct gl_context *ctx, int emit)
                                  l->Diffuse :
                                  l->_MatDiffuse[side]);
 
-               BEGIN_RING(chan, kelvin, LIGHT_DIFFUSE_R(side, i), 3);
-               OUT_RINGp(chan, c_light, 3);
+               BEGIN_NV04(push, SUBC_3D(LIGHT_DIFFUSE_R(side, i)), 3);
+               PUSH_DATAp(push, c_light, 3);
        }
 }
 
@@ -295,8 +299,7 @@ void
 nv20_emit_material_specular(struct gl_context *ctx, int emit)
 {
        const int side = emit - NOUVEAU_STATE_MATERIAL_FRONT_SPECULAR;
-       struct nouveau_channel *chan = context_chan(ctx);
-       struct nouveau_grobj *kelvin = context_eng3d(ctx);
+       struct nouveau_pushbuf *push = context_push(ctx);
        struct gl_light *l;
 
        foreach(l, &ctx->Light.EnabledList) {
@@ -305,8 +308,8 @@ nv20_emit_material_specular(struct gl_context *ctx, int emit)
                                  l->Specular :
                                  l->_MatSpecular[side]);
 
-               BEGIN_RING(chan, kelvin, LIGHT_SPECULAR_R(side, i), 3);
-               OUT_RINGp(chan, c_light, 3);
+               BEGIN_NV04(push, SUBC_3D(LIGHT_SPECULAR_R(side, i)), 3);
+               PUSH_DATAp(push, c_light, 3);
        }
 }
 
@@ -314,8 +317,7 @@ void
 nv20_emit_material_shininess(struct gl_context *ctx, int emit)
 {
        const int side = emit - NOUVEAU_STATE_MATERIAL_FRONT_SHININESS;
-       struct nouveau_channel *chan = context_chan(ctx);
-       struct nouveau_grobj *kelvin = context_eng3d(ctx);
+       struct nouveau_pushbuf *push = context_push(ctx);
        float (*mat)[4] = ctx->Light.Material.Attrib;
        float k[6];
 
@@ -323,16 +325,15 @@ nv20_emit_material_shininess(struct gl_context *ctx, int emit)
                CLAMP(mat[MAT_ATTRIB_SHININESS(side)][0], 0, 1024),
                k);
 
-       BEGIN_RING(chan, kelvin, MATERIAL_SHININESS(side), 6);
-       OUT_RINGp(chan, k, 6);
+       BEGIN_NV04(push, SUBC_3D(MATERIAL_SHININESS(side)), 6);
+       PUSH_DATAp(push, k, 6);
 }
 
 void
 nv20_emit_modelview(struct gl_context *ctx, int emit)
 {
        struct nouveau_context *nctx = to_nouveau_context(ctx);
-       struct nouveau_channel *chan = context_chan(ctx);
-       struct nouveau_grobj *kelvin = context_eng3d(ctx);
+       struct nouveau_pushbuf *push = context_push(ctx);
        GLmatrix *m = ctx->ModelviewMatrixStack.Top;
 
        if (nctx->fallback != HWTNL)
@@ -340,19 +341,18 @@ nv20_emit_modelview(struct gl_context *ctx, int emit)
 
        if (ctx->Light._NeedEyeCoords || ctx->Fog.Enabled ||
            (ctx->Texture._GenFlags & TEXGEN_NEED_EYE_COORD)) {
-               BEGIN_RING(chan, kelvin, NV20_3D_MODELVIEW_MATRIX(0, 0), 16);
-               OUT_RINGm(chan, m->m);
+               BEGIN_NV04(push, NV20_3D(MODELVIEW_MATRIX(0, 0)), 16);
+               PUSH_DATAm(push, m->m);
        }
 
        if (ctx->Light.Enabled ||
            (ctx->Texture._GenFlags & TEXGEN_NEED_EYE_COORD)) {
                int i, j;
 
-               BEGIN_RING(chan, kelvin,
-                          NV20_3D_INVERSE_MODELVIEW_MATRIX(0, 0), 12);
+               BEGIN_NV04(push, NV20_3D(INVERSE_MODELVIEW_MATRIX(0, 0)), 12);
                for (i = 0; i < 3; i++)
                        for (j = 0; j < 4; j++)
-                               OUT_RINGf(chan, m->inv[4*i + j]);
+                               PUSH_DATAf(push, m->inv[4*i + j]);
        }
 }
 
@@ -360,8 +360,7 @@ void
 nv20_emit_projection(struct gl_context *ctx, int emit)
 {
        struct nouveau_context *nctx = to_nouveau_context(ctx);
-       struct nouveau_channel *chan = context_chan(ctx);
-       struct nouveau_grobj *kelvin = context_eng3d(ctx);
+       struct nouveau_pushbuf *push = context_push(ctx);
        GLmatrix m;
 
        _math_matrix_ctr(&m);
@@ -370,8 +369,8 @@ nv20_emit_projection(struct gl_context *ctx, int emit)
        if (nctx->fallback == HWTNL)
                _math_matrix_mul_matrix(&m, &m, &ctx->_ModelProjectMatrix);
 
-       BEGIN_RING(chan, kelvin, NV20_3D_PROJECTION_MATRIX(0), 16);
-       OUT_RINGm(chan, m.m);
+       BEGIN_NV04(push, NV20_3D(PROJECTION_MATRIX(0)), 16);
+       PUSH_DATAm(push, m.m);
 
        _math_matrix_dtr(&m);
 }