r300g: adapt to interface changes
[profile/ivi/mesa.git] / src / gallium / drivers / r300 / r300_state_invariant.c
1 /*
2  * Copyright 2009 Joakim Sindholt <opensource@zhasha.com>
3  *                Corbin Simpson <MostAwesomeDude@gmail.com>
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * on the rights to use, copy, modify, merge, publish, distribute, sub
9  * license, and/or sell copies of the Software, and to permit persons to whom
10  * the Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19  * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22  * USE OR OTHER DEALINGS IN THE SOFTWARE. */
23
24 #include "r300_context.h"
25 #include "r300_cs.h"
26 #include "r300_reg.h"
27 #include "r300_screen.h"
28 #include "r300_state_invariant.h"
29
30 struct pipe_viewport_state r300_viewport_identity = {
31     .scale = {1.0, 1.0, 1.0, 1.0},
32     .translate = {0.0, 0.0, 0.0, 0.0},
33 };
34
35 /* Calculate and emit invariant state. This is data that the 3D engine
36  * will probably want at the beginning of every CS, but it's not currently
37  * handled by any CSO setup, and in addition it doesn't really change much.
38  *
39  * Note that eventually this should be empty, but it's useful for development
40  * and general unduplication of code. */
41 void r300_emit_invariant_state(struct r300_context* r300,
42                                unsigned size, void* state)
43 {
44     CS_LOCALS(r300);
45
46     if (r300->rws->get_value(r300->rws, R300_VID_DRM_2_3_0)) {
47         /* Subpixel multisampling for AA. */
48         BEGIN_CS(4);
49         OUT_CS_REG(R300_GB_MSPOS0, 0x66666666);
50         OUT_CS_REG(R300_GB_MSPOS1, 0x6666666);
51         END_CS;
52     }
53
54     BEGIN_CS(12 + (r300->screen->caps.has_tcl ? 2 : 0));
55
56     /*** Graphics Backend (GB) ***/
57     /* Source of fog depth */
58     OUT_CS_REG(R300_GB_SELECT, R300_GB_FOG_SELECT_1_1_W);
59
60     /*** Fog (FG) ***/
61     OUT_CS_REG(R300_FG_FOG_BLEND, 0x0);
62     OUT_CS_REG(R300_FG_FOG_COLOR_R, 0x0);
63     OUT_CS_REG(R300_FG_FOG_COLOR_G, 0x0);
64     OUT_CS_REG(R300_FG_FOG_COLOR_B, 0x0);
65
66     /*** VAP ***/
67     /* Sign/normalize control */
68     OUT_CS_REG(R300_VAP_PSC_SGN_NORM_CNTL, R300_SGN_NORM_NO_ZERO);
69     /* TCL-only stuff */
70     if (r300->screen->caps.has_tcl) {
71         /* Amount of time to wait for vertex fetches in PVS */
72         OUT_CS_REG(VAP_PVS_VTX_TIMEOUT_REG, 0xffff);
73     }
74
75     END_CS;
76
77     /* XXX unsorted stuff from surface_fill */
78     BEGIN_CS(38 + (r300->screen->caps.has_tcl ? 7 : 0) +
79              (r300->screen->caps.is_rv350 ? 4 : 0));
80
81     if (r300->screen->caps.has_tcl) {
82         /*Flushing PVS is required before the VAP_GB registers can be changed*/
83         OUT_CS_REG(R300_VAP_PVS_STATE_FLUSH_REG, 0);
84         OUT_CS_REG_SEQ(R300_VAP_GB_VERT_CLIP_ADJ, 4);
85         OUT_CS_32F(1.0);
86         OUT_CS_32F(1.0);
87         OUT_CS_32F(1.0);
88         OUT_CS_32F(1.0);
89     }
90     /* XXX line tex stuffing */
91     OUT_CS_REG_SEQ(R300_GA_LINE_S0, 1);
92     OUT_CS_32F(0.0);
93     OUT_CS_REG_SEQ(R300_GA_LINE_S1, 1);
94     OUT_CS_32F(1.0);
95     OUT_CS_REG(R300_GA_TRIANGLE_STIPPLE, 0x5 |
96         (0x5 << R300_GA_TRIANGLE_STIPPLE_Y_SHIFT_SHIFT));
97     /* XXX this big chunk should be refactored into rs_state */
98     OUT_CS_REG(R300_GA_SOLID_RG, 0x00000000);
99     OUT_CS_REG(R300_GA_SOLID_BA, 0x00000000);
100     OUT_CS_REG(R300_GA_ROUND_MODE, 0x00000001);
101     OUT_CS_REG(R300_GA_OFFSET, 0x00000000);
102     OUT_CS_REG(R300_GA_FOG_SCALE, 0x3DBF1412);
103     OUT_CS_REG(R300_GA_FOG_OFFSET, 0x00000000);
104     OUT_CS_REG(R300_SU_TEX_WRAP, 0x00000000);
105     OUT_CS_REG(R300_SU_DEPTH_SCALE, 0x4B7FFFFF);
106     OUT_CS_REG(R300_SU_DEPTH_OFFSET, 0x00000000);
107     OUT_CS_REG(R300_SC_HYPERZ, 0x0000001C);
108     OUT_CS_REG(R300_SC_EDGERULE, 0x2DA49525);
109     OUT_CS_REG(R300_RB3D_AARESOLVE_CTL, 0x00000000);
110
111     if (r300->screen->caps.is_rv350) {
112         OUT_CS_REG(R500_RB3D_DISCARD_SRC_PIXEL_LTE_THRESHOLD, 0x01010101);
113         OUT_CS_REG(R500_RB3D_DISCARD_SRC_PIXEL_GTE_THRESHOLD, 0xFEFEFEFE);
114     }
115
116     OUT_CS_REG(R300_ZB_BW_CNTL, 0x00000000);
117     OUT_CS_REG(R300_ZB_DEPTHCLEARVALUE, 0x00000000);
118     OUT_CS_REG(R300_ZB_HIZ_OFFSET, 0x00000000);
119     OUT_CS_REG(R300_ZB_HIZ_PITCH, 0x00000000);
120     END_CS;
121 }