Electromagnetic wave diffractions from multilayered and corrugated dielectric gratings with three-dimensional modulation are analyzed using rigorous coupled-wave theory. This analysis applies to the lossy and anisotropic multilayered planar gratings with three linearly independent grating vectors in each layer, when the grating vectors in different layers are related in a certain manner. It also applies to the lossless and isotropic corrugated gratings of arbitrarily-shaped periodic profiles with two linearly independent arbitrary grating vectors. The amplitudes of the diffraction waves of all orders and polarization modes are formally solved and expressed in an explicit matrix form. Numerical calculation of the diffraction efficiencies can be implemented on digital computers in a straightforward manner. But large computer memory capacity and execution time are needed.