Varying Unit Survey

This page surveys how GPUs implement varying interpolation between shader stages: what enters the varying path, how it is parameterized, how perspective correction works, how multiple lanes/instances get different varyings, and where software emulation appears.

Short answer:

1) What a varying is

A varying is data written by an earlier stage and read by a later stage. Common examples:

At the API level, varyings are usually declared as:

2) What the varying unit consumes

The interpolation path typically consumes:

Common parameterization inputs

Input Meaning
Per-vertex attribute values The source values to interpolate
Clip-space W Used for perspective-correct interpolation
Primitive coverage Which pixels/samples are covered
Barycentric weights Triangle-local weights for interpolation
Provoking vertex Source for flat-qualified values
Sample position Used for centroid/sample evaluation and MSAA
Interpolation mode Flat, smooth, noperspective, sample, centroid
Primitive ID / face flag Per-primitive values not interpolated from vertices

3) Do vendors implement varyings in hardware or software?

For shipping desktop and mobile GPUs, the normal path is hardware-assisted interpolation, not shader-code emulation. That said, there are software paths in the ecosystem:

So the practical answer is:

4) How perspective correction works

For triangle fragments, interpolation is usually barycentric in screen space with perspective correction. The core idea is:

  1. The rasterizer computes barycentric weights for the fragment within the triangle.
  2. Each varying is divided by vertex W before interpolation.
  3. The interpolated result is re-multiplied by the reciprocal of the interpolated 1/W.

Conceptually:

Barycentric form

For a triangle with vertices A, B, C and barycentric weights λ0, λ1, λ2:

V = \frac{λ0 \frac{V0}{W0} + λ1 \frac{V1}{W1} + λ2 \frac{V2}{W2}}{λ0 \frac{1}{W0} + λ1 \frac{1}{W1} + λ2 \frac{1}{W2}}

For noperspective, the denominator is skipped.

5) How multiple shader instances get different varyings

A single shader program usually runs across many pixels at once. Each lane in the wave/warp corresponds to a different pixel/sample, so each lane needs different interpolated values.

The hardware handles this by:

This is why varyings scale naturally with SIMT execution:

6) How vendors generally expose the varying path

NVIDIA

AMD

Intel

Apple

ARM / Mali

Broadcom (VideoCore / V3D)

7) Explicit barycentrics and programmable interpolation

Modern APIs increasingly expose explicit barycentric inputs so the shader can perform custom interpolation or attribute reconstruction.

Examples:

Advantages:

Disadvantages:

8) Software interpolation paths

Yes: software rasterizers do this in software.

Mesa software paths such as llvmpipe/softpipe can interpolate varyings on the CPU side before the fragment-like shading code runs. This is not unusual for open-source driver stacks because:

Trade-off:

9) Vendor-style inputs and qualifier summary

API concept Typical input to the varying path Notes
GLSL smooth Per-vertex values + clip-space W Perspective-correct
GLSL noperspective Per-vertex values Screen-space linear
GLSL flat Provoking vertex value No interpolation
GLSL centroid Coverage-aware sample position Helps avoid edge artifacts
GLSL sample Per-sample interpolation MSAA-sensitive
HLSL TEXCOORDn / COLORn Generic interpolated payload Semantics guide linkage
HLSL SV_Position Rasterizer-derived screen position Can be linear no perspective in pixel stage
HLSL SV_IsFrontFace Per-primitive facing Not interpolated
HLSL SV_SampleIndex Sample number Per-sample shading
HLSL SV_Barycentrics Explicit barycentric weights Programmable interpolation
Vulkan/GLSL built-ins Interface variables + qualifiers Mirrors the underlying graphics pipeline

10) Barycentric and centroid handling

Barycentric coordinates are the natural model for triangle interpolation. The hardware typically computes them relative to the covered pixel/sample and then applies the interpolation mode:

Centroid sampling is mainly about avoiding artifacts at triangle edges when the pixel center falls outside the covered area under MSAA.

11) Practical pros and cons

Dedicated hardware interpolation

Pros:

Cons:

Software or shader-ALU interpolation

Pros:

Cons:

12) Bottom line

For normal desktop/mobile GPUs, varyings are usually a hardware-interpolated part of the graphics pipeline, not a dedicated shader-written program block. The shader core generally receives ready-to-use interpolants. Software implementation exists mainly in Mesa software rasterizers and fallback/emulation paths. Perspective correction is typically barycentric with 1/W compensation, while qualifiers such as flat, noperspective, centroid, and sample select the exact behavior.