revert between 56095 -> 55830 in arch
[AROS.git] / workbench / libs / mesa / src / gallium / drivers / nvfx / nv30_fragtex.c
blob8a2c023a91a3bbf66fe21c293da022f94ab8b908
1 #include "util/u_format.h"
3 #include "nvfx_context.h"
4 #include "nvfx_tex.h"
5 #include "nvfx_resource.h"
7 void
8 nv30_sampler_state_init(struct pipe_context *pipe,
9 struct nvfx_sampler_state *ps,
10 const struct pipe_sampler_state *cso)
12 #if 0 /* unused */
13 float limit;
14 #endif
16 if (cso->max_anisotropy >= 2)
18 if (cso->max_anisotropy >= 8)
19 ps->en |= NV30_3D_TEX_ENABLE_ANISO_8X;
20 else if (cso->max_anisotropy >= 4)
21 ps->en |= NV30_3D_TEX_ENABLE_ANISO_4X;
22 else if (cso->max_anisotropy >= 2)
23 ps->en |= NV30_3D_TEX_ENABLE_ANISO_2X;
26 #if 0 /* unused */
27 limit = CLAMP(cso->lod_bias, -16.0, 15.0 + (255.0 / 256.0));
28 #endif
29 ps->filt |= (int)(cso->lod_bias * 256.0) & 0x1fff;
31 ps->max_lod = (int)CLAMP(cso->max_lod, 0.0, 15.0);
32 ps->min_lod = (int)CLAMP(cso->min_lod, 0.0, 15.0);
34 ps->en |= NV30_3D_TEX_ENABLE_ENABLE;
37 void
38 nv30_sampler_view_init(struct pipe_context *pipe,
39 struct nvfx_sampler_view *sv)
41 struct pipe_resource* pt = sv->base.texture;
42 struct nvfx_texture_format *tf = &nvfx_texture_formats[sv->base.format];
43 unsigned txf;
44 unsigned level = pt->target == PIPE_TEXTURE_CUBE ? 0 : sv->base.u.tex.first_level;
46 assert(tf->fmt[0] >= 0);
48 txf = sv->u.init_fmt;
49 txf |= (level != sv->base.u.tex.last_level ? NV30_3D_TEX_FORMAT_MIPMAP : 0);
50 txf |= util_logbase2(u_minify(pt->width0, level)) << NV30_3D_TEX_FORMAT_BASE_SIZE_U__SHIFT;
51 txf |= util_logbase2(u_minify(pt->height0, level)) << NV30_3D_TEX_FORMAT_BASE_SIZE_V__SHIFT;
52 txf |= util_logbase2(u_minify(pt->depth0, level)) << NV30_3D_TEX_FORMAT_BASE_SIZE_W__SHIFT;
53 txf |= 0x10000;
55 sv->u.nv30.fmt[0] = tf->fmt[0] | txf;
56 sv->u.nv30.fmt[1] = tf->fmt[1] | txf;
57 sv->u.nv30.fmt[2] = tf->fmt[2] | txf;
58 sv->u.nv30.fmt[3] = tf->fmt[3] | txf;
60 sv->swizzle |= (nvfx_subresource_pitch(pt, 0) << NV30_3D_TEX_SWIZZLE_RECT_PITCH__SHIFT);
62 if(pt->height0 <= 1 || util_format_is_compressed(sv->base.format))
63 sv->u.nv30.rect = -1;
64 else
65 sv->u.nv30.rect = !!(pt->flags & NVFX_RESOURCE_FLAG_LINEAR);
67 sv->lod_offset = sv->base.u.tex.first_level - level;
68 sv->max_lod_limit = sv->base.u.tex.last_level - level;
71 void
72 nv30_fragtex_set(struct nvfx_context *nvfx, int unit)
74 struct nvfx_sampler_state *ps = nvfx->tex_sampler[unit];
75 struct nvfx_sampler_view* sv = (struct nvfx_sampler_view*)nvfx->fragment_sampler_views[unit];
76 struct nouveau_bo *bo = ((struct nvfx_miptree *)sv->base.texture)->base.bo;
77 struct nouveau_channel* chan = nvfx->screen->base.channel;
78 struct nouveau_grobj *eng3d = nvfx->screen->eng3d;
79 unsigned txf;
80 unsigned tex_flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD;
81 unsigned use_rect;
82 unsigned max_lod = MIN2(ps->max_lod + sv->lod_offset, sv->max_lod_limit);
83 unsigned min_lod = MIN2(ps->min_lod + sv->lod_offset, max_lod) ;
85 if(sv->u.nv30.rect < 0)
87 /* in the case of compressed or 1D textures, we can get away with this,
88 * since the layout is the same
90 use_rect = ps->fmt;
92 else
94 static boolean warned = FALSE;
95 if( !!ps->fmt != sv->u.nv30.rect && !warned) {
96 warned = TRUE;
97 fprintf(stderr,
98 "Unimplemented: coordinate normalization mismatch. Possible reasons:\n"
99 "1. ARB_texture_non_power_of_two is being used despite the fact it isn't supported\n"
100 "2. The state tracker is not using the appropriate coordinate normalization\n"
101 "3. The state tracker is not supported\n");
104 use_rect = sv->u.nv30.rect;
107 txf = sv->u.nv30.fmt[ps->compare + (use_rect ? 2 : 0)];
109 MARK_RING(chan, 9, 2);
110 BEGIN_RING(chan, eng3d, NV30_3D_TEX_OFFSET(unit), 8);
111 OUT_RELOC(chan, bo, sv->offset, tex_flags | NOUVEAU_BO_LOW, 0, 0);
112 OUT_RELOC(chan, bo, txf,
113 tex_flags | NOUVEAU_BO_OR,
114 NV30_3D_TEX_FORMAT_DMA0, NV30_3D_TEX_FORMAT_DMA1);
115 OUT_RING(chan, (ps->wrap & sv->wrap_mask) | sv->wrap);
116 OUT_RING(chan, ps->en | (min_lod << NV30_3D_TEX_ENABLE_MIPMAP_MIN_LOD__SHIFT) | (max_lod << NV30_3D_TEX_ENABLE_MIPMAP_MAX_LOD__SHIFT));
117 OUT_RING(chan, sv->swizzle);
118 OUT_RING(chan, ps->filt | sv->filt);
119 OUT_RING(chan, sv->npot_size);
120 OUT_RING(chan, ps->bcol);
122 nvfx->hw_txf[unit] = txf;
123 nvfx->hw_samplers |= (1 << unit);