Skip to content

Add GL_EXT_function_control_attributes#335

Open
Karpov-Ruslan wants to merge 1 commit into
KhronosGroup:mainfrom
Karpov-Ruslan:GL_EXT_function_control_attributes
Open

Add GL_EXT_function_control_attributes#335
Karpov-Ruslan wants to merge 1 commit into
KhronosGroup:mainfrom
Karpov-Ruslan:GL_EXT_function_control_attributes

Conversation

@Karpov-Ruslan

Copy link
Copy Markdown

This extension allows to use [[inline]] and [[noinline]] attributes on functions to give a hint to the compiler.

One of the side effects of this extension is the ability to fine-tune function inlining when using spirv-opt. Let's say I have a GLSL compute shader:

#version 460

layout(set = 0, binding = 0, std430) buffer SSBO {
    uint data;
};

void func() {
    // Imagine that there is quite a lot of code here.
    atomicAdd(data, 1U);
    atomicAdd(data, 2U);
    atomicAdd(data, 3U);
    atomicAdd(data, 4U);
    atomicAdd(data, 5U);
    atomicAdd(data, 6U);
    atomicAdd(data, 7U);
    atomicAdd(data, 8U);
    atomicAdd(data, 9U);
}

void main() {
    // There are a lot of `func` calls here.
    func();
    func();
    func();
    func();
    func();
    func();
    func();
    func();
    func();
    func();
}

I'll take this shader and compile it to SPIR-V using glslang (https://godbolt.org/z/adfrb5soW), and then I'll want to use spirv-opt with the -Os flag, which should reduce the size of incoming SPIR-V. But in this case the size will be increased (https://godbolt.org/z/fxv5rjGo9). However, by adding the [[noinline]] attribute to the func function, the DontInline Function Control bit will be added to this function in SPIR-V, so spirv-opt will not inline this function and the size of the outgoing SPIR-V will indeed be reduced (https://godbolt.org/z/d6daKEK5n).

@spencer-lunarg

Copy link
Copy Markdown
Contributor

tl;dr - agree that GLSL should just have a simple way to just expose this and 💯 support this idea

@Karpov-Ruslan I realize that the goal is to stop spirv-opt, but what is the goal after that

Basically I have tried doing this for GPU-AV inside VVL and found that NO ONE actually will honor your DontInline function control mask... the worst part is there is no way to query for support of it neither

NVIDIA 553.31+ does support it, but we have found periodic issues with it, for example, we have to always turn it off for Ray Tracing shaders

... so more of a "heads up"... if you only care about SPIR-V binary size, that is a VERY valid reason as well!

@Karpov-Ruslan

Copy link
Copy Markdown
Author

Basically I have tried doing this for GPU-AV inside VVL and found that NO ONE actually will honor your DontInline function control mask... the worst part is there is no way to query for support of it neither

To be honest, I didn’t even consider it. Sad to hear that. However, SPIR-V Function Control is about hints to the compiler. If the driver developers don't take this into account, it's their full right. Perhaps in the future more and more drivers will support this, so we need to be prepared.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants