optimal estimate for generalized Kloosterman sum Let $p$ be an odd prime. Denote $e(x):=e^{2\pi i\frac{x}{p}}$. Let $n\ge 2$ be an integer. Consider the exponential sum
$$
S(f,g)=\sum_{g(x_1,\dots,x_n)=0, x_i\in\mathbb{F}_p}e(f(x_1,\dots,x_n)),
$$
where $f$ and $g$ are polynomials of $n$ variables. 
Such $S(f,g)$ is common. For example, Kloosterman sum can be written in this form. 
I am seeking conditions on $f$ and $g$ so that we have the optimal estimate
\begin{equation}
S(f,g)\ll p^{(n-1)/2}.
\end{equation}
My thoughts so far: if from $g(x_1,\dots,x_n)=0$ we can write $x_1$ in terms of other variables in a polynomial way, then $S(f,g)$ becomes a sum over the full $(n-1)$-dim space $\mathbb{F}_p^{n-1}$ and $f$ becomes a polynomial of $n-1$ variables. Then a theorem of Deligne says that we just need to check whether the homogeneous leading term of $f$ defines a smooth projective hypersurface. But I do not know how to deal with general (or other) $g$. For example, what about the case $g(x_1,\dots,x_n)=h(x_1)+\dots+h(x_n)$ for some single-variable polynomial $h$? If $h$ is quadratic, then we can't write $x_1$ in terms of other variables in a polynomial way at all.
It seems to me that Deligne's paper already considers a much more general sum than $S(f,g)$. But the Deligne's criterion to get the optimal estimate is abstract and hard to check for people who do not know algebraic geometry. I hope that in the simpler case of $S(f,g)$ there is an easy-to-check criterion on $f$ and $g$. 
 A: The work of Katz (https://web.math.princeton.edu/~nmk/sommesexp.pdf, 5.1.1, see also the beginning of https://web.math.princeton.edu/~nmk/ESES.pdf for an English exposition)  provides an analogue of Deligne's criterion.
Katz's $X$ here will be the projective closure of the solution set of $g$, his $L$ will be the hyperplane at $\infty$, and his $H$ will be the vanishing locus of $f$.  One demands that $L$ is transverse to $X$, which is equivalent to saying that the leading term of $g$ defines a smooth projective hypersurface, that the degree of $f$ is prime to $p$, and that $H$ is transverse to $X \cap L$, which is equivalent to saying that the leading terms of $f$ and $g$ together define a smooth codimension $2$ subvariety in projective space. 
Of course, if these smoothness assumptions don't hold, then in general you may need to use monodromy, Fourier transform, vanishing cycles, etc. to solve the problem. (This criterion doesn't even apply to the classical Kloosterman sum for $n>2$.) Essentially the boundary between the cases that admit square-root cancellation and those that don't should be very complicated in general, and no general black-box result is expected to cover a significant fraction of the cases where square-root cancellation can be proved.
