bb1084ed11b04263da42cd949b74be082b31a466
[mesa.git] / src / mesa / drivers / dri / nouveau / nv10_state_raster.c
1 /*
2 * Copyright (C) 2009 Francisco Jerez.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 */
26
27 #include "nouveau_driver.h"
28 #include "nouveau_context.h"
29 #include "nouveau_gldefs.h"
30 #include "nouveau_util.h"
31 #include "nv10_3d.xml.h"
32 #include "nv10_driver.h"
33
34 void
35 nv10_emit_alpha_func(struct gl_context *ctx, int emit)
36 {
37 struct nouveau_channel *chan = context_chan(ctx);
38 struct nouveau_grobj *celsius = context_eng3d(ctx);
39
40 BEGIN_RING(chan, celsius, NV10_3D_ALPHA_FUNC_ENABLE, 1);
41 OUT_RINGb(chan, ctx->Color.AlphaEnabled);
42
43 BEGIN_RING(chan, celsius, NV10_3D_ALPHA_FUNC_FUNC, 2);
44 OUT_RING(chan, nvgl_comparison_op(ctx->Color.AlphaFunc));
45 OUT_RING(chan, FLOAT_TO_UBYTE(ctx->Color.AlphaRef));
46 }
47
48 void
49 nv10_emit_blend_color(struct gl_context *ctx, int emit)
50 {
51 struct nouveau_channel *chan = context_chan(ctx);
52 struct nouveau_grobj *celsius = context_eng3d(ctx);
53
54 BEGIN_RING(chan, celsius, NV10_3D_BLEND_COLOR, 1);
55 OUT_RING(chan, FLOAT_TO_UBYTE(ctx->Color.BlendColor[3]) << 24 |
56 FLOAT_TO_UBYTE(ctx->Color.BlendColor[0]) << 16 |
57 FLOAT_TO_UBYTE(ctx->Color.BlendColor[1]) << 8 |
58 FLOAT_TO_UBYTE(ctx->Color.BlendColor[2]) << 0);
59 }
60
61 void
62 nv10_emit_blend_equation(struct gl_context *ctx, int emit)
63 {
64 struct nouveau_channel *chan = context_chan(ctx);
65 struct nouveau_grobj *celsius = context_eng3d(ctx);
66
67 BEGIN_RING(chan, celsius, NV10_3D_BLEND_FUNC_ENABLE, 1);
68 OUT_RINGb(chan, ctx->Color.BlendEnabled);
69
70 BEGIN_RING(chan, celsius, NV10_3D_BLEND_EQUATION, 1);
71 OUT_RING(chan, nvgl_blend_eqn(ctx->Color.BlendEquationRGB));
72 }
73
74 void
75 nv10_emit_blend_func(struct gl_context *ctx, int emit)
76 {
77 struct nouveau_channel *chan = context_chan(ctx);
78 struct nouveau_grobj *celsius = context_eng3d(ctx);
79
80 BEGIN_RING(chan, celsius, NV10_3D_BLEND_FUNC_SRC, 2);
81 OUT_RING(chan, nvgl_blend_func(ctx->Color.BlendSrcRGB));
82 OUT_RING(chan, nvgl_blend_func(ctx->Color.BlendDstRGB));
83 }
84
85 void
86 nv10_emit_color_mask(struct gl_context *ctx, int emit)
87 {
88 struct nouveau_channel *chan = context_chan(ctx);
89 struct nouveau_grobj *celsius = context_eng3d(ctx);
90
91 BEGIN_RING(chan, celsius, NV10_3D_COLOR_MASK, 1);
92 OUT_RING(chan, ((ctx->Color.ColorMask[0][3] ? 1 << 24 : 0) |
93 (ctx->Color.ColorMask[0][0] ? 1 << 16 : 0) |
94 (ctx->Color.ColorMask[0][1] ? 1 << 8 : 0) |
95 (ctx->Color.ColorMask[0][2] ? 1 << 0 : 0)));
96 }
97
98 void
99 nv10_emit_depth(struct gl_context *ctx, int emit)
100 {
101 struct nouveau_channel *chan = context_chan(ctx);
102 struct nouveau_grobj *celsius = context_eng3d(ctx);
103
104 BEGIN_RING(chan, celsius, NV10_3D_DEPTH_TEST_ENABLE, 1);
105 OUT_RINGb(chan, ctx->Depth.Test);
106 BEGIN_RING(chan, celsius, NV10_3D_DEPTH_WRITE_ENABLE, 1);
107 OUT_RINGb(chan, ctx->Depth.Mask);
108 BEGIN_RING(chan, celsius, NV10_3D_DEPTH_FUNC, 1);
109 OUT_RING(chan, nvgl_comparison_op(ctx->Depth.Func));
110 }
111
112 void
113 nv10_emit_dither(struct gl_context *ctx, int emit)
114 {
115 struct nouveau_channel *chan = context_chan(ctx);
116 struct nouveau_grobj *celsius = context_eng3d(ctx);
117
118 BEGIN_RING(chan, celsius, NV10_3D_DITHER_ENABLE, 1);
119 OUT_RINGb(chan, ctx->Color.DitherFlag);
120 }
121
122 void
123 nv10_emit_logic_opcode(struct gl_context *ctx, int emit)
124 {
125 struct nouveau_channel *chan = context_chan(ctx);
126 struct nouveau_grobj *celsius = context_eng3d(ctx);
127
128 assert(!ctx->Color.ColorLogicOpEnabled
129 || context_chipset(ctx) >= 0x11);
130
131 BEGIN_RING(chan, celsius, NV11_3D_COLOR_LOGIC_OP_ENABLE, 2);
132 OUT_RINGb(chan, ctx->Color.ColorLogicOpEnabled);
133 OUT_RING(chan, nvgl_logicop_func(ctx->Color.LogicOp));
134 }
135
136 void
137 nv10_emit_shade_model(struct gl_context *ctx, int emit)
138 {
139 struct nouveau_channel *chan = context_chan(ctx);
140 struct nouveau_grobj *celsius = context_eng3d(ctx);
141
142 BEGIN_RING(chan, celsius, NV10_3D_SHADE_MODEL, 1);
143 OUT_RING(chan, ctx->Light.ShadeModel == GL_SMOOTH ?
144 NV10_3D_SHADE_MODEL_SMOOTH : NV10_3D_SHADE_MODEL_FLAT);
145 }
146
147 void
148 nv10_emit_stencil_func(struct gl_context *ctx, int emit)
149 {
150 struct nouveau_channel *chan = context_chan(ctx);
151 struct nouveau_grobj *celsius = context_eng3d(ctx);
152
153 BEGIN_RING(chan, celsius, NV10_3D_STENCIL_ENABLE, 1);
154 OUT_RINGb(chan, ctx->Stencil.Enabled);
155
156 BEGIN_RING(chan, celsius, NV10_3D_STENCIL_FUNC_FUNC, 3);
157 OUT_RING(chan, nvgl_comparison_op(ctx->Stencil.Function[0]));
158 OUT_RING(chan, ctx->Stencil.Ref[0]);
159 OUT_RING(chan, ctx->Stencil.ValueMask[0]);
160 }
161
162 void
163 nv10_emit_stencil_mask(struct gl_context *ctx, int emit)
164 {
165 struct nouveau_channel *chan = context_chan(ctx);
166 struct nouveau_grobj *celsius = context_eng3d(ctx);
167
168 BEGIN_RING(chan, celsius, NV10_3D_STENCIL_MASK, 1);
169 OUT_RING(chan, ctx->Stencil.WriteMask[0]);
170 }
171
172 void
173 nv10_emit_stencil_op(struct gl_context *ctx, int emit)
174 {
175 struct nouveau_channel *chan = context_chan(ctx);
176 struct nouveau_grobj *celsius = context_eng3d(ctx);
177
178 BEGIN_RING(chan, celsius, NV10_3D_STENCIL_OP_FAIL, 3);
179 OUT_RING(chan, nvgl_stencil_op(ctx->Stencil.FailFunc[0]));
180 OUT_RING(chan, nvgl_stencil_op(ctx->Stencil.ZFailFunc[0]));
181 OUT_RING(chan, nvgl_stencil_op(ctx->Stencil.ZPassFunc[0]));
182 }