Rebel Fork Framework
Compute

Limited GPU compute capability is exposed through the Compute Device class. Compute is currently only available on desktop targets.

The interface for compute is raw and expects the caller to perform all setup, manage constant buffers, as well as textures and even fetch the shader variations oneself.

Notably compute provides a clean means to directly write into texture layers and mipmaps which is of value for filtering tasks. Currently the only supported write-targets are images which must be of the RGBA8, RGBA16F, RGBA32F, or R32F formats to allow writing.

// C#
ComputeDevice cd = Context.GetSubsystem<ComputeDevice>();
cd.SetReadTexture(rampTexture, 0);
cd.SetWriteTexture(tex2D, 1, 0, 0);
cd.SetProgram(computeKernel);
cd.Dispatch(64,64,1);
tex2D.GetImage().SavePNG("TestFilter.png");

Compute Trickiness

Due to OpenGL image-unit space sharing it's recommend that D3D11 UAV registers do not overlap with texture and sampler registers so that the same C++/C# code can be used regardless of the underlying backend.

// Valid HLSL
Texture2D myTex : register(t0);
SamplerState mySampler : register(s0);
RWTexture2D<float4> myWriteTexture : register(u0);
// Bad GLSL
layout(binding = 0)
uniform sampler2D myTex;
layout(binding = 0, rgba8)
uniform image2D myWriteTexture;

In the above code the image-units for myTex and myWriteTexture overlap. The ideal situation is:

// Better HLSL
Texture2D myTex : register(t0);
SamplerState mySampler : register(s0);
RWTexture2D<float4> myWriteTexture : register(u1);
// Good GLSL
layout(binding = 0)
uniform sampler2D myTex;
layout(binding = 1, rgba8)
uniform image2D myWriteTexture;