yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Yong HeAdd texture tri-linear autodiff example. (#2715)96caba75e

master
554 B22 linesraw
1// A compute shader to add gradients to a mip-map texture.
2
3cbuffer Uniforms
4{
5    uint dstWidth;
6    uint dstHeight;
7    float learningRate;
8    RWTexture2D dstTexture;
9    RWTexture2D srcTexture;
10}
11
12[shader("compute")]
13[numthreads(16, 16, 1)]
14void computeMain(uint3 threadIdx : SV_DispatchThreadID)
15{
16    uint x = threadIdx.x;
17    uint y = threadIdx.y;
18    if (x >= dstWidth) return;
19    if (y >= dstHeight) return;
20    var val = srcTexture[uint2(x, y)];
21    dstTexture[uint2(x, y)] = float4((dstTexture[uint2(x, y)] - val * learningRate).xyz, 1.0);
22}