shader-slang / slang

Making it easier to work with shaders
MIT License
1.78k stars 159 forks source link

SPIRV backend: add support for tessellation stages. #4336

Closed csyonghe closed 3 weeks ago

csyonghe commented 3 weeks ago

Closes #4332.

The main task here is to properly lower InputPatch<T> and OutputPatch<T> to array types in SPIRV, and to combine both the hull shader and the patch constant function into a single entrypoint for SPIRV.

A hull shader in the form of:

struct HullInput { float3 inElement; }
struct ConstantOutput { float factor[4] : SV_TessFactor; }
struct HullOutput { float3 outElement; }

ConstantOutput constantFunc(InputPatch<HullInput, N> inPatch, OutputPatch<HullOutput, N> outPatch)
{
    // compute tess factor
}

[patchconstantfunc("constantFunc")]
HullOutput hull(InputPatch<HullInput, N> patch, int i : SV_OutputControlPointID)
{
           // compute outElmeent
} 

should be transformed to:

in float3 inElement[N];
out float3 outElement[N];

void hull()
{
       // compute outElement (original hull shader body)

      barrier;

      if (gl_InvocationID == 0) {
              // compute tess factor and set gl_TessLevelInner[N];  (constantFunc)
      }
}
csyonghe commented 3 weeks ago

Thank you for your kind words and for the prompt review, Jay!