1 #include "nv20_context.h"
3 static INLINE
int log2i(int i
)
33 NV10TCL_TX_FORMAT_FORMAT_##tf, \
36 struct nv20_texture_format
{
42 static struct nv20_texture_format
43 nv20_texture_formats
[] = {
44 _(A8R8G8B8_UNORM
, A8R8G8B8
),
45 _(A1R5G5B5_UNORM
, A1R5G5B5
),
46 _(A4R4G4B4_UNORM
, A4R4G4B4
),
49 _(A8L8_UNORM
, A8L8
),
50 // _(RGB_DXT1 , DXT1, ),
51 // _(RGBA_DXT1 , DXT1, ),
52 // _(RGBA_DXT3 , DXT3, ),
53 // _(RGBA_DXT5 , DXT5, ),
57 static struct nv20_texture_format
*
58 nv20_fragtex_format(uint pipe_format
)
60 struct nv20_texture_format
*tf
= nv20_texture_formats
;
63 if (tf
->pipe
== pipe_format
)
73 nv20_fragtex_build(struct nv20_context
*nv20
, int unit
)
76 struct nv20_sampler_state
*ps
= nv20
->tex_sampler
[unit
];
77 struct nv20_miptree
*nv20mt
= nv20
->tex_miptree
[unit
];
78 struct pipe_texture
*pt
= &nv20mt
->base
;
79 struct nv20_texture_format
*tf
;
80 uint32_t txf
, txs
, txp
;
82 tf
= nv20_fragtex_format(pt
->format
);
83 if (!tf
|| !tf
->defined
) {
84 NOUVEAU_ERR("Unsupported texture format: 0x%x\n", pt
->format
);
88 txf
= tf
->format
<< 8;
89 txf
|= (pt
->last_level
+ 1) << 16;
90 txf
|= log2i(pt
->width
[0]) << 20;
91 txf
|= log2i(pt
->height
[0]) << 24;
92 txf
|= log2i(pt
->depth
[0]) << 28;
96 case PIPE_TEXTURE_CUBE
:
97 txf
|= NV10TCL_TX_FORMAT_CUBE_MAP
;
102 case PIPE_TEXTURE_1D
:
106 NOUVEAU_ERR("Unknown target %d\n", pt
->target
);
110 BEGIN_RING(kelvin
, NV10TCL_TX_OFFSET(unit
), 8);
111 OUT_RELOCl(nv20mt
->buffer
, 0, NOUVEAU_BO_VRAM
| NOUVEAU_BO_GART
| NOUVEAU_BO_RD
);
112 OUT_RELOCd(nv20mt
->buffer
,txf
,NOUVEAU_BO_VRAM
| NOUVEAU_BO_GART
| NOUVEAU_BO_OR
| NOUVEAU_BO_RD
, 1/*VRAM*/,2/*TT*/);
114 OUT_RING (0x40000000); /* enable */
116 OUT_RING (ps
->filt
| 0x2000 /* magic */);
117 OUT_RING ((pt
->width
[0] << 16) | pt
->height
[0]);
123 nv20_fragtex_bind(struct nv20_context
*nv20
)
126 struct nv20_fragment_program
*fp
= nv20
->fragprog
.active
;
127 unsigned samplers
, unit
;
129 samplers
= nv20
->fp_samplers
& ~fp
->samplers
;
131 unit
= ffs(samplers
) - 1;
132 samplers
&= ~(1 << unit
);
134 BEGIN_RING(kelvin
, NV10TCL_TX_ENABLE(unit
), 1);
138 samplers
= nv20
->dirty_samplers
& fp
->samplers
;
140 unit
= ffs(samplers
) - 1;
141 samplers
&= ~(1 << unit
);
143 nv20_fragtex_build(nv20
, unit
);
146 nv20
->fp_samplers
= fp
->samplers
;