Intrinsics2 min read

store

Writes a value to a storage texture.

Reading Time
2 min
Word Count
182
Sections
12
Try It Live

Test store in a live shader

Open the playground, start from a visual preset, and wire store into the fragment stage to see how it behaves with real values.

Open Playground

Live Demo Pending

This intrinsic does not yet have a self-contained interactive preview. Compute-only and external-resource intrinsics need a different demo path than the current fragment and 3D showcases.

The store function writes a value to a storage (read-write) texture at the specified coordinates.

Signature

bwsl
store :: (RWTexture2D tex, int2 coord, float4 value) {...}
store :: (RWTexture3D tex, int3 coord, float4 value) {...}

Parameters

ParameterTypeDescription
texRWTexture*The storage texture to write to
coordint2/3Integer texel coordinates
valuefloat4Value to write

Return Value

This function returns void.

Example

bwsl
pipeline ComputeBlur {
pass "Main" {
compute "Main" [8, 8, 1] {
int2 gid = int2(input.global_id.xy);
// Simple box blur
float4 sum = float4(0.0);
for (int y = -1; y <= 1; y++) {
for (int x = -1; x <= 1; x++) {
sum += load(inputTex, gid + int2(x, y), 0);
}
}
float4 result = sum / 9.0;
// Write result to output
store(outputTex, gid, result);
}
}
}

Common Use Cases

Compute Shader Output

bwsl
pass "Main" {
compute "Main" [8, 8, 1] {
int2 gid = int2(input.global_id.xy);
float4 result = computeValue(gid);
store(outputTex, gid, result);
}
}

Image Effects

bwsl
// Apply tone mapping
float4 hdr = load(hdrInput, coord, 0);
float4 ldr = toneMap(hdr);
store(ldrOutput, coord, ldr);

Mipmap Generation

bwsl
// Downsample for mip generation
float4 samples[4];
samples[0] = load(srcMip, srcCoord * 2, 0);
samples[1] = load(srcMip, srcCoord * 2 + int2(1, 0), 0);
samples[2] = load(srcMip, srcCoord * 2 + int2(0, 1), 0);
samples[3] = load(srcMip, srcCoord * 2 + int2(1, 1), 0);
float4 avg = (samples[0] + samples[1] + samples[2] + samples[3]) * 0.25;
store(dstMip, srcCoord, avg);

GPU Particle Systems

bwsl
// Update particle positions
float4 pos = load(particlePos, particleId, 0);
float4 vel = load(particleVel, particleId, 0);
pos.xyz += vel.xyz * deltaTime;
store(particlePos, particleId, pos);

Screen-Space Effects

bwsl
// Write screen-space calculation
float ao = computeAO(screenPos);
store(aoTexture, screenPos, float4(ao, ao, ao, 1.0));

Storage Texture Format

The texture must be created as a storage/UAV texture with write access. The format must be compatible with the values being written.

Synchronization

When multiple invocations write to the same texture, ensure proper synchronization using barriers if reading back the results in the same dispatch.

Compute Shaders

store is primarily used in compute shaders and pixel shaders with UAV output. Regular fragment shader output uses the standard output semantics.

Compiled Output

When compiled to GLSL:

glsl
imageStore(tex, coord, value)

When compiled to HLSL:

hlsl
tex[coord] = value

When compiled to Metal:

metal
tex.write(value, coord)

When compiled to SPIR-V:

Uses OpImageWrite instruction.

See Also

  • load - Read from texture
  • sample - Filtered texture read