Merge branch 'instanced-arrays'
[mesa.git] / src / gallium / drivers / nv10 / nv10_fragtex.c
1 #include "nv10_context.h"
2 #include "nouveau/nouveau_util.h"
3
4 #define _(m,tf) \
5 { \
6 TRUE, \
7 PIPE_FORMAT_##m, \
8 NV10TCL_TX_FORMAT_FORMAT_##tf, \
9 }
10
11 struct nv10_texture_format {
12 boolean defined;
13 uint pipe;
14 int format;
15 };
16
17 static struct nv10_texture_format
18 nv10_texture_formats[] = {
19 _(A8R8G8B8_UNORM, A8R8G8B8),
20 _(A1R5G5B5_UNORM, A1R5G5B5),
21 _(A4R4G4B4_UNORM, A4R4G4B4),
22 _(L8_UNORM , L8 ),
23 _(A8_UNORM , A8 ),
24 _(A8L8_UNORM , A8L8 ),
25 // _(RGB_DXT1 , DXT1, ),
26 // _(RGBA_DXT1 , DXT1, ),
27 // _(RGBA_DXT3 , DXT3, ),
28 // _(RGBA_DXT5 , DXT5, ),
29 {},
30 };
31
32 static struct nv10_texture_format *
33 nv10_fragtex_format(uint pipe_format)
34 {
35 struct nv10_texture_format *tf = nv10_texture_formats;
36
37 while (tf->defined) {
38 if (tf->pipe == pipe_format)
39 return tf;
40 tf++;
41 }
42
43 return NULL;
44 }
45
46
47 static void
48 nv10_fragtex_build(struct nv10_context *nv10, int unit)
49 {
50 #if 0
51 struct nv10_sampler_state *ps = nv10->tex_sampler[unit];
52 struct nv10_miptree *nv10mt = nv10->tex_miptree[unit];
53 struct pipe_texture *pt = &nv10mt->base;
54 struct nv10_texture_format *tf;
55 struct nv10_screen *screen = nv10->screen;
56 struct nouveau_channel *chan = screen->base.channel;
57 struct nouveau_grobj *celsius = screen->celsius;
58 uint32_t txf, txs, txp;
59
60 tf = nv10_fragtex_format(pt->format);
61 if (!tf || !tf->defined) {
62 NOUVEAU_ERR("Unsupported texture format: 0x%x\n", pt->format);
63 return;
64 }
65
66 txf = tf->format << 8;
67 txf |= (pt->last_level + 1) << 16;
68 txf |= log2i(pt->width0) << 20;
69 txf |= log2i(pt->height0) << 24;
70 txf |= log2i(pt->depth0) << 28;
71 txf |= 8;
72
73 switch (pt->target) {
74 case PIPE_TEXTURE_CUBE:
75 txf |= NV10TCL_TX_FORMAT_CUBE_MAP;
76 /* fall-through */
77 case PIPE_TEXTURE_2D:
78 txf |= (2<<4);
79 break;
80 case PIPE_TEXTURE_1D:
81 txf |= (1<<4);
82 break;
83 default:
84 NOUVEAU_ERR("Unknown target %d\n", pt->target);
85 return;
86 }
87
88 BEGIN_RING(chan, celsius, NV10TCL_TX_OFFSET(unit), 8);
89 OUT_RELOCl(chan, nouveau_bo(nv10mt->buffer), 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD);
90 OUT_RELOCd(chan, nouveau_bo(nv10mt->buffer),txf,NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_OR | NOUVEAU_BO_RD, 1/*VRAM*/,2/*TT*/);
91 OUT_RING (chan, ps->wrap);
92 OUT_RING (chan, 0x40000000); /* enable */
93 OUT_RING (chan, txs);
94 OUT_RING (chan, ps->filt | 0x2000 /* magic */);
95 OUT_RING (chan, (pt->width0 << 16) | pt->height0);
96 OUT_RING (chan, ps->bcol);
97 #endif
98 }
99
100 void
101 nv10_fragtex_bind(struct nv10_context *nv10)
102 {
103 #if 0
104 struct nv10_fragment_program *fp = nv10->fragprog.active;
105 struct nv10_screen *screen = nv10->screen;
106 struct nouveau_channel *chan = screen->base.channel;
107 struct nouveau_grobj *celsius = screen->celsius;
108 unsigned samplers, unit;
109
110 samplers = nv10->fp_samplers & ~fp->samplers;
111 while (samplers) {
112 unit = ffs(samplers) - 1;
113 samplers &= ~(1 << unit);
114
115 BEGIN_RING(chan, celsius, NV10TCL_TX_ENABLE(unit), 1);
116 OUT_RING (chan, 0);
117 }
118
119 samplers = nv10->dirty_samplers & fp->samplers;
120 while (samplers) {
121 unit = ffs(samplers) - 1;
122 samplers &= ~(1 << unit);
123
124 nv10_fragtex_build(nv10, unit);
125 }
126
127 nv10->fp_samplers = fp->samplers;
128 #endif
129 }
130