1
#include "util/u_format.h"
2
#include "nvfx_context.h"
4
#include "nvfx_resource.h"
7
nv40_sampler_state_init(struct pipe_context *pipe,
8
struct nvfx_sampler_state *ps,
9
const struct pipe_sampler_state *cso)
11
if (cso->max_anisotropy >= 2) {
12
/* no idea, binary driver sets it, works without it.. meh.. */
15
if (cso->max_anisotropy >= 16)
16
ps->en |= NV40_3D_TEX_ENABLE_ANISO_16X;
17
else if (cso->max_anisotropy >= 12)
18
ps->en |= NV40_3D_TEX_ENABLE_ANISO_12X;
19
else if (cso->max_anisotropy >= 10)
20
ps->en |= NV40_3D_TEX_ENABLE_ANISO_10X;
21
else if (cso->max_anisotropy >= 8)
22
ps->en |= NV40_3D_TEX_ENABLE_ANISO_8X;
23
else if (cso->max_anisotropy >= 6)
24
ps->en |= NV40_3D_TEX_ENABLE_ANISO_6X;
25
else if (cso->max_anisotropy >= 4)
26
ps->en |= NV40_3D_TEX_ENABLE_ANISO_4X;
28
ps->en |= NV40_3D_TEX_ENABLE_ANISO_2X;
31
ps->filt |= (int)(cso->lod_bias * 256.0) & 0x1fff;
33
ps->max_lod = (int)(CLAMP(cso->max_lod, 0.0, 15.0 + (255.0 / 256.0)) * 256.0);
34
ps->min_lod = (int)(CLAMP(cso->min_lod, 0.0, 15.0 + (255.0 / 256.0)) * 256.0);
36
ps->en |= NV40_3D_TEX_ENABLE_ENABLE;
40
nv40_sampler_view_init(struct pipe_context *pipe,
41
struct nvfx_sampler_view *sv)
43
struct pipe_resource* pt = sv->base.texture;
44
struct nvfx_miptree* mt = (struct nvfx_miptree*)pt;
45
struct nvfx_texture_format *tf = &nvfx_texture_formats[sv->base.format];
47
unsigned level = pt->target == PIPE_TEXTURE_CUBE ? 0 : sv->base.u.tex.first_level;
48
assert(tf->fmt[4] >= 0);
52
if(pt->target == PIPE_TEXTURE_CUBE)
53
txf |= ((pt->last_level + 1) << NV40_3D_TEX_FORMAT_MIPMAP_COUNT__SHIFT);
55
txf |= (((sv->base.u.tex.last_level - sv->base.u.tex.first_level) + 1) << NV40_3D_TEX_FORMAT_MIPMAP_COUNT__SHIFT);
57
if (!mt->linear_pitch)
58
sv->u.nv40.npot_size2 = 0;
60
sv->u.nv40.npot_size2 = mt->linear_pitch;
61
txf |= NV40_3D_TEX_FORMAT_LINEAR;
64
sv->u.nv40.fmt[0] = tf->fmt[4] | txf;
65
sv->u.nv40.fmt[1] = tf->fmt[5] | txf;
67
sv->u.nv40.npot_size2 |= (u_minify(pt->depth0, level) << NV40_3D_TEX_SIZE1_DEPTH__SHIFT);
69
sv->lod_offset = (sv->base.u.tex.first_level - level) * 256;
70
sv->max_lod_limit = (sv->base.u.tex.last_level - level) * 256;
74
nv40_fragtex_set(struct nvfx_context *nvfx, int unit)
76
struct nouveau_channel* chan = nvfx->screen->base.channel;
77
struct nouveau_grobj *eng3d = nvfx->screen->eng3d;
78
struct nvfx_sampler_state *ps = nvfx->tex_sampler[unit];
79
struct nvfx_sampler_view* sv = (struct nvfx_sampler_view*)nvfx->fragment_sampler_views[unit];
80
struct nouveau_bo *bo = ((struct nvfx_miptree *)sv->base.texture)->base.bo;
81
unsigned tex_flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD;
83
unsigned max_lod = MIN2(ps->max_lod + sv->lod_offset, sv->max_lod_limit);
84
unsigned min_lod = MIN2(ps->min_lod + sv->lod_offset, max_lod);
86
txf = sv->u.nv40.fmt[ps->compare] | ps->fmt;
88
MARK_RING(chan, 11, 2);
89
BEGIN_RING(chan, eng3d, NV30_3D_TEX_OFFSET(unit), 8);
90
OUT_RELOC(chan, bo, sv->offset, tex_flags | NOUVEAU_BO_LOW, 0, 0);
91
OUT_RELOC(chan, bo, txf, tex_flags | NOUVEAU_BO_OR,
92
NV30_3D_TEX_FORMAT_DMA0, NV30_3D_TEX_FORMAT_DMA1);
93
OUT_RING(chan, (ps->wrap & sv->wrap_mask) | sv->wrap);
94
OUT_RING(chan, ps->en | (min_lod << 19) | (max_lod << 7));
95
OUT_RING(chan, sv->swizzle);
96
OUT_RING(chan, ps->filt | sv->filt);
97
OUT_RING(chan, sv->npot_size);
98
OUT_RING(chan, ps->bcol);
99
BEGIN_RING(chan, eng3d, NV40_3D_TEX_SIZE1(unit), 1);
100
OUT_RING(chan, sv->u.nv40.npot_size2);
102
nvfx->hw_txf[unit] = txf;
103
nvfx->hw_samplers |= (1 << unit);