r300g: attempt to fix texture corruption on RV505
[mesa.git] / src / gallium / drivers / nvfx / nvfx_fragtex.c
1 #include "nvfx_context.h"
2 #include "nvfx_resource.h"
3
4 void
5 nvfx_fragtex_validate(struct nvfx_context *nvfx)
6 {
7 struct nouveau_channel* chan = nvfx->screen->base.channel;
8 unsigned samplers, unit;
9
10 samplers = nvfx->dirty_samplers;
11 if(!samplers)
12 return;
13
14 while (samplers) {
15 unit = ffs(samplers) - 1;
16 samplers &= ~(1 << unit);
17
18 if(nvfx->fragment_sampler_views[unit] && nvfx->tex_sampler[unit]) {
19 if(!nvfx->is_nv4x)
20 nv30_fragtex_set(nvfx, unit);
21 else
22 nv40_fragtex_set(nvfx, unit);
23 } else {
24 WAIT_RING(chan, 2);
25 /* this is OK for nv40 too */
26 OUT_RING(chan, RING_3D(NV34TCL_TX_ENABLE(unit), 1));
27 OUT_RING(chan, 0);
28 nvfx->hw_samplers &= ~(1 << unit);
29 }
30 }
31 nvfx->dirty_samplers = 0;
32 }
33
34 void
35 nvfx_fragtex_relocate(struct nvfx_context *nvfx)
36 {
37 struct nouveau_channel* chan = nvfx->screen->base.channel;
38 unsigned samplers, unit;
39 unsigned tex_flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD;
40
41 samplers = nvfx->hw_samplers;
42 while (samplers) {
43 struct nvfx_miptree* mt;
44 struct nouveau_bo *bo;
45
46 unit = ffs(samplers) - 1;
47 samplers &= ~(1 << unit);
48
49 mt = (struct nvfx_miptree*)nvfx->fragment_sampler_views[unit]->texture;
50 bo = mt->base.bo;
51
52 MARK_RING(chan, 3, 3);
53 OUT_RELOC(chan, bo, RING_3D(NV34TCL_TX_OFFSET(unit), 2), tex_flags | NOUVEAU_BO_DUMMY, 0, 0);
54 OUT_RELOC(chan, bo, 0, tex_flags | NOUVEAU_BO_LOW | NOUVEAU_BO_DUMMY, 0, 0);
55 OUT_RELOC(chan, bo, nvfx->hw_txf[unit], tex_flags | NOUVEAU_BO_OR | NOUVEAU_BO_DUMMY,
56 NV34TCL_TX_FORMAT_DMA0, NV34TCL_TX_FORMAT_DMA1);
57 }
58 }