Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slang compiles all the HLSL vertex/pixel/computer shaders, but none of the HLSL geometry shaders #6185

Closed
itamago opened this issue Jan 26, 2025 · 10 comments · Fixed by #6197
Assignees
Labels
goal:quality & productivity Quality issues and issues that impact our productivity coding day to day inside slang

Comments

@itamago
Copy link

itamago commented Jan 26, 2025

Hello,
I am new to slang. I try to make it compile all the HLSL shaders I have, before migrating to new slang language features.

Basically, when compiling the HLSL geometry shaders, slang seems not accepting any semantics to communicate between the vertex and the geometry shader with the following errors :
dxc 1.8: mymodule.slang(34): error : Semantic POSITION is invalid for shader model: gs
dxc 1.8: mymodule.slang(58): error : Semantic CUSTOM is invalid for shader model: gs
dxc 1.8: mymodule.slang(58): error : Semantic TEXTURE is invalid for shader model: gs

I tried changing to various semantics , but the errors remain. Here is an example semantics which fail :

struct GS_INPUT
{
    float4 PosSS : TEXTURE0;
};

In my code, I ask slang compiling to DXIL with sm_6_0.
I thought it would be related to the version of sm, but all the tested versions gave the same result.

Maybe I'm missing something, because all the other kind of shaders are compiling correctly.

Please see the code which compile the shaders :

slang::SessionDesc sessionDesc = {};
slang::TargetDesc  targetDesc  = {};
targetDesc.format  = SLANG_DXIL;
targetDesc.profile = s_sessionSlang->findProfile("sm_6_0");
targetDesc.flags = 0;

sessionDesc.targets = &targetDesc;
sessionDesc.targetCount = 1;

Slang::ComPtr<slang::ISession> session;
ENSURE(SLANG_SUCCEEDED(s_sessionSlang->createSession(sessionDesc, session.writeRef())));

auto PrintDiagnostics = [](ISlangBlob* diagnostics)
    {
        if (diagnostics)
        {
            const char* diagnosticMessage = (const char*)diagnostics->getBufferPointer();
            Log("Diagnostics : %s\n", diagnosticMessage);
        }
    };

ISlangBlob* diagnostics = NULL;

slang::IModule* module = session->loadModuleFromSourceString(
    "mymodule",
    "mymodule.slang",
    m_source.Chars(),
    &diagnostics
);
PrintDiagnostics(diagnostics);
ENSURE(module != NULL);

// Specify the entry point and target profile (e.g., vertex shader for DirectX 12)
SlangStage stage = SLANG_STAGE_NONE;
switch (m_type)
{
    case ShaderType::Vertex:    stage = SLANG_STAGE_VERTEX;     break;
    case ShaderType::Geometry:  stage = SLANG_STAGE_GEOMETRY;   break;
    case ShaderType::Pixel:     stage = SLANG_STAGE_PIXEL;      break;
    case ShaderType::Compute:   stage = SLANG_STAGE_COMPUTE;    break;
    default:                    ENSURE(false);                  break;
}

Slang::ComPtr<slang::IEntryPoint> entryPoint;
ENSURE(SLANG_SUCCEEDED(module->findAndCheckEntryPoint(m_entryPoint.Chars(), stage, entryPoint.writeRef(), &diagnostics)));
PrintDiagnostics(diagnostics);

slang::IComponentType* components[] = {module, entryPoint};
Slang::ComPtr<slang::IComponentType> composedProgram;
STATIC_ASSERT(EASE_ARRAY_SIZE(components) == 2);
ENSURE(SLANG_SUCCEEDED(session->createCompositeComponentType(components, EASE_ARRAY_SIZE(components), composedProgram.writeRef(), &diagnostics)));
PrintDiagnostics(diagnostics);

Slang::ComPtr<slang::IComponentType> linkedProgram;
ENSURE(SLANG_SUCCEEDED(composedProgram->link(linkedProgram.writeRef(), &diagnostics)));
PrintDiagnostics(diagnostics);

Do you have any idea or remark, please ?
Thanks for your help

@csyonghe
Copy link
Collaborator

Can you share the full source of your geometry shader?

@itamago
Copy link
Author

itamago commented Jan 27, 2025

Hello @csyonghe

Thank you for considering my issue.
Please find the following HLSL Geometry shader, simplified to the minimum, which doesn't compile.
When I change the semantic TEXTURE0 with other semantic (SV_xxx or any usual ones) it provides the same error.

struct GS_INPUT
{
    float4 PosSS : TEXTURE0;     // [Screen Space] Position
};

struct PS_INPUT
{
    float4 PosSS : SV_POSITION;  // [Screen Space] Position
};

[maxvertexcount(3)] 
void main(triangle GS_INPUT input[3], inout TriangleStream<PS_INPUT> outStream)
{
    PS_INPUT output;

    output.PosSS = input[0].PosSS;
    outStream.Append(output);
     
    output.PosSS = input[1].PosSS;
    outStream.Append(output);

    output.PosSS = input[2].PosSS;
    outStream.Append(output);

    outStream.RestartStrip();
}

Here is the error for this example :
dxc 1.8: mymodule.slang(14): error : Semantic TEXTURE is invalid for shader model: gs

I confirm this shader compiles correctly with :

  • FXC gs_5_1
  • DXC gs_6_0

I am honestly disappointed because I intensively use geometry shaders, and that is the only blocking point to adopt Slang in my engine.

Thanks again.

@csyonghe
Copy link
Collaborator

csyonghe commented Jan 27, 2025

I find this to be related to the specific version of dxc you are using.
Note that the error is printed out by dxc 1.8 when compiling the HLSL generated by Slang.

I tried to use latest Slang release to compile your shader with this command:

 .\slangc.exe D:\git_repo\slang\tests\hlsl\geometry-shader.slang -target dxil -entry main -profile gs_6_0

Where slangc.exe is downloaded from the release package, and I am able to get correct result.

In addition, compiling to HLSL with Slang, then compile the HLSL to dxil with DXC also works on my machine:

PS D:\test\bin> .\slangc.exe D:\git_repo\slang\tests\hlsl\geometry-shader.slang -target hlsl -entry main -stage geometry -profile sm_6_0 -o out.hlsl
PS D:\test\bin> dxc out.hlsl -E main -T gs_6_0

Can you verify if you can compile with slangc?

I also tested compiling with the compilation API, and it is also working. What is the version number DXC on your system? Here's mine and it is working:

PS D:\test\bin> dxc --version
dxcompiler.dll: 1.8 - 1.8.0.4775 (d39324e06); dxil.dll: 1.7(101.7.2212.36)

@csyonghe csyonghe added the Needs reporter feedback Bugs awaiting more information from the reporter label Jan 27, 2025
@itamago
Copy link
Author

itamago commented Jan 27, 2025

Hello @csyonghe

Thank you for testing on your side.
I just downloaded Slang v2025.3.2 and DXC released on July 2024 (https://github.com/microsoft/DirectXShaderCompiler/releases/tag/v1.8.2407).
And I confirm that compiling the test file I provided with the command-line you mentioned seems outputting something relevant without any error.

Then, in my C++ code, I updated DXC and Slang to the same versions mentioned before. But Slang is outputting the same error regarding the semantics of the Geometry shader. This error only happens on any Geometry shaders I try to compile..

I am using the C++ code described in my first post. Do you see any obvious mistake, or any missing flag, which could explain the error ?

Thanks again

[EDIT] As shown in my C++ code, I load the shader into memory, remove the UTF8 BOM (if present), then provide this code to Slang.

@csyonghe
Copy link
Collaborator

csyonghe commented Jan 27, 2025

Hmm, I am trying this with the compilation API and I have reproduced the error, let me look into this now.

@itamago
Copy link
Author

itamago commented Jan 27, 2025

Thanks for pointing out the possible issue of wrong DXC dll version.
In my case, both Slang and DXC dlls are copied and present in the same directory, so I doubt it would explain the error, or maybe Slang would manually try the system folders before ? (but that would be really risky to do so without notifying the developer)

[EDIT] Thank you for confirming the issue with the compilation API. I will wait your feedback. Thanks again

@csyonghe csyonghe added goal:quality & productivity Quality issues and issues that impact our productivity coding day to day inside slang and removed Needs reporter feedback Bugs awaiting more information from the reporter labels Jan 27, 2025
@csyonghe
Copy link
Collaborator

@itamago This is now fixed in PR#6197. Thank you for reporting this issue!

@csyonghe csyonghe self-assigned this Jan 28, 2025
@csyonghe csyonghe added this to the Q1 2025 (Winter) milestone Jan 28, 2025
@itamago
Copy link
Author

itamago commented Jan 28, 2025

Hello @csyonghe
Thank you for fixing this issue.
I see you added this PR to a specific milestone in Q1 2025 ; do you have an estimasted date when it will be merged and I could try the fix ?
Thanks again

@csyonghe
Copy link
Collaborator

It’s merged. Please let us know if you are still having issues.

@itamago
Copy link
Author

itamago commented Jan 28, 2025

Hello @csyonghe
I compiled Slang from the latest commit (under Windows), and I confirm the Geometry shaders are now compiling.
Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
goal:quality & productivity Quality issues and issues that impact our productivity coding day to day inside slang
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants