1 #include "nv40_context.h"
2 #include "nv40_state.h"
3 #include "draw/draw_context.h"
5 static struct nv40_state_entry
*render_states
[] = {
6 &nv40_state_framebuffer
,
7 &nv40_state_rasterizer
,
14 &nv40_state_blend_colour
,
21 static struct nv40_state_entry
*swtnl_states
[] = {
22 &nv40_state_framebuffer
,
23 &nv40_state_rasterizer
,
30 &nv40_state_blend_colour
,
38 nv40_state_do_validate(struct nv40_context
*nv40
,
39 struct nv40_state_entry
**states
)
42 struct nv40_state_entry
*e
= *states
;
44 if (nv40
->dirty
& e
->dirty
.pipe
) {
45 if (e
->validate(nv40
))
46 nv40
->state
.dirty
|= (1ULL << e
->dirty
.hw
);
55 nv40_state_emit(struct nv40_context
*nv40
)
57 struct nv40_state
*state
= &nv40
->state
;
58 struct nv40_screen
*screen
= nv40
->screen
;
59 struct nouveau_channel
*chan
= screen
->base
.channel
;
60 struct nouveau_grobj
*curie
= screen
->curie
;
64 /* XXX: race conditions
66 if (nv40
!= screen
->cur_ctx
) {
67 for (i
= 0; i
< NV40_STATE_MAX
; i
++) {
68 if (state
->hw
[i
] && screen
->state
[i
] != state
->hw
[i
])
69 state
->dirty
|= (1ULL << i
);
72 screen
->cur_ctx
= nv40
;
75 for (i
= 0, states
= state
->dirty
; states
; i
++) {
76 if (!(states
& (1ULL << i
)))
78 so_ref (state
->hw
[i
], &nv40
->screen
->state
[i
]);
80 so_emit(chan
, nv40
->screen
->state
[i
]);
81 states
&= ~(1ULL << i
);
84 if (state
->dirty
& ((1ULL << NV40_STATE_FRAGPROG
) |
85 (1ULL << NV40_STATE_FRAGTEX0
))) {
86 BEGIN_RING(chan
, curie
, NV40TCL_TEX_CACHE_CTL
, 1);
88 BEGIN_RING(chan
, curie
, NV40TCL_TEX_CACHE_CTL
, 1);
96 nv40_state_flush_notify(struct nouveau_channel
*chan
)
98 struct nv40_context
*nv40
= chan
->user_private
;
99 struct nv40_state
*state
= &nv40
->state
;
100 unsigned i
, samplers
;
102 so_emit_reloc_markers(chan
, state
->hw
[NV40_STATE_FB
]);
103 for (i
= 0, samplers
= state
->fp_samplers
; i
< 16 && samplers
; i
++) {
104 if (!(samplers
& (1 << i
)))
106 so_emit_reloc_markers(chan
,
107 state
->hw
[NV40_STATE_FRAGTEX0
+i
]);
108 samplers
&= ~(1ULL << i
);
110 so_emit_reloc_markers(chan
, state
->hw
[NV40_STATE_FRAGPROG
]);
111 if (state
->hw
[NV40_STATE_VTXBUF
] && nv40
->render_mode
== HW
)
112 so_emit_reloc_markers(chan
, state
->hw
[NV40_STATE_VTXBUF
]);
116 nv40_state_validate(struct nv40_context
*nv40
)
118 boolean was_sw
= nv40
->fallback_swtnl
? TRUE
: FALSE
;
120 if (nv40
->render_mode
!= HW
) {
121 /* Don't even bother trying to go back to hw if none
122 * of the states that caused swtnl previously have changed.
124 if ((nv40
->fallback_swtnl
& nv40
->dirty
)
125 != nv40
->fallback_swtnl
)
128 /* Attempt to go to hwtnl again */
129 nv40
->pipe
.flush(&nv40
->pipe
, 0, NULL
);
130 nv40
->dirty
|= (NV40_NEW_VIEWPORT
|
133 nv40
->render_mode
= HW
;
136 nv40_state_do_validate(nv40
, render_states
);
137 if (nv40
->fallback_swtnl
|| nv40
->fallback_swrast
)
141 NOUVEAU_ERR("swtnl->hw\n");
147 nv40_state_validate_swtnl(struct nv40_context
*nv40
)
149 struct draw_context
*draw
= nv40
->draw
;
151 /* Setup for swtnl */
152 if (nv40
->render_mode
== HW
) {
153 NOUVEAU_ERR("hw->swtnl 0x%08x\n", nv40
->fallback_swtnl
);
154 nv40
->pipe
.flush(&nv40
->pipe
, 0, NULL
);
155 nv40
->dirty
|= (NV40_NEW_VIEWPORT
|
158 nv40
->render_mode
= SWTNL
;
161 if (nv40
->draw_dirty
& NV40_NEW_VERTPROG
)
162 draw_bind_vertex_shader(draw
, nv40
->vertprog
->draw
);
164 if (nv40
->draw_dirty
& NV40_NEW_RAST
)
165 draw_set_rasterizer_state(draw
, &nv40
->rasterizer
->pipe
);
167 if (nv40
->draw_dirty
& NV40_NEW_UCP
)
168 draw_set_clip_state(draw
, &nv40
->clip
);
170 if (nv40
->draw_dirty
& NV40_NEW_VIEWPORT
)
171 draw_set_viewport_state(draw
, &nv40
->viewport
);
173 if (nv40
->draw_dirty
& NV40_NEW_ARRAYS
) {
174 draw_set_vertex_buffers(draw
, nv40
->vtxbuf_nr
, nv40
->vtxbuf
);
175 draw_set_vertex_elements(draw
, nv40
->vtxelt_nr
, nv40
->vtxelt
);
178 nv40_state_do_validate(nv40
, swtnl_states
);
179 if (nv40
->fallback_swrast
) {
180 NOUVEAU_ERR("swtnl->swrast 0x%08x\n", nv40
->fallback_swrast
);
184 nv40
->draw_dirty
= 0;