1 #include "nv30_context.h"
2 #include "nv30_state.h"
4 static struct nv30_state_entry
*render_states
[] = {
5 &nv30_state_framebuffer
,
6 &nv30_state_rasterizer
,
10 &nv30_state_blend_colour
,
17 nv30_state_do_validate(struct nv30_context
*nv30
,
18 struct nv30_state_entry
**states
)
20 const struct pipe_framebuffer_state
*fb
= &nv30
->framebuffer
;
23 for (i
= 0; i
< fb
->num_cbufs
; i
++)
24 fb
->cbufs
[i
]->status
= PIPE_SURFACE_STATUS_DEFINED
;
26 fb
->zsbuf
->status
= PIPE_SURFACE_STATUS_DEFINED
;
29 struct nv30_state_entry
*e
= *states
;
31 if (nv30
->dirty
& e
->dirty
.pipe
) {
32 if (e
->validate(nv30
)) {
33 nv30
->state
.dirty
|= (1ULL << e
->dirty
.hw
);
40 /* TODO: uncomment when finished converting
46 nv30_emit_hw_state(struct nv30_context
*nv30
)
48 struct nv30_state
*state
= &nv30
->state
;
49 struct nv30_screen
*screen
= nv30
->screen
;
53 if (nv30
->pctx_id
!= screen
->cur_pctx
) {
54 for (i
= 0; i
< NV30_STATE_MAX
; i
++) {
55 if (state
->hw
[i
] && screen
->state
[i
] != state
->hw
[i
])
56 state
->dirty
|= (1ULL << i
);
59 screen
->cur_pctx
= nv30
->pctx_id
;
62 for (i
= 0, states
= state
->dirty
; states
; i
++) {
63 if (!(states
& (1ULL << i
)))
65 so_ref (state
->hw
[i
], &nv30
->screen
->state
[i
]);
67 so_emit(nv30
->nvws
, nv30
->screen
->state
[i
]);
68 states
&= ~(1ULL << i
);
71 if (nv30
->dirty
& NV30_NEW_FRAGPROG
) {
72 nv30_fragprog_bind(nv30
, nv30
->fragprog
.current
);
73 /*XXX: clear NV30_NEW_FRAGPROG if no new program uploaded */
76 if (nv30
->dirty_samplers
|| (nv30
->dirty
& NV30_NEW_FRAGPROG
)) {
77 nv30_fragtex_bind(nv30
);
79 BEGIN_RING(rankine, NV34TCL_TX_CACHE_CTL, 1);
81 BEGIN_RING(rankine, NV34TCL_TX_CACHE_CTL, 1);
83 nv30
->dirty
&= ~NV30_NEW_FRAGPROG
;
86 if (nv30
->dirty
& NV30_NEW_VERTPROG
) {
87 nv30_vertprog_bind(nv30
, nv30
->vertprog
.current
);
88 nv30
->dirty
&= ~NV30_NEW_VERTPROG
;
91 nv30
->dirty_samplers
= 0;
93 so_emit_reloc_markers(nv30
->nvws
, state
->hw
[NV30_STATE_FB
]);
95 /* Texture images, emitted in nv30_fragtex_build */
97 for (i
= 0; i
< 16; i
++) {
98 if (!(nv30
->fp_samplers
& (1 << i
)))
100 BEGIN_RING(rankine
, NV34TCL_TX_OFFSET(i
), 2);
101 OUT_RELOCl(nv30
->tex
[i
].buffer
, 0, NOUVEAU_BO_VRAM
|
102 NOUVEAU_BO_GART
| NOUVEAU_BO_RD
);
103 OUT_RELOCd(nv30
->tex
[i
].buffer
, nv30
->tex
[i
].format
,
104 NOUVEAU_BO_VRAM
| NOUVEAU_BO_GART
| NOUVEAU_BO_RD
|
105 NOUVEAU_BO_OR
, NV34TCL_TX_FORMAT_DMA0
,
106 NV34TCL_TX_FORMAT_DMA1
);
110 /* Fragment program */
111 BEGIN_RING(rankine
, NV34TCL_FP_ACTIVE_PROGRAM
, 1);
112 OUT_RELOC (nv30
->fragprog
.active
->buffer
, 0, NOUVEAU_BO_VRAM
|
113 NOUVEAU_BO_GART
| NOUVEAU_BO_RD
| NOUVEAU_BO_LOW
|
114 NOUVEAU_BO_OR
, NV34TCL_FP_ACTIVE_PROGRAM_DMA0
,
115 NV34TCL_FP_ACTIVE_PROGRAM_DMA1
);
119 nv30_state_validate(struct nv30_context
*nv30
)
122 boolean was_sw
= nv30
->fallback_swtnl
? TRUE
: FALSE
;
124 if (nv30
->render_mode
!= HW
) {
125 /* Don't even bother trying to go back to hw if none
126 * of the states that caused swtnl previously have changed.
128 if ((nv30
->fallback_swtnl
& nv30
->dirty
)
129 != nv30
->fallback_swtnl
)
132 /* Attempt to go to hwtnl again */
133 nv30
->pipe
.flush(&nv30
->pipe
, 0, NULL
);
134 nv30
->dirty
|= (NV30_NEW_VIEWPORT
|
137 nv30
->render_mode
= HW
;
140 nv30_state_do_validate(nv30
, render_states
);
142 if (nv30
->fallback_swtnl
|| nv30
->fallback_swrast
)
146 NOUVEAU_ERR("swtnl->hw\n");