1 #include "nv10_context.h"
2 #include "nouveau/nouveau_util.h"
8 NV10TCL_TX_FORMAT_FORMAT_##tf, \
11 struct nv10_texture_format
{
17 static struct nv10_texture_format
18 nv10_texture_formats
[] = {
19 _(A8R8G8B8_UNORM
, A8R8G8B8
),
20 _(A1R5G5B5_UNORM
, A1R5G5B5
),
21 _(A4R4G4B4_UNORM
, A4R4G4B4
),
24 _(A8L8_UNORM
, A8L8
),
25 // _(RGB_DXT1 , DXT1, ),
26 // _(RGBA_DXT1 , DXT1, ),
27 // _(RGBA_DXT3 , DXT3, ),
28 // _(RGBA_DXT5 , DXT5, ),
32 static struct nv10_texture_format
*
33 nv10_fragtex_format(uint pipe_format
)
35 struct nv10_texture_format
*tf
= nv10_texture_formats
;
38 if (tf
->pipe
== pipe_format
)
48 nv10_fragtex_build(struct nv10_context
*nv10
, int unit
)
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
;
60 tf
= nv10_fragtex_format(pt
->format
);
61 if (!tf
|| !tf
->defined
) {
62 NOUVEAU_ERR("Unsupported texture format: 0x%x\n", pt
->format
);
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;
74 case PIPE_TEXTURE_CUBE
:
75 txf
|= NV10TCL_TX_FORMAT_CUBE_MAP
;
84 NOUVEAU_ERR("Unknown target %d\n", pt
->target
);
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 */
94 OUT_RING (chan
, ps
->filt
| 0x2000 /* magic */);
95 OUT_RING (chan
, (pt
->width0
<< 16) | pt
->height0
);
96 OUT_RING (chan
, ps
->bcol
);
101 nv10_fragtex_bind(struct nv10_context
*nv10
)
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
;
110 samplers
= nv10
->fp_samplers
& ~fp
->samplers
;
112 unit
= ffs(samplers
) - 1;
113 samplers
&= ~(1 << unit
);
115 BEGIN_RING(chan
, celsius
, NV10TCL_TX_ENABLE(unit
), 1);
119 samplers
= nv10
->dirty_samplers
& fp
->samplers
;
121 unit
= ffs(samplers
) - 1;
122 samplers
&= ~(1 << unit
);
124 nv10_fragtex_build(nv10
, unit
);
127 nv10
->fp_samplers
= fp
->samplers
;