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

"DerivativeGroupLinear" not working when compiled with glslang #4305

Closed
jkwak-work opened this issue Jun 7, 2024 · 1 comment · Fixed by #4323
Closed

"DerivativeGroupLinear" not working when compiled with glslang #4305

jkwak-work opened this issue Jun 7, 2024 · 1 comment · Fixed by #4323
Assignees
Labels
goal:quality & productivity Quality issues and issues that impact our productivity coding day to day inside slang kind:bug something doesn't work like it should

Comments

@jkwak-work
Copy link
Collaborator

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 ArielG-NV added kind:bug something doesn't work like it should goal:quality & productivity Quality issues and issues that impact our productivity coding day to day inside slang labels Jun 7, 2024
@ArielG-NV
Copy link
Collaborator

ArielG-NV commented Jun 10, 2024

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.

ArielG-NV added a commit to ArielG-NV/slang that referenced this issue Jun 10, 2024
fixes: shader-slang#4305

The solution is to emit some `layout`s after a module source is emitted.

Added to slangs gfx backend code to enable the compute shader derivative extension for testing purposes.
ArielG-NV added a commit to ArielG-NV/slang that referenced this issue Jun 10, 2024
ArielG-NV added a commit to ArielG-NV/slang that referenced this issue Jun 10, 2024
ArielG-NV added a commit to ArielG-NV/slang that referenced this issue Jun 10, 2024
ArielG-NV added a commit to ArielG-NV/slang that referenced this issue Jun 10, 2024
csyonghe added a commit to ArielG-NV/slang that referenced this issue Jun 10, 2024
csyonghe added a commit that referenced this issue Jun 10, 2024
* Address glslang ordering requirments for 'derivative_group_*NV'

fixes: #4305

The solution is to emit some `layout`s after a module source is emitted.

Added to slangs gfx backend code to enable the compute shader derivative extension for testing purposes.

* address review

* enable removed test

---------

Co-authored-by: Yong He <yonghe@outlook.com>
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 kind:bug something doesn't work like it should
Projects
None yet
2 participants