6. If $x \in\left(0, \frac{\pi}{2}\right)$, then the maximum value of the function $f(x)=2 \cos ^{3} x+3 \cos ^{2} x-6 \cos x-2 \cos 3 x$ is
$\qquad$ .
6. $\frac{1}{9}$.

Because
$$
\begin{aligned}
\cos 3 x= & \cos (2 x+x)=\cos 2 x \cos x-\sin 2 x \sin x \\
= & \left(2 \cos ^{2} x-1\right) \cos x-2 \cos x\left(1-\cos ^{2} x\right) \\
& =4 \cos ^{3} x-3 \cos x,
\end{aligned}
$$

Therefore,
$$
\begin{aligned}
f(x) & =3 \cos ^{2} x-6 \cos ^{3} x=3 \cos ^{2} x(1-2 \cos x) \\
& \leqslant 3\left(\frac{\cos x+\cos x+1-2 \cos x}{3}\right)^{3}=\frac{1}{9}
\end{aligned}
$$

Equality holds if and only if $\cos x=1-2 \cos x$, i.e., $\cos x=\frac{1}{3}$.
Thus, when $x=\arccos \frac{1}{3}$, $f(x)$ attains its maximum value $\frac{1}{9}$.