I’m bumping this because I have the same question. I don’t understand why shadow sampler can’t be used for other single component textures.
I’m rendering my depth maps manually and I can’t use it with the shadow sampler
It’s probably the same reason that the R32 and DEPTH_COMPONENT32 formats are not interchangeable. Depth components aren’t just single-channel formats even when they don’t have stencil attached.
To add to what Alfonse said, I think it’s primarily because it requires both:
Depth format texture
Depth comparisons enabled
on the GL side. (Disclaimer: I’m not a driver developer.)
Yes, it requires a depth texture, but you can read from those directly without depth compare using a standard sampler (e.g. sampler2D instead of sampler2DShadow).
However, the depth comparison operation requiring these special sampler types is sometimes backed by special purpose hardware on the GPU (e.g. for performing fast PCF filtering) that probably needs to be enabled, or at least selected, and very likely only works for depth texture formats. And whether it is or not, you can easily envision some GL drivers producing different underlying shader code depending on whether a texture() lookup in the shader should reflect the result of:
a direct depth texture lookup, or
a depth lookup with depth comparison (with or without PCF)
As some evidence of this, one of the guys I’ve worked with struggled for the longest time to get to the bottom of a GL driver crash that was caused by mismatching:
The GL depth compare state,
The GLSL shader referencing a shadow or a non-shadow sampler, and
The GL texture format.
Apparently in some drivers, these must be synced properly to avoid invalid memory accesses down in the driver and/or on the GPU. Crashing in the GL driver is just fine here though because it’s invalid per-spec. But from his perspective, it sure would have been nice if the driver had checked for this and thrown a GL error.
It should also be noted that functions like texture use overloading based on the sampler type in order to know what parameters to take. Shadow samplers require an additional value: the comparison value. So the GLSL code must know that you’re doing a shadow sampler access.
Note that even SPIR-V (somewhat) requires that you put the depth comparison in the OpTypeImage type. It has a way to say “maybe, maybe not”. However, the sampling opcode you use does say whether you’re using depth comparisons. So it’s still hard-coded into the shader logic.