store
Writes a value to a storage texture.
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 PlaygroundLive Demo Pending
The store function writes a value to a storage (read-write) texture at the specified coordinates.
Signature
store :: (RWTexture2D tex, int2 coord, float4 value) {...}
store :: (RWTexture3D tex, int3 coord, float4 value) {...}
Parameters
| Parameter | Type | Description |
|---|---|---|
tex | RWTexture* | The storage texture to write to |
coord | int2/3 | Integer texel coordinates |
value | float4 | Value to write |
Return Value
This function returns void.
Example
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
pass "Main" {
compute "Main" [8, 8, 1] {
int2 gid = int2(input.global_id.xy);
float4 result = computeValue(gid);
store(outputTex, gid, result);
}
}Image Effects
// Apply tone mapping
float4 hdr = load(hdrInput, coord, 0);
float4 ldr = toneMap(hdr);
store(ldrOutput, coord, ldr);Mipmap Generation
// 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
// 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
// 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:
imageStore(tex, coord, value)
When compiled to HLSL:
tex[coord] = value
When compiled to Metal:
tex.write(value, coord)
When compiled to SPIR-V:
Uses OpImageWrite instruction.