i965/nir/vec4: Implement various rounding functions
[mesa.git] / src / mesa / drivers / dri / nouveau / nv10_state_tnl.c
index 0e592a16292e9aa8c675104e7e2a26415db031c1..1398385b262611e9453a4dfaf886cbc24f47ca42 100644 (file)
 #include "nouveau_context.h"
 #include "nouveau_gldefs.h"
 #include "nouveau_util.h"
-#include "nouveau_class.h"
+#include "nv10_3d.xml.h"
 #include "nv10_driver.h"
 
+#include "util/simple_list.h"
+
 void
-nv10_emit_clip_plane(GLcontext *ctx, int emit)
+nv10_emit_clip_plane(struct gl_context *ctx, int emit)
 {
 }
 
@@ -42,26 +44,25 @@ get_material_bitmask(unsigned m)
        unsigned ret = 0;
 
        if (m & MAT_BIT_FRONT_EMISSION)
-               ret |= NV10TCL_COLOR_MATERIAL_EMISSION;
+               ret |= NV10_3D_COLOR_MATERIAL_EMISSION;
        if (m & MAT_BIT_FRONT_AMBIENT)
-               ret |= NV10TCL_COLOR_MATERIAL_AMBIENT;
+               ret |= NV10_3D_COLOR_MATERIAL_AMBIENT;
        if (m & MAT_BIT_FRONT_DIFFUSE)
-               ret |= NV10TCL_COLOR_MATERIAL_DIFFUSE;
+               ret |= NV10_3D_COLOR_MATERIAL_DIFFUSE;
        if (m & MAT_BIT_FRONT_SPECULAR)
-               ret |= NV10TCL_COLOR_MATERIAL_SPECULAR;
+               ret |= NV10_3D_COLOR_MATERIAL_SPECULAR;
 
        return ret;
 }
 
 void
-nv10_emit_color_material(GLcontext *ctx, int emit)
+nv10_emit_color_material(struct gl_context *ctx, int emit)
 {
-       struct nouveau_channel *chan = context_chan(ctx);
-       struct nouveau_grobj *celsius = 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, celsius, NV10TCL_COLOR_MATERIAL, 1);
-       OUT_RING(chan, ctx->Light.ColorMaterialEnabled ? mask : 0);
+       BEGIN_NV04(push, NV10_3D(COLOR_MATERIAL), 1);
+       PUSH_DATA (push, ctx->Light.ColorMaterialEnabled ? mask : 0);
 }
 
 static unsigned
@@ -69,31 +70,40 @@ get_fog_mode(unsigned mode)
 {
        switch (mode) {
        case GL_LINEAR:
-               return NV10TCL_FOG_MODE_LINEAR;
+               return NV10_3D_FOG_MODE_LINEAR;
        case GL_EXP:
-               return NV10TCL_FOG_MODE_EXP;
+               return NV10_3D_FOG_MODE_EXP;
        case GL_EXP2:
-               return NV10TCL_FOG_MODE_EXP2;
+               return NV10_3D_FOG_MODE_EXP2;
        default:
                assert(0);
        }
 }
 
 static unsigned
-get_fog_source(unsigned source)
+get_fog_source(unsigned source, unsigned distance_mode)
 {
        switch (source) {
        case GL_FOG_COORDINATE_EXT:
-               return NV10TCL_FOG_COORD_FOG;
+               return NV10_3D_FOG_COORD_FOG;
        case GL_FRAGMENT_DEPTH_EXT:
-               return NV10TCL_FOG_COORD_DIST_ORTHOGONAL_ABS;
+               switch (distance_mode) {
+               case GL_EYE_PLANE_ABSOLUTE_NV:
+                       return NV10_3D_FOG_COORD_DIST_ORTHOGONAL_ABS;
+               case GL_EYE_PLANE:
+                       return NV10_3D_FOG_COORD_DIST_ORTHOGONAL;
+               case GL_EYE_RADIAL_NV:
+                       return NV10_3D_FOG_COORD_DIST_RADIAL;
+               default:
+                       assert(0);
+               }
        default:
                assert(0);
        }
 }
 
 void
-nv10_get_fog_coeff(GLcontext *ctx, float k[3])
+nv10_get_fog_coeff(struct gl_context *ctx, float k[3])
 {
        struct gl_fog_attrib *f = &ctx->Fog;
 
@@ -121,11 +131,10 @@ nv10_get_fog_coeff(GLcontext *ctx, float k[3])
 }
 
 void
-nv10_emit_fog(GLcontext *ctx, int emit)
+nv10_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 *celsius = 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;
@@ -133,14 +142,14 @@ nv10_emit_fog(GLcontext *ctx, int emit)
 
        nv10_get_fog_coeff(ctx, k);
 
-       BEGIN_RING(chan, celsius, NV10TCL_FOG_MODE, 4);
-       OUT_RING(chan, get_fog_mode(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_NV04(push, NV10_3D(FOG_MODE), 4);
+       PUSH_DATA (push, get_fog_mode(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_RING(chan, celsius, NV10TCL_FOG_EQUATION_CONSTANT, 3);
-       OUT_RINGp(chan, k, 3);
+       BEGIN_NV04(push, NV10_3D(FOG_COEFF(0)), 3);
+       PUSH_DATAp(push, k, 3);
 
        context_dirty(ctx, FRAG);
 }
@@ -150,59 +159,57 @@ get_light_mode(struct gl_light *l)
 {
        if (l->Enabled) {
                if (l->_Flags & LIGHT_SPOT)
-                       return NV10TCL_ENABLED_LIGHTS_0_DIRECTIONAL;
+                       return NV10_3D_ENABLED_LIGHTS_0_DIRECTIONAL;
                else if (l->_Flags & LIGHT_POSITIONAL)
-                       return NV10TCL_ENABLED_LIGHTS_0_POSITIONAL;
+                       return NV10_3D_ENABLED_LIGHTS_0_POSITIONAL;
                else
-                       return NV10TCL_ENABLED_LIGHTS_0_NONPOSITIONAL;
+                       return NV10_3D_ENABLED_LIGHTS_0_NONPOSITIONAL;
        } else {
-               return NV10TCL_ENABLED_LIGHTS_0_DISABLED;
+               return NV10_3D_ENABLED_LIGHTS_0_DISABLED;
        }
 }
 
 void
-nv10_emit_light_enable(GLcontext *ctx, int emit)
+nv10_emit_light_enable(struct gl_context *ctx, int emit)
 {
        struct nouveau_context *nctx = to_nouveau_context(ctx);
-       struct nouveau_channel *chan = context_chan(ctx);
-       struct nouveau_grobj *celsius = context_eng3d(ctx);
+       struct nouveau_pushbuf *push = context_push(ctx);
        uint32_t en_lights = 0;
        int i;
 
        if (nctx->fallback != HWTNL) {
-               BEGIN_RING(chan, celsius, NV10TCL_LIGHTING_ENABLE, 1);
-               OUT_RING(chan, 0);
+               BEGIN_NV04(push, NV10_3D(LIGHTING_ENABLE), 1);
+               PUSH_DATA (push, 0);
                return;
        }
 
        for (i = 0; i < MAX_LIGHTS; i++)
                en_lights |= get_light_mode(&ctx->Light.Light[i]) << 2 * i;
 
-       BEGIN_RING(chan, celsius, NV10TCL_ENABLED_LIGHTS, 1);
-       OUT_RING(chan, en_lights);
-       BEGIN_RING(chan, celsius, NV10TCL_LIGHTING_ENABLE, 1);
-       OUT_RING(chan, ctx->Light.Enabled ? 1 : 0);
-       BEGIN_RING(chan, celsius, NV10TCL_NORMALIZE_ENABLE, 1);
-       OUT_RING(chan, ctx->Transform.Normalize ? 1 : 0);
+       BEGIN_NV04(push, NV10_3D(ENABLED_LIGHTS), 1);
+       PUSH_DATA (push, en_lights);
+       BEGIN_NV04(push, NV10_3D(LIGHTING_ENABLE), 1);
+       PUSH_DATAb(push, ctx->Light.Enabled);
+       BEGIN_NV04(push, NV10_3D(NORMALIZE_ENABLE), 1);
+       PUSH_DATAb(push, ctx->Transform.Normalize);
 }
 
 void
-nv10_emit_light_model(GLcontext *ctx, int emit)
+nv10_emit_light_model(struct gl_context *ctx, int emit)
 {
-       struct nouveau_channel *chan = context_chan(ctx);
-       struct nouveau_grobj *celsius = context_eng3d(ctx);
+       struct nouveau_pushbuf *push = context_push(ctx);
        struct gl_lightmodel *m = &ctx->Light.Model;
 
-       BEGIN_RING(chan, celsius, NV10TCL_SEPARATE_SPECULAR_ENABLE, 1);
-       OUT_RING(chan, m->ColorControl == GL_SEPARATE_SPECULAR_COLOR ? 1 : 0);
+       BEGIN_NV04(push, NV10_3D(SEPARATE_SPECULAR_ENABLE), 1);
+       PUSH_DATAb(push, m->ColorControl == GL_SEPARATE_SPECULAR_COLOR);
 
-       BEGIN_RING(chan, celsius, NV10TCL_LIGHT_MODEL, 1);
-       OUT_RING(chan, ((m->LocalViewer ?
-                        NV10TCL_LIGHT_MODEL_LOCAL_VIEWER : 0) |
-                       (NEED_SECONDARY_COLOR(ctx) ?
-                        NV10TCL_LIGHT_MODEL_SEPARATE_SPECULAR : 0) |
+       BEGIN_NV04(push, NV10_3D(LIGHT_MODEL), 1);
+       PUSH_DATA (push, ((m->LocalViewer ?
+                        NV10_3D_LIGHT_MODEL_LOCAL_VIEWER : 0) |
+                       (_mesa_need_secondary_color(ctx) ?
+                        NV10_3D_LIGHT_MODEL_SEPARATE_SPECULAR : 0) |
                        (!ctx->Light.Enabled && ctx->Fog.ColorSumEnabled ?
-                        NV10TCL_LIGHT_MODEL_VERTEX_SPECULAR : 0)));
+                        NV10_3D_LIGHT_MODEL_VERTEX_SPECULAR : 0)));
 }
 
 static float
@@ -273,29 +280,27 @@ nv10_get_spot_coeff(struct gl_light *l, float k[7])
 }
 
 void
-nv10_emit_light_source(GLcontext *ctx, int emit)
+nv10_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 *celsius = 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, celsius, NV10TCL_LIGHT_POSITION_X(i), 3);
-               OUT_RINGp(chan, l->_Position, 3);
+               BEGIN_NV04(push, NV10_3D(LIGHT_POSITION_X(i)), 3);
+               PUSH_DATAp(push, l->_Position, 3);
 
-               BEGIN_RING(chan, celsius,
-                          NV10TCL_LIGHT_ATTENUATION_CONSTANT(i), 3);
-               OUT_RINGf(chan, l->ConstantAttenuation);
-               OUT_RINGf(chan, l->LinearAttenuation);
-               OUT_RINGf(chan, l->QuadraticAttenuation);
+               BEGIN_NV04(push, NV10_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, celsius, NV10TCL_LIGHT_DIRECTION_X(i), 3);
-               OUT_RINGp(chan, l->_VP_inf_norm, 3);
+               BEGIN_NV04(push, NV10_3D(LIGHT_DIRECTION_X(i)), 3);
+               PUSH_DATAp(push, l->_VP_inf_norm, 3);
 
-               BEGIN_RING(chan, celsius, NV10TCL_LIGHT_HALF_VECTOR_X(i), 3);
-               OUT_RINGp(chan, l->_h_inf_norm, 3);
+               BEGIN_NV04(push, NV10_3D(LIGHT_HALF_VECTOR_X(i)), 3);
+               PUSH_DATAp(push, l->_h_inf_norm, 3);
        }
 
        if (l->_Flags & LIGHT_SPOT) {
@@ -303,20 +308,19 @@ nv10_emit_light_source(GLcontext *ctx, int emit)
 
                nv10_get_spot_coeff(l, k);
 
-               BEGIN_RING(chan, celsius, NV10TCL_LIGHT_SPOT_CUTOFF_A(i), 7);
-               OUT_RINGp(chan, k, 7);
+               BEGIN_NV04(push, NV10_3D(LIGHT_SPOT_CUTOFF(i, 0)), 7);
+               PUSH_DATAp(push, k, 7);
        }
 }
 
 #define USE_COLOR_MATERIAL(attr)                                       \
        (ctx->Light.ColorMaterialEnabled &&                             \
-        ctx->Light.ColorMaterialBitmask & (1 << MAT_ATTRIB_FRONT_##attr))
+        ctx->Light._ColorMaterialBitmask & (1 << MAT_ATTRIB_FRONT_##attr))
 
 void
-nv10_emit_material_ambient(GLcontext *ctx, int emit)
+nv10_emit_material_ambient(struct gl_context *ctx, int emit)
 {
-       struct nouveau_channel *chan = context_chan(ctx);
-       struct nouveau_grobj *celsius = 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;
@@ -335,12 +339,12 @@ nv10_emit_material_ambient(GLcontext *ctx, int emit)
                ZERO_3V(c_factor);
        }
 
-       BEGIN_RING(chan, celsius, NV10TCL_LIGHT_MODEL_AMBIENT_R, 3);
-       OUT_RINGp(chan, c_scene, 3);
+       BEGIN_NV04(push, NV10_3D(LIGHT_MODEL_AMBIENT_R), 3);
+       PUSH_DATAp(push, c_scene, 3);
 
        if (ctx->Light.ColorMaterialEnabled) {
-               BEGIN_RING(chan, celsius, NV10TCL_MATERIAL_FACTOR_R, 3);
-               OUT_RINGp(chan, c_factor, 3);
+               BEGIN_NV04(push, NV10_3D(MATERIAL_FACTOR_R), 3);
+               PUSH_DATAp(push, c_factor, 3);
        }
 
        foreach(l, &ctx->Light.EnabledList) {
@@ -349,21 +353,20 @@ nv10_emit_material_ambient(GLcontext *ctx, int emit)
                                  l->Ambient :
                                  l->_MatAmbient[0]);
 
-               BEGIN_RING(chan, celsius, NV10TCL_LIGHT_AMBIENT_R(i), 3);
-               OUT_RINGp(chan, c_light, 3);
+               BEGIN_NV04(push, NV10_3D(LIGHT_AMBIENT_R(i)), 3);
+               PUSH_DATAp(push, c_light, 3);
        }
 }
 
 void
-nv10_emit_material_diffuse(GLcontext *ctx, int emit)
+nv10_emit_material_diffuse(struct gl_context *ctx, int emit)
 {
-       struct nouveau_channel *chan = context_chan(ctx);
-       struct nouveau_grobj *celsius = context_eng3d(ctx);
+       struct nouveau_pushbuf *push = context_push(ctx);
        GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
        struct gl_light *l;
 
-       BEGIN_RING(chan, celsius, NV10TCL_MATERIAL_FACTOR_A, 1);
-       OUT_RINGf(chan, mat[MAT_ATTRIB_FRONT_DIFFUSE][3]);
+       BEGIN_NV04(push, NV10_3D(MATERIAL_FACTOR_A), 1);
+       PUSH_DATAf(push, mat[MAT_ATTRIB_FRONT_DIFFUSE][3]);
 
        foreach(l, &ctx->Light.EnabledList) {
                const int i = l - ctx->Light.Light;
@@ -371,16 +374,15 @@ nv10_emit_material_diffuse(GLcontext *ctx, int emit)
                                  l->Diffuse :
                                  l->_MatDiffuse[0]);
 
-               BEGIN_RING(chan, celsius, NV10TCL_LIGHT_DIFFUSE_R(i), 3);
-               OUT_RINGp(chan, c_light, 3);
+               BEGIN_NV04(push, NV10_3D(LIGHT_DIFFUSE_R(i)), 3);
+               PUSH_DATAp(push, c_light, 3);
        }
 }
 
 void
-nv10_emit_material_specular(GLcontext *ctx, int emit)
+nv10_emit_material_specular(struct gl_context *ctx, int emit)
 {
-       struct nouveau_channel *chan = context_chan(ctx);
-       struct nouveau_grobj *celsius = context_eng3d(ctx);
+       struct nouveau_pushbuf *push = context_push(ctx);
        struct gl_light *l;
 
        foreach(l, &ctx->Light.EnabledList) {
@@ -389,8 +391,8 @@ nv10_emit_material_specular(GLcontext *ctx, int emit)
                                  l->Specular :
                                  l->_MatSpecular[0]);
 
-               BEGIN_RING(chan, celsius, NV10TCL_LIGHT_SPECULAR_R(i), 3);
-               OUT_RINGp(chan, c_light, 3);
+               BEGIN_NV04(push, NV10_3D(LIGHT_SPECULAR_R(i)), 3);
+               PUSH_DATAp(push, c_light, 3);
        }
 }
 
@@ -419,10 +421,9 @@ nv10_get_shininess_coeff(float s, float k[6])
 }
 
 void
-nv10_emit_material_shininess(GLcontext *ctx, int emit)
+nv10_emit_material_shininess(struct gl_context *ctx, int emit)
 {
-       struct nouveau_channel *chan = context_chan(ctx);
-       struct nouveau_grobj *celsius = context_eng3d(ctx);
+       struct nouveau_pushbuf *push = context_push(ctx);
        float (*mat)[4] = ctx->Light.Material.Attrib;
        float k[6];
 
@@ -430,16 +431,15 @@ nv10_emit_material_shininess(GLcontext *ctx, int emit)
                CLAMP(mat[MAT_ATTRIB_FRONT_SHININESS][0], 0, 1024),
                k);
 
-       BEGIN_RING(chan, celsius, NV10TCL_MATERIAL_SHININESS(0), 6);
-       OUT_RINGp(chan, k, 6);
+       BEGIN_NV04(push, NV10_3D(MATERIAL_SHININESS(0)), 6);
+       PUSH_DATAp(push, k, 6);
 }
 
 void
-nv10_emit_modelview(GLcontext *ctx, int emit)
+nv10_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 *celsius = context_eng3d(ctx);
+       struct nouveau_pushbuf *push = context_push(ctx);
        GLmatrix *m = ctx->ModelviewMatrixStack.Top;
 
        if (nctx->fallback != HWTNL)
@@ -447,43 +447,44 @@ nv10_emit_modelview(GLcontext *ctx, int emit)
 
        if (ctx->Light._NeedEyeCoords || ctx->Fog.Enabled ||
            (ctx->Texture._GenFlags & TEXGEN_NEED_EYE_COORD)) {
-               BEGIN_RING(chan, celsius, NV10TCL_MODELVIEW0_MATRIX(0), 16);
-               OUT_RINGm(chan, m->m);
+               BEGIN_NV04(push, NV10_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, celsius,
-                          NV10TCL_INVERSE_MODELVIEW0_MATRIX(0), 12);
+               BEGIN_NV04(push, NV10_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]);
        }
 }
 
 void
-nv10_emit_point_parameter(GLcontext *ctx, int emit)
+nv10_emit_point_parameter(struct gl_context *ctx, int emit)
 {
 }
 
 void
-nv10_emit_projection(GLcontext *ctx, int emit)
+nv10_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 *celsius = context_eng3d(ctx);
+       struct nouveau_pushbuf *push = context_push(ctx);
        GLmatrix m;
 
        _math_matrix_ctr(&m);
        get_viewport_scale(ctx, m.m);
 
+       if (nv10_use_viewport_zclear(ctx))
+               m.m[MAT_SZ] /= 8;
+
        if (nctx->fallback == HWTNL)
                _math_matrix_mul_matrix(&m, &m, &ctx->_ModelProjectMatrix);
 
-       BEGIN_RING(chan, celsius, NV10TCL_PROJECTION_MATRIX(0), 16);
-       OUT_RINGm(chan, m.m);
+       BEGIN_NV04(push, NV10_3D(PROJECTION_MATRIX(0)), 16);
+       PUSH_DATAm(push, m.m);
 
        _math_matrix_dtr(&m);
 }