• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "nv_object.xml.h"
32 #include "nv10_3d.xml.h"
33 #include "nv10_driver.h"
34 
35 #include "main/stencil.h"
36 
37 void
nv10_emit_alpha_func(struct gl_context * ctx,int emit)38 nv10_emit_alpha_func(struct gl_context *ctx, int emit)
39 {
40 	struct nouveau_pushbuf *push = context_push(ctx);
41 
42 	BEGIN_NV04(push, NV10_3D(ALPHA_FUNC_ENABLE), 1);
43 	PUSH_DATAb(push, ctx->Color.AlphaEnabled);
44 
45 	BEGIN_NV04(push, NV10_3D(ALPHA_FUNC_FUNC), 2);
46 	PUSH_DATA (push, nvgl_comparison_op(ctx->Color.AlphaFunc));
47 	PUSH_DATA (push, FLOAT_TO_UBYTE(ctx->Color.AlphaRef));
48 }
49 
50 void
nv10_emit_blend_color(struct gl_context * ctx,int emit)51 nv10_emit_blend_color(struct gl_context *ctx, int emit)
52 {
53 	struct nouveau_pushbuf *push = context_push(ctx);
54 
55 	BEGIN_NV04(push, NV10_3D(BLEND_COLOR), 1);
56 	PUSH_DATA (push, FLOAT_TO_UBYTE(ctx->Color.BlendColor[3]) << 24 |
57 		 FLOAT_TO_UBYTE(ctx->Color.BlendColor[0]) << 16 |
58 		 FLOAT_TO_UBYTE(ctx->Color.BlendColor[1]) << 8 |
59 		 FLOAT_TO_UBYTE(ctx->Color.BlendColor[2]) << 0);
60 }
61 
62 void
nv10_emit_blend_equation(struct gl_context * ctx,int emit)63 nv10_emit_blend_equation(struct gl_context *ctx, int emit)
64 {
65 	struct nouveau_pushbuf *push = context_push(ctx);
66 
67 	BEGIN_NV04(push, NV10_3D(BLEND_FUNC_ENABLE), 1);
68 	PUSH_DATAb(push, ctx->Color.BlendEnabled);
69 
70 	BEGIN_NV04(push, NV10_3D(BLEND_EQUATION), 1);
71 	PUSH_DATA (push, nvgl_blend_eqn(ctx->Color.Blend[0].EquationRGB));
72 }
73 
74 void
nv10_emit_blend_func(struct gl_context * ctx,int emit)75 nv10_emit_blend_func(struct gl_context *ctx, int emit)
76 {
77 	struct nouveau_pushbuf *push = context_push(ctx);
78 
79 	BEGIN_NV04(push, NV10_3D(BLEND_FUNC_SRC), 2);
80 	PUSH_DATA (push, nvgl_blend_func(ctx->Color.Blend[0].SrcRGB));
81 	PUSH_DATA (push, nvgl_blend_func(ctx->Color.Blend[0].DstRGB));
82 }
83 
84 void
nv10_emit_color_mask(struct gl_context * ctx,int emit)85 nv10_emit_color_mask(struct gl_context *ctx, int emit)
86 {
87 	struct nouveau_pushbuf *push = context_push(ctx);
88 
89 	BEGIN_NV04(push, NV10_3D(COLOR_MASK), 1);
90 	PUSH_DATA (push, ((GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 3) ? 1 << 24 : 0) |
91 			(GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 0) ? 1 << 16 : 0) |
92 			(GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 1) ? 1 << 8 : 0) |
93 			(GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 2) ? 1 << 0 : 0)));
94 }
95 
96 void
nv10_emit_depth(struct gl_context * ctx,int emit)97 nv10_emit_depth(struct gl_context *ctx, int emit)
98 {
99 	struct nouveau_pushbuf *push = context_push(ctx);
100 	struct gl_framebuffer *fb = ctx->DrawBuffer;
101 
102 	BEGIN_NV04(push, NV10_3D(DEPTH_TEST_ENABLE), 1);
103 	PUSH_DATAb(push, ctx->Depth.Test && fb->Visual.depthBits > 0);
104 	BEGIN_NV04(push, NV10_3D(DEPTH_WRITE_ENABLE), 1);
105 	PUSH_DATAb(push, ctx->Depth.Mask && fb->Visual.depthBits > 0);
106 	BEGIN_NV04(push, NV10_3D(DEPTH_FUNC), 1);
107 	PUSH_DATA (push, nvgl_comparison_op(ctx->Depth.Func));
108 }
109 
110 void
nv10_emit_dither(struct gl_context * ctx,int emit)111 nv10_emit_dither(struct gl_context *ctx, int emit)
112 {
113 	struct nouveau_pushbuf *push = context_push(ctx);
114 
115 	BEGIN_NV04(push, NV10_3D(DITHER_ENABLE), 1);
116 	PUSH_DATAb(push, ctx->Color.DitherFlag);
117 }
118 
119 void
nv10_emit_logic_opcode(struct gl_context * ctx,int emit)120 nv10_emit_logic_opcode(struct gl_context *ctx, int emit)
121 {
122 	struct nouveau_pushbuf *push = context_push(ctx);
123 
124 	assert(!ctx->Color.ColorLogicOpEnabled
125 	       || context_eng3d(ctx)->oclass >= NV15_3D_CLASS);
126 
127 	BEGIN_NV04(push, NV11_3D(COLOR_LOGIC_OP_ENABLE), 2);
128 	PUSH_DATAb(push, ctx->Color.ColorLogicOpEnabled);
129 	PUSH_DATA (push, ctx->Color.LogicOp);
130 }
131 
132 void
nv10_emit_shade_model(struct gl_context * ctx,int emit)133 nv10_emit_shade_model(struct gl_context *ctx, int emit)
134 {
135 	struct nouveau_pushbuf *push = context_push(ctx);
136 
137 	BEGIN_NV04(push, NV10_3D(SHADE_MODEL), 1);
138 	PUSH_DATA (push, ctx->Light.ShadeModel == GL_SMOOTH ?
139 		 NV10_3D_SHADE_MODEL_SMOOTH : NV10_3D_SHADE_MODEL_FLAT);
140 }
141 
142 void
nv10_emit_stencil_func(struct gl_context * ctx,int emit)143 nv10_emit_stencil_func(struct gl_context *ctx, int emit)
144 {
145 	struct nouveau_pushbuf *push = context_push(ctx);
146 
147 	BEGIN_NV04(push, NV10_3D(STENCIL_ENABLE), 1);
148 	PUSH_DATAb(push, _mesa_stencil_is_enabled(ctx));
149 
150 	BEGIN_NV04(push, NV10_3D(STENCIL_FUNC_FUNC), 3);
151 	PUSH_DATA (push, nvgl_comparison_op(ctx->Stencil.Function[0]));
152 	PUSH_DATA (push, _mesa_get_stencil_ref(ctx, 0));
153 	PUSH_DATA (push, ctx->Stencil.ValueMask[0]);
154 }
155 
156 void
nv10_emit_stencil_mask(struct gl_context * ctx,int emit)157 nv10_emit_stencil_mask(struct gl_context *ctx, int emit)
158 {
159 	struct nouveau_pushbuf *push = context_push(ctx);
160 
161 	BEGIN_NV04(push, NV10_3D(STENCIL_MASK), 1);
162 	PUSH_DATA (push, ctx->Stencil.WriteMask[0]);
163 }
164 
165 void
nv10_emit_stencil_op(struct gl_context * ctx,int emit)166 nv10_emit_stencil_op(struct gl_context *ctx, int emit)
167 {
168 	struct nouveau_pushbuf *push = context_push(ctx);
169 
170 	BEGIN_NV04(push, NV10_3D(STENCIL_OP_FAIL), 3);
171 	PUSH_DATA (push, nvgl_stencil_op(ctx->Stencil.FailFunc[0]));
172 	PUSH_DATA (push, nvgl_stencil_op(ctx->Stencil.ZFailFunc[0]));
173 	PUSH_DATA (push, nvgl_stencil_op(ctx->Stencil.ZPassFunc[0]));
174 }
175