r300: Add dsa state emit.
[mesa.git] / src / gallium / drivers / r300 / r300_emit.c
1 /*
2 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
22
23 /* r300_emit: Functions for emitting state. */
24
25 #include "r300_emit.h"
26
27 void r300_emit_blend_state(struct r300_context* r300,
28 struct r300_blend_state* blend)
29 {
30 CS_LOCALS(r300);
31 BEGIN_CS(7);
32 OUT_CS_REG_SEQ(R300_RB3D_CBLEND, 2);
33 OUT_CS(blend->blend_control);
34 OUT_CS(blend->alpha_blend_control);
35 OUT_CS_REG(R300_RB3D_ROPCNTL, blend->rop);
36 OUT_CS_REG(R300_RB3D_DITHER_CTL, blend->dither);
37 END_CS;
38 }
39
40 void r300_emit_blend_color_state(struct r300_context* r300,
41 struct r300_blend_color_state* bc)
42 {
43 struct r300_screen* r300screen =
44 (struct r300_screen*)r300->context.screen;
45 CS_LOCALS(r300);
46 if (r300screen->caps->is_r500) {
47 BEGIN_CS(3);
48 OUT_CS_REG_SEQ(R500_RB3D_CONSTANT_COLOR_AR, 2);
49 OUT_CS(bc->blend_color_red_alpha);
50 OUT_CS(bc->blend_color_green_blue);
51 END_CS;
52 } else {
53 BEGIN_CS(2);
54 OUT_CS_REG(R300_RB3D_BLEND_COLOR, bc->blend_color);
55 END_CS;
56 }
57 }
58
59 void r300_emit_dsa_state(struct r300_context* r300,
60 struct r300_dsa_state* dsa)
61 {
62 struct r300_screen* r300screen =
63 (struct r300_screen*)r300->context.screen;
64 CS_LOCALS(r300);
65 BEGIN_CS(r300screen->caps->is_r500 ? 12 : 10);
66 OUT_CS_REG(R300_FG_ALPHA_FUNC, dsa->alpha_function);
67 OUT_CS_REG(R500_FG_ALPHA_VALUE, dsa->alpha_reference);
68 OUT_CS_REG_SEQ(R300_ZB_CNTL, 3);
69 OUT_CS(dsa->z_buffer_control);
70 OUT_CS(dsa->z_stencil_control);
71 OUT_CS(dsa->stencil_ref_mask);
72 OUT_CS_REG(R300_ZB_ZTOP, dsa->z_buffer_top);
73 if (r300screen->caps->is_r500) {
74 OUT_CS_REG(R500_ZB_STENCILREFMASK_BF, dsa->stencil_ref_bf);
75 }
76 }
77
78 static void r300_emit_dirty_state(struct r300_context* r300)
79 {
80 struct r300_screen* r300screen =
81 (struct r300_screen*)r300->context.screen;
82 CS_LOCALS(r300);
83
84 if (!(r300->dirty_state) && !(r300->dirty_hw)) {
85 return;
86 }
87
88 /* XXX check size */
89
90 if (r300->dirty_state & R300_NEW_BLEND) {
91 r300_emit_blend_state(r300, r300->blend_state);
92 }
93
94 if (r300->dirty_state & R300_NEW_BLEND_COLOR) {
95 r300_emit_blend_color_state(r300, r300->blend_color_state);
96 }
97
98 if (r300->dirty_state & R300_NEW_DSA) {
99 r300_emit_dsa_state(r300, r300->dsa_state);
100 }
101
102 if (r300->dirty_state & R300_NEW_RASTERIZER) {
103 struct r300_rs_state* rs = r300->rs_state;
104 OUT_CS_REG(R300_VAP_CNTL_STATUS, rs->vap_control_status);
105 /* XXX next six are contiguous regs */
106 OUT_CS_REG(R300_SU_POLY_OFFSET_FRONT_SCALE, rs->depth_scale_front);
107 OUT_CS_REG(R300_SU_POLY_OFFSET_FRONT_OFFSET, rs->depth_offset_front);
108 OUT_CS_REG(R300_SU_POLY_OFFSET_BACK_SCALE, rs->depth_scale_back);
109 OUT_CS_REG(R300_SU_POLY_OFFSET_BACK_OFFSET, rs->depth_offset_back);
110 OUT_CS_REG(R300_SU_POLY_OFFSET_ENABLE, rs->polygon_offset_enable);
111 OUT_CS_REG(R300_SU_CULL_MODE, rs->cull_mode);
112 }
113
114 if (r300->dirty_state & R300_NEW_SCISSOR) {
115 struct r300_scissor_state* scissor = r300->scissor_state;
116 /* XXX next two are contiguous regs */
117 OUT_CS_REG(R300_SC_SCISSORS_TL, scissor->scissor_top_left);
118 OUT_CS_REG(R300_SC_SCISSORS_BR, scissor->scissor_bottom_right);
119 }
120
121 r300->dirty_state = 0;
122 }