mesa: Change many Type A MESA_FORMATs to meet naming standard
[mesa.git] / src / mesa / drivers / dri / nouveau / nv10_state_frag.c
index 76b95fdd518094e37ee0814c0b75f6279aa9f703..10f067fdec160f6a49cec5147b7be64547cd1cf0 100644 (file)
@@ -27,7 +27,7 @@
 #include "nouveau_driver.h"
 #include "nouveau_context.h"
 #include "nouveau_gldefs.h"
-#include "nouveau_class.h"
+#include "nv10_3d.xml.h"
 #include "nouveau_util.h"
 #include "nv10_driver.h"
 #include "nv20_driver.h"
 #define RC_IN_SHIFT_G  40
 
 #define RC_IN_SOURCE(source)                           \
-       ((uint64_t)NV10TCL_RC_IN_RGB_D_INPUT_##source)
+       ((uint64_t)NV10_3D_RC_IN_RGB_D_INPUT_##source)
 #define RC_IN_USAGE(usage)                                     \
-       ((uint64_t)NV10TCL_RC_IN_RGB_D_COMPONENT_USAGE_##usage)
+       ((uint64_t)NV10_3D_RC_IN_RGB_D_COMPONENT_USAGE_##usage)
 #define RC_IN_MAPPING(mapping)                                 \
-       ((uint64_t)NV10TCL_RC_IN_RGB_D_MAPPING_##mapping)
+       ((uint64_t)NV10_3D_RC_IN_RGB_D_MAPPING_##mapping)
 
-#define RC_OUT_BIAS    NV10TCL_RC_OUT_RGB_BIAS_BIAS_BY_NEGATIVE_ONE_HALF
-#define RC_OUT_SCALE_1 NV10TCL_RC_OUT_RGB_SCALE_NONE
-#define RC_OUT_SCALE_2 NV10TCL_RC_OUT_RGB_SCALE_SCALE_BY_TWO
-#define RC_OUT_SCALE_4 NV10TCL_RC_OUT_RGB_SCALE_SCALE_BY_FOUR
+#define RC_OUT_BIAS    NV10_3D_RC_OUT_RGB_BIAS_BIAS_BY_NEGATIVE_ONE_HALF
+#define RC_OUT_SCALE_1 NV10_3D_RC_OUT_RGB_SCALE_NONE
+#define RC_OUT_SCALE_2 NV10_3D_RC_OUT_RGB_SCALE_SCALE_BY_TWO
+#define RC_OUT_SCALE_4 NV10_3D_RC_OUT_RGB_SCALE_SCALE_BY_FOUR
 
 /* Make the combiner do: spare0_i = A_i * B_i */
-#define RC_OUT_AB      NV10TCL_RC_OUT_RGB_AB_OUTPUT_SPARE0
+#define RC_OUT_AB      NV10_3D_RC_OUT_RGB_AB_OUTPUT_SPARE0
 /* spare0_i = dot3(A, B) */
-#define RC_OUT_DOT_AB  (NV10TCL_RC_OUT_RGB_AB_OUTPUT_SPARE0 |  \
-                        NV10TCL_RC_OUT_RGB_AB_DOT_PRODUCT)
+#define RC_OUT_DOT_AB  (NV10_3D_RC_OUT_RGB_AB_OUTPUT_SPARE0 |  \
+                        NV10_3D_RC_OUT_RGB_AB_DOT_PRODUCT)
 /* spare0_i = A_i * B_i + C_i * D_i */
-#define RC_OUT_SUM     NV10TCL_RC_OUT_RGB_SUM_OUTPUT_SPARE0
+#define RC_OUT_SUM     NV10_3D_RC_OUT_RGB_SUM_OUTPUT_SPARE0
 
 struct combiner_state {
-       GLcontext *ctx;
+       struct gl_context *ctx;
        int unit;
+       GLboolean premodulate;
 
        /* GL state */
        GLenum mode;
@@ -82,6 +83,7 @@ struct combiner_state {
                        ctx->Texture.Unit[i]._CurrentCombine;   \
                (rc)->ctx = ctx;                                \
                (rc)->unit = i;                                 \
+               (rc)->premodulate = c->_NumArgs##chan == 4;     \
                (rc)->mode = c->Mode##chan;                     \
                (rc)->source = c->Source##chan;                 \
                (rc)->operand = c->Operand##chan;               \
@@ -95,6 +97,9 @@ static uint32_t
 get_input_source(struct combiner_state *rc, int source)
 {
        switch (source) {
+       case GL_ZERO:
+               return RC_IN_SOURCE(ZERO);
+
        case GL_TEXTURE:
                return RC_IN_SOURCE(TEXTURE0) + rc->unit;
 
@@ -165,22 +170,22 @@ get_input_arg(struct combiner_state *rc, int arg, int flags)
                int i = (source == GL_TEXTURE ?
                         rc->unit : source - GL_TEXTURE0);
                struct gl_texture_object *t = rc->ctx->Texture.Unit[i]._Current;
-               gl_format format = t->Image[0][t->BaseLevel]->TexFormat;
+               mesa_format format = t->Image[0][t->BaseLevel]->TexFormat;
 
-               if (format == MESA_FORMAT_A8) {
+               if (format == MESA_FORMAT_A_UNORM8) {
                        /* Emulated using I8. */
                        if (is_color_operand(operand))
                                return RC_IN_SOURCE(ZERO) |
                                        get_input_mapping(rc, operand, flags);
 
-               } else if (format == MESA_FORMAT_L8) {
+               } else if (format == MESA_FORMAT_L_UNORM8) {
                        /* Sometimes emulated using I8. */
                        if (!is_color_operand(operand))
                                return RC_IN_SOURCE(ZERO) |
                                        get_input_mapping(rc, operand,
                                                          flags ^ INVERT);
 
-               } else if (format == MESA_FORMAT_XRGB8888) {
+               } else if (format == MESA_FORMAT_B8G8R8X8_UNORM) {
                        /* Sometimes emulated using ARGB8888. */
                        if (!is_color_operand(operand))
                                return RC_IN_SOURCE(ZERO) |
@@ -228,21 +233,21 @@ setup_combiner(struct combiner_state *rc)
                break;
 
        case GL_ADD:
-               INPUT_ARG(rc, A, 0, 0);
-               INPUT_ONE(rc, B, 0);
-               INPUT_ARG(rc, C, 1, 0);
-               INPUT_ONE(rc, D, 0);
-
-               rc->out = RC_OUT_SUM;
-               break;
-
        case GL_ADD_SIGNED:
-               INPUT_ARG(rc, A, 0, 0);
-               INPUT_ONE(rc, B, 0);
-               INPUT_ARG(rc, C, 1, 0);
-               INPUT_ONE(rc, D, 0);
+               if (rc->premodulate) {
+                       INPUT_ARG(rc, A, 0, 0);
+                       INPUT_ARG(rc, B, 1, 0);
+                       INPUT_ARG(rc, C, 2, 0);
+                       INPUT_ARG(rc, D, 3, 0);
+               } else {
+                       INPUT_ARG(rc, A, 0, 0);
+                       INPUT_ONE(rc, B, 0);
+                       INPUT_ARG(rc, C, 1, 0);
+                       INPUT_ONE(rc, D, 0);
+               }
 
-               rc->out = RC_OUT_SUM | RC_OUT_BIAS;
+               rc->out = RC_OUT_SUM |
+                       (rc->mode == GL_ADD_SIGNED ? RC_OUT_BIAS : 0);
                break;
 
        case GL_INTERPOLATE:
@@ -293,7 +298,7 @@ setup_combiner(struct combiner_state *rc)
 }
 
 void
-nv10_get_general_combiner(GLcontext *ctx, int i,
+nv10_get_general_combiner(struct gl_context *ctx, int i,
                          uint32_t *a_in, uint32_t *a_out,
                          uint32_t *c_in, uint32_t *c_out, uint32_t *k)
 {
@@ -314,7 +319,7 @@ nv10_get_general_combiner(GLcontext *ctx, int i,
                rc_a.in = rc_a.out = rc_c.in = rc_c.out = 0;
        }
 
-       *k = pack_rgba_f(MESA_FORMAT_ARGB8888,
+       *k = pack_rgba_f(MESA_FORMAT_B8G8R8A8_UNORM,
                         ctx->Texture.Unit[i].EnvColor);
        *a_in = rc_a.in;
        *a_out = rc_a.out;
@@ -323,7 +328,7 @@ nv10_get_general_combiner(GLcontext *ctx, int i,
 }
 
 void
-nv10_get_final_combiner(GLcontext *ctx, uint64_t *in, int *n)
+nv10_get_final_combiner(struct gl_context *ctx, uint64_t *in, int *n)
 {
        struct combiner_state rc = {};
 
@@ -361,11 +366,10 @@ nv10_get_final_combiner(GLcontext *ctx, uint64_t *in, int *n)
 }
 
 void
-nv10_emit_tex_env(GLcontext *ctx, int emit)
+nv10_emit_tex_env(struct gl_context *ctx, int emit)
 {
        const int i = emit - NOUVEAU_STATE_TEX_ENV0;
-       struct nouveau_channel *chan = context_chan(ctx);
-       struct nouveau_grobj *celsius = context_eng3d(ctx);
+       struct nouveau_pushbuf *push = context_push(ctx);
        uint32_t a_in, a_out, c_in, c_out, k;
 
        nv10_get_general_combiner(ctx, i, &a_in, &a_out, &c_in, &c_out, &k);
@@ -378,31 +382,30 @@ nv10_emit_tex_env(GLcontext *ctx, int emit)
                        c_out |= 0x3 << 27;
        }
 
-       BEGIN_RING(chan, celsius, NV10TCL_RC_IN_ALPHA(i), 1);
-       OUT_RING(chan, a_in);
-       BEGIN_RING(chan, celsius, NV10TCL_RC_IN_RGB(i), 1);
-       OUT_RING(chan, c_in);
-       BEGIN_RING(chan, celsius, NV10TCL_RC_COLOR(i), 1);
-       OUT_RING(chan, k);
-       BEGIN_RING(chan, celsius, NV10TCL_RC_OUT_ALPHA(i), 1);
-       OUT_RING(chan, a_out);
-       BEGIN_RING(chan, celsius, NV10TCL_RC_OUT_RGB(i), 1);
-       OUT_RING(chan, c_out);
+       BEGIN_NV04(push, NV10_3D(RC_IN_ALPHA(i)), 1);
+       PUSH_DATA (push, a_in);
+       BEGIN_NV04(push, NV10_3D(RC_IN_RGB(i)), 1);
+       PUSH_DATA (push, c_in);
+       BEGIN_NV04(push, NV10_3D(RC_COLOR(i)), 1);
+       PUSH_DATA (push, k);
+       BEGIN_NV04(push, NV10_3D(RC_OUT_ALPHA(i)), 1);
+       PUSH_DATA (push, a_out);
+       BEGIN_NV04(push, NV10_3D(RC_OUT_RGB(i)), 1);
+       PUSH_DATA (push, c_out);
 
        context_dirty(ctx, FRAG);
 }
 
 void
-nv10_emit_frag(GLcontext *ctx, int emit)
+nv10_emit_frag(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);
        uint64_t in;
        int n;
 
        nv10_get_final_combiner(ctx, &in, &n);
 
-       BEGIN_RING(chan, celsius, NV10TCL_RC_FINAL0, 2);
-       OUT_RING(chan, in);
-       OUT_RING(chan, in >> 32);
+       BEGIN_NV04(push, NV10_3D(RC_FINAL0), 2);
+       PUSH_DATA (push, in);
+       PUSH_DATA (push, in >> 32);
 }