microsoft / DirectXShaderCompiler

This repo hosts the source for the DirectX Shader Compiler which is based on LLVM/Clang.
Other
3.11k stars 696 forks source link

Use interface, DXC crashed #6117

Open johnson3d opened 11 months ago

johnson3d commented 11 months ago

Description use interface simply, dxc will crash,but d3dcompile is ok

interface IQueueReadProxy
{
    void GetReadPos(out uint readPos);
};

struct TtQueueReadProxyTest : IQueueReadProxy
{
    void GetReadPos(out uint readPos)
    {
        readPos = 0;
    }
    uint Dequeue1()
    {
        uint readPos = 0;
        GetReadPos(readPos);
        return (uint)readPos;
    }
};

[numthreads(1, 1, 1)]
void CS_ClusterCullingMain(uint DispatchThreadId : SV_DispatchThreadID)
{
    TtQueueReadProxyTest q;
    uint a = q.Dequeue1();
}

Steps to Reproduce

save code in test.hlsl dxc -E CS_ClusterCullingMain -T cs_6_6 -Fo myshader.bin -Zi -Fd myshader.pdb -D MYDEFINE=1 test.hlsl

Actual Behavior

Internal compiler error: access violation. Attempted to read from address 0x00000000000000A8

Environment

llvm-beanz commented 11 months ago

The interface keyword is not supported in HLSL 2016 and later (the versions supported by DXC).

The compiler should not crash, but this code is not valid modern HLSL.

johnson3d commented 11 months ago

The interface keyword is not supported in HLSL 2016 and later (the versions supported by DXC).

The compiler should not crash, but this code is not valid modern HLSL.

I see, so i must use template to do that?

llvm-beanz commented 10 months ago

I see, so i must use template to do that?

If you're using HLSL 2021+ you can use C++ template patterns with SFINAE to get similar results to the legacy interface feature, but aspects of HLSL interface objects are just not supported in HLSL anymore. Specifically, interface objects could be resolved late at PSO creation time. In modern HLSL, all function calls must be resolved at compile time, unless you're building a lib target in which case the rules are a bit more complicated.