textureStore
Function
A texture store replaces the value of one integer-addressed texel.
Related names in other languages
These related operations can differ in arguments, support, and semantics. The foreign names are not accepted TypeShade aliases. Check the target forms and restrictions.
- GLSL:
imageStore
Compare examples
Only the selected texel changes to the input value. The call returns no value; the display shows the texel before and after the store.
Model assumptionstexture_storage_2d<"r32float", "write">; value = vec4(0.5, 0, 0, 1)
Example 1textureStore(tex, vec2i(0, 0), value)
0.7510.50.25 - Stored value before
0- Returned value
void- Stored value after
0.5
Example 2textureStore(tex, vec2i(1, 0), value)
0.75100.5 - Stored value before
0.25- Returned value
void- Stored value after
0.5
Example 3textureStore(tex, vec2i(1, 1), value)
0.750.500.25 - Stored value before
1- Returned value
void- Stored value after
0.5
The examples are calculation models and do not run GPU work. The reference below gives the complete call signatures. Decimal results are rounded for display. The stated assumptions determine each example; actual shader results follow the target precision and execution rules.
When to use it
Use it to write a compute result into an image.
Inputs and limits
Use a writable storage texture and a value matching its format. This model shows separate writes; overlapping writes need an explicit race-free design.
For shader input rules and precision, consult WGSL and GLSL ES 3.00.
Related functions
The signature, the sentence and any message are the compiler's own text at commit af54ddad5.
Writes one texel to a storage texture at the integer coord, on a binding declared "write" or "read_write"; returns nothing.
Syntax
declare function textureStore<F extends StorageFormat, A extends 'write' | 'read_write'>( tex: texture_storage_2d<F, A>, coord: TexelCoord2, value: StorageTexel<F>,): voiddeclare function textureStore<F extends StorageFormat, A extends 'write' | 'read_write'>( tex: texture_storage_2d_array<F, A>, coord: TexelCoord2, layer: number, value: StorageTexel<F>,): voidA number in a parameter or a return position is the scalar slot. The ambient file declares a GPU scalar as a branded number whose brand is optional, so a literal and any branded scalar both fill it.
type f32 = number & { readonly [f32Tag]?: true }
A number you write as a type is inferred from its uses, and f32, i32 and u32 fix a width; the TypeScript constructs page carries that row with the compiler's emit.
A signature may name a type the ambient file declares for its own use. These are those declarations.
TexelCoord2type TexelCoord2 = vec2i | vec2uStorageFormattype StorageFormat = 'rgba8unorm' | 'rgba8snorm' | 'rgba8uint' | 'rgba8sint' | 'rgba16uint' | 'rgba16sint' | 'rgba16float' | 'r32uint' | 'r32sint' | 'r32float' | 'rg32uint' | 'rg32sint' | 'rg32float' | 'rgba32uint' | 'rgba32sint' | 'rgba32float' | 'bgra8unorm'StorageTexeltype StorageTexel<F extends StorageFormat> = F extends `${string}uint` ? vec4u : F extends `${string}sint` ? vec4i : vec4
Parameters
-
textexture_storage_2d<F, A>texture_storage_2d_array<F, A> -
coordTexelCoord2 -
valueStorageTexel<F> -
layeroptionalnumber
Return value
void
Description
The value is the texel the format decides: a "…uint" format stores a vec4u, a "…sint" one a vec4i, and every other one a vec4. Compiles to textureStore on WGSL; in a render entry its GLSL lowering is not supported yet (Rule 10.5), so a module using it emits WGSL alone, and on the CPU tier a store into a CpuTexture converts the value as the format decides while a store outside it, or into a texture not in that memory, is dropped (Rule 11.7).
Targets
- WGSL
-
textureStore(a, b, c) - GLSL ES 3.00
-
textureStoreis not supported yet on the WebGL2 tier (Rule 10.5)