summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancisco Jerez <[email protected]>2010-02-23 16:15:14 +0100
committerFrancisco Jerez <[email protected]>2010-02-25 18:37:36 +0100
commit7269a30b86745a29bb575ce3545ab82e6514ce2a (patch)
tree7be861341897e4e66c1519cd77e922574b4ec30c
parent323e6bbb052f37f91c7340e16c2352bb780a43d8 (diff)
dri/nouveau: Restructure the nv[12]0 regcombiner code, and fake A8/L8 support.
-rw-r--r--src/mesa/drivers/dri/nouveau/Makefile1
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_util.h18
-rw-r--r--src/mesa/drivers/dri/nouveau/nv10_driver.h8
-rw-r--r--src/mesa/drivers/dri/nouveau/nv10_state_frag.c233
-rw-r--r--src/mesa/drivers/dri/nouveau/nv20_context.c10
-rw-r--r--src/mesa/drivers/dri/nouveau/nv20_driver.h7
-rw-r--r--src/mesa/drivers/dri/nouveau/nv20_state_frag.c73
7 files changed, 221 insertions, 129 deletions
diff --git a/src/mesa/drivers/dri/nouveau/Makefile b/src/mesa/drivers/dri/nouveau/Makefile
index 43bc9f95161..49e89335614 100644
--- a/src/mesa/drivers/dri/nouveau/Makefile
+++ b/src/mesa/drivers/dri/nouveau/Makefile
@@ -42,6 +42,7 @@ DRIVER_SOURCES = \
nv20_state_polygon.c \
nv20_state_raster.c \
nv20_state_tex.c \
+ nv20_state_frag.c \
nv20_state_tnl.c
C_SOURCES = \
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_util.h b/src/mesa/drivers/dri/nouveau/nouveau_util.h
index 076f225fedc..d6007aba2b9 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_util.h
+++ b/src/mesa/drivers/dri/nouveau/nouveau_util.h
@@ -173,4 +173,22 @@ OUT_RINGm(struct nouveau_channel *chan, float m[16])
OUT_RINGf(chan, m[4*j + i]);
}
+static inline GLboolean
+is_color_operand(int op)
+{
+ return op == GL_SRC_COLOR || op == GL_ONE_MINUS_SRC_COLOR;
+}
+
+static inline GLboolean
+is_negative_operand(int op)
+{
+ return op == GL_ONE_MINUS_SRC_COLOR || op == GL_ONE_MINUS_SRC_ALPHA;
+}
+
+static inline GLboolean
+is_texture_source(int s)
+{
+ return s == GL_TEXTURE || (s >= GL_TEXTURE0 && s <= GL_TEXTURE31);
+}
+
#endif
diff --git a/src/mesa/drivers/dri/nouveau/nv10_driver.h b/src/mesa/drivers/dri/nouveau/nv10_driver.h
index 4c220b0373f..b5ab19b3bc0 100644
--- a/src/mesa/drivers/dri/nouveau/nv10_driver.h
+++ b/src/mesa/drivers/dri/nouveau/nv10_driver.h
@@ -119,6 +119,14 @@ nv10_emit_stencil_op(GLcontext *ctx, int emit);
/* nv10_state_frag.c */
void
+nv10_get_general_combiner(GLcontext *ctx, int i,
+ uint32_t *a_in, uint32_t *a_out,
+ uint32_t *c_in, uint32_t *c_out, uint32_t *k);
+
+void
+nv10_get_final_combiner(GLcontext *ctx, uint64_t *in, int *n);
+
+void
nv10_emit_tex_env(GLcontext *ctx, int emit);
void
diff --git a/src/mesa/drivers/dri/nouveau/nv10_state_frag.c b/src/mesa/drivers/dri/nouveau/nv10_state_frag.c
index c1df26ecce6..b56b4ff02cf 100644
--- a/src/mesa/drivers/dri/nouveau/nv10_state_frag.c
+++ b/src/mesa/drivers/dri/nouveau/nv10_state_frag.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 Francisco Jerez.
+ * Copyright (C) 2009-2010 Francisco Jerez.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining
@@ -90,11 +90,11 @@ struct combiner_state {
} while (0)
/* Get the RC input source for the specified EXT_texture_env_combine
- * argument. */
+ * source. */
static uint32_t
-get_input_source(struct combiner_state *rc, int arg)
+get_input_source(struct combiner_state *rc, int source)
{
- switch (rc->source[arg]) {
+ switch (source) {
case GL_TEXTURE:
return RC_IN_SOURCE(TEXTURE0) + rc->unit;
@@ -127,52 +127,69 @@ get_input_source(struct combiner_state *rc, int arg)
}
}
-/* Get the RC input mapping for the specified argument, possibly
- * inverted or biased. */
+/* Get the RC input mapping for the specified texture_env_combine
+ * operand, possibly inverted or biased. */
#define INVERT 0x1
#define HALF_BIAS 0x2
static uint32_t
-get_input_mapping(struct combiner_state *rc, int arg, int flags)
+get_input_mapping(struct combiner_state *rc, int operand, int flags)
{
int map = 0;
- switch (rc->operand[arg]) {
- case GL_SRC_COLOR:
- case GL_ONE_MINUS_SRC_COLOR:
+ if (is_color_operand(operand))
map |= RC_IN_USAGE(RGB);
- break;
-
- case GL_SRC_ALPHA:
- case GL_ONE_MINUS_SRC_ALPHA:
+ else
map |= RC_IN_USAGE(ALPHA);
- break;
- }
- switch (rc->operand[arg]) {
- case GL_SRC_COLOR:
- case GL_SRC_ALPHA:
- map |= (flags & INVERT ? RC_IN_MAPPING(UNSIGNED_INVERT) :
- flags & HALF_BIAS ? RC_IN_MAPPING(HALF_BIAS_NORMAL) :
- RC_IN_MAPPING(UNSIGNED_IDENTITY));
- break;
+ if (is_negative_operand(operand) == !(flags & INVERT))
+ map |= flags & HALF_BIAS ?
+ RC_IN_MAPPING(HALF_BIAS_NEGATE) :
+ RC_IN_MAPPING(UNSIGNED_INVERT);
+ else
+ map |= flags & HALF_BIAS ?
+ RC_IN_MAPPING(HALF_BIAS_NORMAL) :
+ RC_IN_MAPPING(UNSIGNED_IDENTITY);
- case GL_ONE_MINUS_SRC_COLOR:
- case GL_ONE_MINUS_SRC_ALPHA:
- map |= (flags & INVERT ? RC_IN_MAPPING(UNSIGNED_IDENTITY) :
- flags & HALF_BIAS ? RC_IN_MAPPING(HALF_BIAS_NEGATE) :
- RC_IN_MAPPING(UNSIGNED_INVERT));
- break;
+ return map;
+}
+
+static uint32_t
+get_input_arg(struct combiner_state *rc, int arg, int flags)
+{
+ int source = rc->source[arg];
+ int operand = rc->operand[arg];
+
+ /* Fake several unsupported texture formats. */
+ if (is_texture_source(source)) {
+ 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;
+
+ if (format == MESA_FORMAT_A8) {
+ /* 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) {
+ /* Sometimes emulated using I8. */
+ if (!is_color_operand(operand))
+ return RC_IN_SOURCE(ZERO) |
+ get_input_mapping(rc, operand,
+ flags ^ INVERT);
+ }
}
- return map;
+ return get_input_source(rc, source) |
+ get_input_mapping(rc, operand, flags);
}
/* Bind the RC input variable <var> to the EXT_texture_env_combine
* argument <arg>, possibly inverted or biased. */
#define INPUT_ARG(rc, var, arg, flags) \
- (rc)->in |= (get_input_mapping(rc, arg, flags) | \
- get_input_source(rc, arg)) << RC_IN_SHIFT_##var
+ (rc)->in |= get_input_arg(rc, arg, flags) << RC_IN_SHIFT_##var
/* Bind the RC input variable <var> to the RC source <src>. */
#define INPUT_SRC(rc, var, src, chan) \
@@ -268,86 +285,13 @@ setup_combiner(struct combiner_state *rc)
}
}
-/* Write the register combiner state out to the hardware. */
-static void
-nv10_load_combiner(GLcontext *ctx, int i, struct combiner_state *rc_a,
- struct combiner_state *rc_c, uint32_t rc_const)
-{
- struct nouveau_channel *chan = context_chan(ctx);
- struct nouveau_grobj *celsius = context_eng3d(ctx);
-
- /* Enable the combiners we're going to need. */
- if (i == 1) {
- if (rc_c->out || rc_a->out)
- rc_c->out |= 0x5 << 27;
- else
- rc_c->out |= 0x3 << 27;
- }
-
- BEGIN_RING(chan, celsius, NV10TCL_RC_IN_ALPHA(i), 1);
- OUT_RING(chan, rc_a->in);
- BEGIN_RING(chan, celsius, NV10TCL_RC_IN_RGB(i), 1);
- OUT_RING(chan, rc_c->in);
- BEGIN_RING(chan, celsius, NV10TCL_RC_COLOR(i), 1);
- OUT_RING(chan, rc_const);
- BEGIN_RING(chan, celsius, NV10TCL_RC_OUT_ALPHA(i), 1);
- OUT_RING(chan, rc_a->out);
- BEGIN_RING(chan, celsius, NV10TCL_RC_OUT_RGB(i), 1);
- OUT_RING(chan, rc_c->out);
-}
-
-static void
-nv10_load_final(GLcontext *ctx, struct combiner_state *rc, int n)
-{
- struct nouveau_channel *chan = context_chan(ctx);
- struct nouveau_grobj *celsius = context_eng3d(ctx);
-
- BEGIN_RING(chan, celsius, NV10TCL_RC_FINAL0, 2);
- OUT_RING(chan, rc->in);
- OUT_RING(chan, rc->in >> 32);
-}
-
-static void
-nv20_load_combiner(GLcontext *ctx, int i, struct combiner_state *rc_a,
- struct combiner_state *rc_c, uint32_t rc_const)
-{
- struct nouveau_channel *chan = context_chan(ctx);
- struct nouveau_grobj *kelvin = context_eng3d(ctx);
-
- BEGIN_RING(chan, kelvin, NV20TCL_RC_IN_ALPHA(i), 1);
- OUT_RING(chan, rc_a->in);
- BEGIN_RING(chan, kelvin, NV20TCL_RC_OUT_ALPHA(i), 1);
- OUT_RING(chan, rc_a->out);
- BEGIN_RING(chan, kelvin, NV20TCL_RC_IN_RGB(i), 1);
- OUT_RING(chan, rc_c->in);
- BEGIN_RING(chan, kelvin, NV20TCL_RC_OUT_RGB(i), 1);
- OUT_RING(chan, rc_c->out);
- BEGIN_RING(chan, kelvin, NV20TCL_RC_CONSTANT_COLOR0(i), 1);
- OUT_RING(chan, rc_const);
-}
-
-static void
-nv20_load_final(GLcontext *ctx, struct combiner_state *rc, int n)
-{
- struct nouveau_channel *chan = context_chan(ctx);
- struct nouveau_grobj *kelvin = context_eng3d(ctx);
-
- BEGIN_RING(chan, kelvin, NV20TCL_RC_FINAL0, 2);
- OUT_RING(chan, rc->in);
- OUT_RING(chan, rc->in >> 32);
-
- BEGIN_RING(chan, kelvin, NV20TCL_RC_ENABLE, 1);
- OUT_RING(chan, n);
-}
-
void
-nv10_emit_tex_env(GLcontext *ctx, int emit)
+nv10_get_general_combiner(GLcontext *ctx, int i,
+ uint32_t *a_in, uint32_t *a_out,
+ uint32_t *c_in, uint32_t *c_out, uint32_t *k)
{
- const int i = emit - NOUVEAU_STATE_TEX_ENV0;
struct combiner_state rc_a, rc_c;
- uint32_t rc_const;
- /* Compute the new combiner state. */
if (ctx->Texture.Unit[i]._ReallyEnabled) {
INIT_COMBINER(RGB, ctx, &rc_c, i);
@@ -359,26 +303,22 @@ nv10_emit_tex_env(GLcontext *ctx, int emit)
setup_combiner(&rc_c);
setup_combiner(&rc_a);
- rc_const = pack_rgba_f(MESA_FORMAT_ARGB8888,
- ctx->Texture.Unit[i].EnvColor);
-
} else {
- rc_a.in = rc_a.out = rc_c.in = rc_c.out = rc_const = 0;
+ rc_a.in = rc_a.out = rc_c.in = rc_c.out = 0;
}
- if (context_chipset(ctx) >= 0x20)
- nv20_load_combiner(ctx, i, &rc_a, &rc_c, rc_const);
- else
- nv10_load_combiner(ctx, i, &rc_a, &rc_c, rc_const);
-
- context_dirty(ctx, FRAG);
+ *k = pack_rgba_f(MESA_FORMAT_ARGB8888,
+ ctx->Texture.Unit[i].EnvColor);
+ *a_in = rc_a.in;
+ *a_out = rc_a.out;
+ *c_in = rc_c.in;
+ *c_out = rc_c.out;
}
void
-nv10_emit_frag(GLcontext *ctx, int emit)
+nv10_get_final_combiner(GLcontext *ctx, uint64_t *in, int *n)
{
struct combiner_state rc = {};
- int n = log2i(ctx->Texture._EnabledUnits) + 1;
/*
* The final fragment value equation is something like:
@@ -409,8 +349,53 @@ nv10_emit_frag(GLcontext *ctx, int emit)
INPUT_SRC(&rc, G, PRIMARY_COLOR, ALPHA);
}
- if (context_chipset(ctx) >= 0x20)
- nv20_load_final(ctx, &rc, n);
- else
- nv10_load_final(ctx, &rc, n);
+ *in = rc.in;
+ *n = log2i(ctx->Texture._EnabledUnits) + 1;
+}
+
+void
+nv10_emit_tex_env(GLcontext *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);
+ 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);
+
+ /* Enable the combiners we're going to need. */
+ if (i == 1) {
+ if (c_out || a_out)
+ c_out |= 0x5 << 27;
+ else
+ 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);
+
+ context_dirty(ctx, FRAG);
+}
+
+void
+nv10_emit_frag(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *celsius = context_eng3d(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);
}
diff --git a/src/mesa/drivers/dri/nouveau/nv20_context.c b/src/mesa/drivers/dri/nouveau/nv20_context.c
index 82a13fb6ff0..a80062f5f1e 100644
--- a/src/mesa/drivers/dri/nouveau/nv20_context.c
+++ b/src/mesa/drivers/dri/nouveau/nv20_context.c
@@ -449,7 +449,7 @@ const struct nouveau_driver nv20_driver = {
nv10_emit_front_face,
nv10_emit_depth,
nv10_emit_dither,
- nv10_emit_frag,
+ nv20_emit_frag,
nv20_emit_framebuffer,
nv20_emit_fog,
nv10_emit_index_mask,
@@ -487,10 +487,10 @@ const struct nouveau_driver nv20_driver = {
nv10_emit_stencil_func,
nv10_emit_stencil_mask,
nv10_emit_stencil_op,
- nv10_emit_tex_env,
- nv10_emit_tex_env,
- nv10_emit_tex_env,
- nv10_emit_tex_env,
+ nv20_emit_tex_env,
+ nv20_emit_tex_env,
+ nv20_emit_tex_env,
+ nv20_emit_tex_env,
nv10_emit_tex_gen,
nv10_emit_tex_gen,
nv10_emit_tex_gen,
diff --git a/src/mesa/drivers/dri/nouveau/nv20_driver.h b/src/mesa/drivers/dri/nouveau/nv20_driver.h
index f82a292cf7a..18574e9be64 100644
--- a/src/mesa/drivers/dri/nouveau/nv20_driver.h
+++ b/src/mesa/drivers/dri/nouveau/nv20_driver.h
@@ -59,6 +59,13 @@ nv20_emit_point_mode(GLcontext *ctx, int emit);
void
nv20_emit_logic_opcode(GLcontext *ctx, int emit);
+/* nv20_state_frag.c */
+void
+nv20_emit_tex_env(GLcontext *ctx, int emit);
+
+void
+nv20_emit_frag(GLcontext *ctx, int emit);
+
/* nv20_state_tex.c */
void
nv20_emit_tex_obj(GLcontext *ctx, int emit);
diff --git a/src/mesa/drivers/dri/nouveau/nv20_state_frag.c b/src/mesa/drivers/dri/nouveau/nv20_state_frag.c
new file mode 100644
index 00000000000..74803d2ae84
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/nv20_state_frag.c
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2009-2010 Francisco Jerez.
+ * 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 (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 NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) 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.
+ *
+ */
+
+#include "nouveau_driver.h"
+#include "nouveau_context.h"
+#include "nouveau_class.h"
+#include "nv10_driver.h"
+#include "nv20_driver.h"
+
+void
+nv20_emit_tex_env(GLcontext *ctx, int emit)
+{
+ const int i = emit - NOUVEAU_STATE_TEX_ENV0;
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *kelvin = context_eng3d(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);
+
+ BEGIN_RING(chan, kelvin, NV20TCL_RC_IN_ALPHA(i), 1);
+ OUT_RING(chan, a_in);
+ BEGIN_RING(chan, kelvin, NV20TCL_RC_OUT_ALPHA(i), 1);
+ OUT_RING(chan, a_out);
+ BEGIN_RING(chan, kelvin, NV20TCL_RC_IN_RGB(i), 1);
+ OUT_RING(chan, c_in);
+ BEGIN_RING(chan, kelvin, NV20TCL_RC_OUT_RGB(i), 1);
+ OUT_RING(chan, c_out);
+ BEGIN_RING(chan, kelvin, NV20TCL_RC_CONSTANT_COLOR0(i), 1);
+ OUT_RING(chan, k);
+
+ context_dirty(ctx, FRAG);
+}
+
+void
+nv20_emit_frag(GLcontext *ctx, int emit)
+{
+ struct nouveau_channel *chan = context_chan(ctx);
+ struct nouveau_grobj *kelvin = context_eng3d(ctx);
+ uint64_t in;
+ int n;
+
+ nv10_get_final_combiner(ctx, &in, &n);
+
+ BEGIN_RING(chan, kelvin, NV20TCL_RC_FINAL0, 2);
+ OUT_RING(chan, in);
+ OUT_RING(chan, in >> 32);
+
+ BEGIN_RING(chan, kelvin, NV20TCL_RC_ENABLE, 1);
+ OUT_RING(chan, n);
+}