The rigorous coupled-wave approach (RCWA) was used to calculate the optical absorption in a dielectric material deposited over a two-dimensional (2D) metallic surface-relief grating. The dielectric material was taken to be nonhomogeneous in the direction normal to the mean plane of the grating. The grating was chosen to comprise hillocks on a square grid. On illumination by a monochromatic plane waves, the chosen structure should support the excitation of two types of guided-wave modes: surface-plasmon-polariton (SPP) waves and waveguide modes (WGMs). Two cases were considered: (i) a 1D photonic crystal made from layers of silicon oxynitrides of differing composition, and (ii) a tandem solar cell comprising three amorphous-silicon p-i-n junctions. Optical absorption was studied in relation to the direction of propagation, polarization state, and the free-space wavelength of the incident plane wave. Several but not all absorptance peaks were correlated with the excitations of SPP-wave modes and WGMs predicted by the solutions of the underlying canonical boundary-value problems for guided-wave propagation. Some peaks of useful absorptances in the solar cell were also predicted by solutions of the canonical problems.