TS8052
On this page

TS8052

Front-end code UNIFORMITY

A call that needs uniform control flow — textureSample and the other implicit-LOD forms, the derivatives, a barrier, or workgroupUniformLoad — reached under a condition that is not uniform across the invocations that run together (an if, a switch, a loop's condition, the left side of && or ||, the condition of a ?: WGSL writes as an if), or after a return, break or continue taken under one (§54).

The registry text and every compiler message on these pages are the compiler's own English.

Example

example.shade.ts
"use typeshade"
declare const tex: texture_2d<f32>
declare const smp: sampler
@fragment
export function main(@location(0) uv: vec2): vec4 {
if (uv.x > 0.5) {
return textureSample(tex, smp, uv)
}
return vec4(0., 0., 0., 1.)
}

Compiled at build time against the pinned compiler, this program gets:

TS8052 error, line 9: textureSample() is reached under "uv" (a fragment input at @location(0)), which WGSL's derivative_uniformity rule refuses: the implicit level of detail is a difference between neighbouring invocations, and one that did not run has no value to difference against. Hoist the call above the branch, or use textureSampleLevel or textureSampleGrad, whose level of detail is the one you wrote, or write @diagnostic("off", "derivative_uniformity") on the entry to take the module as written.

How to fix it

The same program, corrected. It compiles with no diagnostic.

example.shade.ts
"use typeshade"
declare const tex: texture_2d<f32>
declare const smp: sampler
@fragment
export function main(@location(0) uv: vec2): vec4 {
const c = textureSample(tex, smp, uv)
if (uv.x > 0.5) {
return c
}
return vec4(0., 0., 0., 1.)
}

The rules this enforces

Rule 8.3 Test
A builtin WGSL confines by stage may be used in an entry of a permitted stage, and in a helper that no entry of an excluded stage can reach.
Rule 8.5 Test
A collective operation (a derivative, an implicit-LOD texture sample, a barrier) must be in uniform control flow.

See also

Source

Where the compiler raises this code at commit 26de7be8, one line per file:

Edit this page Report a problem