shader-slang / slang

Making it easier to work with shaders
MIT License
2.07k stars 177 forks source link

error 49999: unknown system-value semantic 'SV_InsideTessFactor' #4313

Closed n3b closed 3 months ago

n3b commented 3 months ago

Are tessellation shaders supported yet? Is there an example how to map both endpoints to the hull stage?

Also, VulkanUtil::getShaderStage: domain stage is mapped to VK control, hull to evaluation https://github.com/shader-slang/slang/blob/master/tools/gfx/vulkan/vk-util.cpp#L183

A simple sample I get the error with (v2024.1.21, SPIRV target):

struct HS_CONTROL_POINT_OUTPUT
{
    float4 Position : POSITION;
    float2 TexCoord : TEXCOORD;
};

struct HS_CONSTANT_DATA_OUTPUT
{
    float EdgeTessFactor[4] : SV_TessFactor;
    float InsideTessFactor[2] : SV_InsideTessFactor;
};

struct DS_OUTPUT
{
    float4 Position : SV_Position;
    float2 TexCoord : TEXCOORD;
};

// Domain Shader (DS)
[domain("quad")]
DS_OUTPUT main(HS_CONSTANT_DATA_OUTPUT input, const OutputPatch<HS_CONTROL_POINT_OUTPUT, 4> patch, float2 uv : SV_DomainLocation)
{
    DS_OUTPUT output;
    output.Position = 0;
    output.TexCoord = 0;
    return output;
}
ArielG-NV commented 3 months ago

tessellation shaders are supported

it seems that we did not implement:

  1. SV_InsideTessFactor->TessLevelInner for SPIRV
  2. SV_InsideTessFactor->gl_TessLevelOuter for GLSL
csyonghe commented 3 months ago

@ArielG-NV Sorry I didn't notice that you already assigned this issue yourself, but I have just fixed this along with the other spirv issue.

n3b commented 3 months ago

Hey, thanks for a quick turnaround!

Unfortunately I still see issues even with the https://github.com/shader-slang/slang/pull/4318, but I might be missing something

hlsl.meta.slang(3698): error 29000: unable to parse target intrinsic snippet: .operator[]
hlsl.meta.slang(3698): error 29000: unable to parse target intrinsic snippet: .operator[]
hlsl.meta.slang(3698): error 29000: unable to parse target intrinsic snippet: .operator[]
hlsl.meta.slang(3698): error 29000: unable to parse target intrinsic snippet: .operator[]
hlsl.meta.slang(3698): error 29000: unable to parse target intrinsic snippet: .operator[]
hlsl.meta.slang(3698): error 29000: unable to parse target intrinsic snippet: .operator[]
hlsl.meta.slang(3698): error 29000: unable to parse target intrinsic snippet: .operator[]
(0): error 99999: Slang compilation aborted due to an exception of class Slang::InternalError: unimplemented: Unhandled global inst in spirv-emit:
let  %1 : _     = InputPatch(%VSx5FOUT, %2)
struct VS_OUT
{
    float3 position : POSITION;
};

struct HS_OUT
{
    float3 position : POSITION;
};

struct HSC_OUT
{
    float EdgeTessFactor[4] : SV_TessFactor;
    float InsideTessFactor[2] : SV_InsideTessFactor;
};

// Hull Shader (HS)
[domain("quad")]
[partitioning("integer")]
[outputtopology("triangle_cw")]
[outputcontrolpoints(4)]
[patchconstantfunc("constants")]
HS_OUT main(InputPatch<VS_OUT, 4> patch, uint i : SV_OutputControlPointID)
{
    HS_OUT o;
    o.position = patch[i].position;
    return o;
}

HSC_OUT constants(InputPatch<VS_OUT, 4> patch)
{
    float3 p0 = patch[0].position;
    float3 p1 = patch[1].position;
    float3 p2 = patch[2].position;
    float3 p3 = patch[3].position;

    HSC_OUT o;
    o.EdgeTessFactor[0] = dot(p0, p1); 
    o.EdgeTessFactor[1] = dot(p0, p3);
    o.EdgeTessFactor[2] = dot(p2, p3);
    o.EdgeTessFactor[3] = dot(p1, p2);
    o.InsideTessFactor[0] = lerp(o.EdgeTessFactor[1], o.EdgeTessFactor[3], 0.5);
    o.InsideTessFactor[1] = lerp(o.EdgeTessFactor[0], o.EdgeTessFactor[2], 0.5);
    return o;
}

Respectively domain shader complains that OutputPatch is not implemented

csyonghe commented 3 months ago

I think you are right. We haven't fully supported tessellation stages for SPIRV yet, but I think we are close and I'll make sure these are supported today.

csyonghe commented 3 months ago

Opened https://github.com/shader-slang/slang/issues/4332 to track development of InputPatch and OutputPatch.