shader-slang / slang

Making it easier to work with shaders
MIT License
1.94k stars 166 forks source link

-capability dont work with -emit-spirv-directly #3465

Closed vkensou closed 7 months ago

vkensou commented 7 months ago

I tried slangc 2023.5.5. the shader code:

static const float4 positions[3] = {
    float4( 0.0,  0.5, 0, 1),
    float4(-0.5, -0.5, 0, 1),
    float4( 0.5, -0.5, 0, 1)
};

static const float3 colors[3] = {
    float3(1.0, 0.0, 0.0),
    float3(0.0, 1.0, 0.0),
    float3(0.0, 0.0, 1.0),
};

struct VSInput
{
    uint vertexId : SV_VERTEXID;
};

struct VSOutput
{
    float4 Pos : SV_POSITION;
    [[vk::location(0)]]
    float3 Color : COLOR0;
};

[shader("vertex")]
VSOutput vert(VSInput input)
{
    VSOutput output = (VSOutput)0;
    output.Color = colors[input.vertexId];
    output.Pos = positions[input.vertexId];
    return output;
}

[shader("pixel")]
float4 frag(VSOutput input) : SV_TARGET
{
    return float4(input.Color, 1);
}

command line is :

.\slangc hello.hlsl -profile sm_5_0 -target spirv-asm -capability spirv_1_1 -entry vert -o shaders\hello.vert.spv -O3 -emit-spirv-directly

the output spirv-asm is:

; SPIR-V
; Version: 1.5
; Generator: Khronos; 40
; Bound: 43
; Schema: 0

If I remove the "-emit-spirv-directly" option, the spirv-asm version will be Version: 1.1

csyonghe commented 7 months ago

Our direct-to-spirv backend will always emit spirv 1.5. It is the only target spirv version that is currently implemented. So this is expected.

vkensou commented 7 months ago

Our direct-to-spirv backend will always emit spirv 1.5. It is the only target spirv version that is currently implemented. So this is expected.

Does you have any plan support other spirv version?

vkensou commented 7 months ago

Our direct-to-spirv backend will always emit spirv 1.5. It is the only target spirv version that is currently implemented. So this is expected.

去掉-emit-spirv-directly后生成的spirv,贴图和sampler的名字都加了一个“_0”后缀,请问这样符合预期吗?怎么才能去掉这个后缀?

csyonghe commented 7 months ago

不用-emit-spirv-directly的时候,slang会先生成GLSL再调用glslang生成spirv。因为要经过GLSL,为了避免潜在的命名冲突问题,slang会在所有的标识符后面增加_0 _1等后缀。这个方法简单粗暴了些,但我们目前没有实现更好的办法来避免生成这些后缀。如果想要干净的名字,唯一的办法是使用-emit-spirv-directly。

vkensou commented 7 months ago

不用-emit-spirv-directly的时候,slang会先生成GLSL再调用glslang生成spirv。因为要经过GLSL,为了避免潜在的命名冲突问题,slang会在所有的标识符后面增加_0 _1等后缀。这个方法简单粗暴了些,但我们目前没有实现更好的办法来避免生成这些后缀。如果想要干净的名字,唯一的办法是使用-emit-spirv-directly。

好吧,那我还是期待一下直出spirv可以设置spirv的version吧。。。