shader-slang / slang

Making it easier to work with shaders
MIT License
1.79k stars 160 forks source link

"DerivativeGroupLinear" not working when compiled with glslang #4305

Closed jkwak-work closed 4 weeks ago

jkwak-work commented 1 month ago

Problem description The extension for a keyword, "DerivativeGroupLinear", appears to require the group size to be declared before.

layout(local_size_x = 4, local_size_y = 1, local_size_z = 1) in; // <== must appear first
layout(derivative_group_linearNV) in;

I didn't see any mention about the ordering on the document. And it could be a bug in glslang.

Repro step The following test can reproduce the issue.

//TEST:SIMPLE(filecheck=GLSL): -stage compute  -entry computeMain -target glsl
//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -compute -entry computeMain -output-using-type -emit-spirv-via-glsl

//TEST_INPUT: ubuffer(data=[0], stride=4):out,name outputBuffer
RWStructuredBuffer<float> outputBuffer;

//TEST_INPUT: Texture2D(size=4, content = one):name t2D
Texture2D<float> t2D;

//TEST_INPUT: Sampler:name samplerState
SamplerState samplerState;

// "local_size_x" must appear before "derivative_group_linearNV"
//GLSL:local_size_x
//GLSL:derivative_group_linearNV

[DerivativeGroupLinear]
[numthreads(4, 1, 1)]
void computeMain()
{
    //BUF:1
    outputBuffer[0] = t2D.Sample(samplerState, float2(0.5, 0.5));
}

Note that the issue cannot be reproduced when using "-emit-spirv-directly". The issue appears to be more related to glslang.

Goal Emit "local_size_x" before "derivative_group_linearNV". Or figure out if it is a bug in glslang.

ArielG-NV commented 4 weeks ago

This issue is likely a bug with glslang validation, none of the posted specifications online say anything about order (https://github.com/KhronosGroup/GLSL/blob/main/extensions/nv/GLSL_NV_compute_shader_derivatives.txt). Regardless, we need a fix for the glslang bug or not because else the code won't compile.