Merge branch 'mesa_7_6_branch'
[mesa.git] / src / gallium / drivers / nv20 / nv20_fragtex.c
1 #include "nv20_context.h"
2 #include "nouveau/nouveau_util.h"
3
4 #define _(m,tf) \
5 { \
6 TRUE, \
7 PIPE_FORMAT_##m, \
8 NV20TCL_TX_FORMAT_FORMAT_##tf, \
9 }
10
11 struct nv20_texture_format {
12 boolean defined;
13 uint pipe;
14 int format;
15 };
16
17 static struct nv20_texture_format
18 nv20_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 nv20_texture_format *
33 nv20_fragtex_format(uint pipe_format)
34 {
35 struct nv20_texture_format *tf = nv20_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 nv20_fragtex_build(struct nv20_context *nv20, int unit)
49 {
50 #if 0
51 struct nv20_sampler_state *ps = nv20->tex_sampler[unit];
52 struct nv20_miptree *nv20mt = nv20->tex_miptree[unit];
53 struct pipe_texture *pt = &nv20mt->base;
54 struct nv20_texture_format *tf;
55 uint32_t txf, txs, txp;
56
57 tf = nv20_fragtex_format(pt->format);
58 if (!tf || !tf->defined) {
59 NOUVEAU_ERR("Unsupported texture format: 0x%x\n", pt->format);
60 return;
61 }
62
63 txf = tf->format << 8;
64 txf |= (pt->last_level + 1) << 16;
65 txf |= log2i(pt->width[0]) << 20;
66 txf |= log2i(pt->height[0]) << 24;
67 txf |= log2i(pt->depth[0]) << 28;
68 txf |= 8;
69
70 switch (pt->target) {
71 case PIPE_TEXTURE_CUBE:
72 txf |= NV10TCL_TX_FORMAT_CUBE_MAP;
73 /* fall-through */
74 case PIPE_TEXTURE_2D:
75 txf |= (2<<4);
76 break;
77 case PIPE_TEXTURE_1D:
78 txf |= (1<<4);
79 break;
80 default:
81 NOUVEAU_ERR("Unknown target %d\n", pt->target);
82 return;
83 }
84
85 BEGIN_RING(kelvin, NV10TCL_TX_OFFSET(unit), 8);
86 OUT_RELOCl(nv20mt->buffer, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD);
87 OUT_RELOCd(nv20mt->buffer,txf,NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_OR | NOUVEAU_BO_RD, 1/*VRAM*/,2/*TT*/);
88 OUT_RING (ps->wrap);
89 OUT_RING (0x40000000); /* enable */
90 OUT_RING (txs);
91 OUT_RING (ps->filt | 0x2000 /* magic */);
92 OUT_RING ((pt->width[0] << 16) | pt->height[0]);
93 OUT_RING (ps->bcol);
94 #endif
95 }
96
97 void
98 nv20_fragtex_bind(struct nv20_context *nv20)
99 {
100 #if 0
101 struct nv20_fragment_program *fp = nv20->fragprog.active;
102 unsigned samplers, unit;
103
104 samplers = nv20->fp_samplers & ~fp->samplers;
105 while (samplers) {
106 unit = ffs(samplers) - 1;
107 samplers &= ~(1 << unit);
108
109 BEGIN_RING(kelvin, NV10TCL_TX_ENABLE(unit), 1);
110 OUT_RING (0);
111 }
112
113 samplers = nv20->dirty_samplers & fp->samplers;
114 while (samplers) {
115 unit = ffs(samplers) - 1;
116 samplers &= ~(1 << unit);
117
118 nv20_fragtex_build(nv20, unit);
119 }
120
121 nv20->fp_samplers = fp->samplers;
122 #endif
123 }
124