Hull Shader: Patch Constant Function SV_PrimitiveID missing semantics
Hi,
I'm facing an error when I try to implement the Hull Shader's Patch Constant Function.
Referring to the Microsoft Docs "How To Design a Hull Shader" it should be possible to retrieve the current patchID via the second parameter uint patchID : SV_PrimitiveID.
HS_Constant_Output HSConstant(InputPatch<HS_Input, 4> inputPatch, uint patchId : SV_PrimitiveID)
{
HS_Constant_Output output;
float tessFactor = 2.0;
[...]
return output;
};
But unfortunately I'm getting a missing semantics error:
fxc: [filename] error X3502: 'HSConstant_0': input parameter 'patchId_0' missing semantics
On the other hand the parameter is working in the main shader function as expected
[domain("quad")]
[partitioning("integer")]
[outputtopology("triangle_cw")]
[outputcontrolpoints(4)]
[patchconstantfunc("HSConstant")]
HS_Output main(InputPatch<HS_Input, 4> inputPatch, uint pointId : SV_OutputControlPointID, uint patchId : SV_PrimitiveID)
{
HS_Output output;
output.posW = inputPatch[pointId].posW;
output.posH = inputPatch[pointId].posH;
output.texC = inputPatch[pointId].texC;
return output;
}
If I delete the patchId parameter from the PCF parameterlist, everything is working fine but I need the patchID value in the PCF itself. I've already found a similar issue on the KhronosGroup glslang repo but it couldn't help me except the hint for the workaround to delete the parameter to get it running at all.
Is there a way to solve this problem?
Is HSConstant() a hull-shader entry-point or an internal shader function?
No, the HSConstant() function is not the entry point. But the hull shader requires it. The main shader is running once per control point (4 in my case) and runs the HSConstant() function once per patch (a quad in my case) to set tessellation data like the tessellation amount. It acts like a preparation stage for the actual tessellation.
The HSConstant function is only linked via the defined hull shader attribute [patchconstantfunc("HSConstant")] - that also prevents me to call the function in a "normal way" and with additional parameters.
I assume you are using Falcor to compile it and not FXC directly, correct? @tfoleyNV Could it be a Slang issue?
This looks like a Slang issue, yes. The Slang front-end is failing to look for (and therefore preserve) system-value semantics on the patch-constant function.
I assume you are using Falcor to compile it and not FXC directly, correct?
Yes, I'm using Falcor. I haven't looked into the process of compiling the shader extanally with FXC yet (never worked with hlsl shaders before) - but if it's easy to use with Falcor and would help me to compile the shader as intended, then it would be great.
We don't use FXC directly. Falcor's shading-language is actually Slang (@tfoleyNV is the lead developer) and it looks like there's an issue there with hull-shaders.
@tfoleyNV Is that something that can be fixed for Falcor 3.2? The version of Slang we are using is pretty old. We're going to release a preview version of 4.0 in mid-September, it might make more sense to wait for that.
@nbenty It is possible that we could issue a hotfix to the version of Slang that is currently used by Falcor 3.2. I have a good sense of what is going wrong here, but I haven't dived into the code to think about what a solution would look like.
You and I should probably figure out how to prioritize this relative to other work.
Thanks for your quick support. I found a very ugly workaround by passing an additional vertex attribute as a "patchID" in the pipeline which works for my context now. And since I'm currently working on my master's thesis, waiting is rather unfavorable for me right now :) But I'm looking forward for any updates.
@tfoleyNV Is there a Slang issue or should I open one?
I'll make one.
Edit: https://github.com/shader-slang/slang/issues/1020