1 #include "util/u_format.h"
3 #include "nvfx_context.h"
4 #include "nouveau/nouveau_util.h"
6 #include "nvfx_resource.h"
9 nv30_sampler_state_init(struct pipe_context
*pipe
,
10 struct nvfx_sampler_state
*ps
,
11 const struct pipe_sampler_state
*cso
)
13 if (cso
->max_anisotropy
>= 8) {
14 ps
->en
|= NV34TCL_TX_ENABLE_ANISO_8X
;
16 if (cso
->max_anisotropy
>= 4) {
17 ps
->en
|= NV34TCL_TX_ENABLE_ANISO_4X
;
19 if (cso
->max_anisotropy
>= 2) {
20 ps
->en
|= NV34TCL_TX_ENABLE_ANISO_2X
;
26 limit
= CLAMP(cso
->lod_bias
, -16.0, 15.0);
27 ps
->filt
|= (int)(cso
->lod_bias
* 256.0) & 0x1fff;
29 limit
= CLAMP(cso
->max_lod
, 0.0, 15.0);
30 ps
->en
|= (int)(limit
) << 14 /*NV34TCL_TX_ENABLE_MIPMAP_MAX_LOD_SHIFT*/;
32 limit
= CLAMP(cso
->min_lod
, 0.0, 15.0);
33 ps
->en
|= (int)(limit
) << 26 /*NV34TCL_TX_ENABLE_MIPMAP_MIN_LOD_SHIFT*/;
37 #define _(m,tf,ts0x,ts0y,ts0z,ts0w,ts1x,ts1y,ts1z,ts1w) \
41 NV34TCL_TX_FORMAT_FORMAT_##tf, \
42 (NV34TCL_TX_SWIZZLE_S0_X_##ts0x | NV34TCL_TX_SWIZZLE_S0_Y_##ts0y | \
43 NV34TCL_TX_SWIZZLE_S0_Z_##ts0z | NV34TCL_TX_SWIZZLE_S0_W_##ts0w | \
44 NV34TCL_TX_SWIZZLE_S1_X_##ts1x | NV34TCL_TX_SWIZZLE_S1_Y_##ts1y | \
45 NV34TCL_TX_SWIZZLE_S1_Z_##ts1z | NV34TCL_TX_SWIZZLE_S1_W_##ts1w) \
48 struct nv30_texture_format
{
55 static struct nv30_texture_format
56 nv30_texture_formats
[] = {
57 _(B8G8R8X8_UNORM
, A8R8G8B8
, S1
, S1
, S1
, ONE
, X
, Y
, Z
, W
),
58 _(B8G8R8A8_UNORM
, A8R8G8B8
, S1
, S1
, S1
, S1
, X
, Y
, Z
, W
),
59 _(B5G5R5A1_UNORM
, A1R5G5B5
, S1
, S1
, S1
, S1
, X
, Y
, Z
, W
),
60 _(B4G4R4A4_UNORM
, A4R4G4B4
, S1
, S1
, S1
, S1
, X
, Y
, Z
, W
),
61 _(B5G6R5_UNORM
, R5G6B5
, S1
, S1
, S1
, ONE
, X
, Y
, Z
, W
),
62 _(L8_UNORM
, L8
, S1
, S1
, S1
, ONE
, X
, X
, X
, X
),
63 _(A8_UNORM
, L8
, ZERO
, ZERO
, ZERO
, S1
, X
, X
, X
, X
),
64 _(I8_UNORM
, L8
, S1
, S1
, S1
, S1
, X
, X
, X
, X
),
65 _(L8A8_UNORM
, A8L8
, S1
, S1
, S1
, S1
, X
, X
, X
, Y
),
66 _(Z16_UNORM
, R5G6B5
, S1
, S1
, S1
, ONE
, X
, X
, X
, X
),
67 _(S8_USCALED_Z24_UNORM
, A8R8G8B8
, S1
, S1
, S1
, ONE
, X
, X
, X
, X
),
68 _(DXT1_RGB
, DXT1
, S1
, S1
, S1
, ONE
, X
, Y
, Z
, W
),
69 _(DXT1_RGBA
, DXT1
, S1
, S1
, S1
, S1
, X
, Y
, Z
, W
),
70 _(DXT3_RGBA
, DXT3
, S1
, S1
, S1
, S1
, X
, Y
, Z
, W
),
71 _(DXT5_RGBA
, DXT5
, S1
, S1
, S1
, S1
, X
, Y
, Z
, W
),
75 static struct nv30_texture_format
*
76 nv30_fragtex_format(uint pipe_format
)
78 struct nv30_texture_format
*tf
= nv30_texture_formats
;
81 if (tf
->pipe
== pipe_format
)
86 NOUVEAU_ERR("unknown texture format %s\n", util_format_name(pipe_format
));
92 nv30_fragtex_set(struct nvfx_context
*nvfx
, int unit
)
94 struct nvfx_sampler_state
*ps
= nvfx
->tex_sampler
[unit
];
95 struct nvfx_miptree
*nv30mt
= (struct nvfx_miptree
*)nvfx
->fragment_sampler_views
[unit
]->texture
;
96 struct pipe_resource
*pt
= &nv30mt
->base
.base
;
97 struct nouveau_bo
*bo
= nv30mt
->base
.bo
;
98 struct nv30_texture_format
*tf
;
99 struct nouveau_channel
* chan
= nvfx
->screen
->base
.channel
;
101 unsigned tex_flags
= NOUVEAU_BO_VRAM
| NOUVEAU_BO_GART
| NOUVEAU_BO_RD
;
103 tf
= nv30_fragtex_format(pt
->format
);
108 txf
|= ((pt
->last_level
>0) ? NV34TCL_TX_FORMAT_MIPMAP
: 0);
109 txf
|= log2i(pt
->width0
) << NV34TCL_TX_FORMAT_BASE_SIZE_U_SHIFT
;
110 txf
|= log2i(pt
->height0
) << NV34TCL_TX_FORMAT_BASE_SIZE_V_SHIFT
;
111 txf
|= log2i(pt
->depth0
) << NV34TCL_TX_FORMAT_BASE_SIZE_W_SHIFT
;
112 txf
|= NV34TCL_TX_FORMAT_NO_BORDER
| 0x10000;
114 switch (pt
->target
) {
115 case PIPE_TEXTURE_CUBE
:
116 txf
|= NV34TCL_TX_FORMAT_CUBIC
;
118 case PIPE_TEXTURE_2D
:
119 txf
|= NV34TCL_TX_FORMAT_DIMS_2D
;
121 case PIPE_TEXTURE_3D
:
122 txf
|= NV34TCL_TX_FORMAT_DIMS_3D
;
124 case PIPE_TEXTURE_1D
:
125 txf
|= NV34TCL_TX_FORMAT_DIMS_1D
;
128 NOUVEAU_ERR("Unknown target %d\n", pt
->target
);
134 MARK_RING(chan
, 9, 2);
135 OUT_RING(chan
, RING_3D(NV34TCL_TX_OFFSET(unit
), 8));
136 OUT_RELOC(chan
, bo
, 0, tex_flags
| NOUVEAU_BO_LOW
, 0, 0);
137 OUT_RELOC(chan
, bo
, txf
, tex_flags
| NOUVEAU_BO_OR
,
138 NV34TCL_TX_FORMAT_DMA0
, NV34TCL_TX_FORMAT_DMA1
);
139 OUT_RING(chan
, ps
->wrap
);
140 OUT_RING(chan
, NV34TCL_TX_ENABLE_ENABLE
| ps
->en
);
142 OUT_RING(chan
, ps
->filt
| 0x2000 /*voodoo*/);
143 OUT_RING(chan
, (pt
->width0
<< NV34TCL_TX_NPOT_SIZE_W_SHIFT
) |
145 OUT_RING(chan
, ps
->bcol
);
147 nvfx
->hw_txf
[unit
] = txf
;
148 nvfx
->hw_samplers
|= (1 << unit
);