KhronosGroup / KhronosGroup/GLSL

local workgroup specification while selecting alternative entrypoint

Open
#240 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
458
Forks
114
Avg merge
4m
Merged PRs (30d)
1

Description

To my understanding glslang presently supports for selecting an alternative entrypoints. While working with multiple compute shaders, I wondered what the correct way is to specifcy the workgroup size when their parameters differ for the respective entrypoints.

Consider the following example:

```
[numthreads(1,1,1)]
void shader1() {
}

[numthreads(2,2,2)]
void shader2() {
}
```

This would roughly be mapped like this, but also illustrates the problem. Most glsl snippets the local size is uniformly specified in global scope disassociated from the effective entrypoint so this causes double declaration problem.

```
layout(local_size_x = 1, local_size_y = 1,​ local_size_z = 1​) in;
void shader1() {
}

layout(local_size_x = 2​, local_size_y = 2​, local_size_z = 2​) in;
void shader2() {
}
```

One of the question I have is what is the official approach to this behavior without invoking/relying on preprocessor directives. After some quick tests I noticed this declaration statement can be inside the function body scope, that behavior seems conform the documented grammer outlined in "Ch 9. Shading Language Grammer" of "OpenGL Shading Language, Version 4.60.8".

```
void shader1() { layout(local_size_x = 1, local_size_y = 1,​ local_size_z = 1​) in; }
void shader2() { layout(local_size_x = 2​, local_size_y = 2​, local_size_z = 2​) in; }
```

In specific the "layout_qualifier" is reachable from the "function_definition" however lack of clear documented cases makes me question if it's actually a case of valid or undefined behavior, and/or if I can rely on traditional compiler optimisations e.g. function call elimination to negate the potentional double declaration.

```
layout_qualifier :
LAYOUT LEFT_PAREN layout_qualifier_id_list RIGHT_PAREN <----

single_type_qualifier :
storage_qualifier
layout_qualifier <----
precision_qualifier
interpolation_qualifier
invariant_qualifier
precise_qualifier

type_qualifier :
single_type_qualifier <----
type_qualifier single_type_qualifier

declaration :
function_prototype SEMICOLON
init_declarator_list SEMICOLON
PRECISION precision_qualifier type_specifier SEMICOLON
type_qualifier IDENTIFIER LEFT_BRACE struct_declaration_list RIGHT_BRACE SEMICOLON
type_qualifier IDENTIFIER LEFT_BRACE struct_declaration_list RIGHT_BRACE IDENTIFIER
SEMICOLON
type_qualifier IDENTIFIER LEFT_BRACE struct_declaration_list RIGHT_BRACE IDENTIFIER
array_specifier SEMICOLON
type_qualifier SEMICOLON <----
type_qualifier IDENTIFIER SEMICOLON
type_qualifier IDENTIFIER identifier_list SEMICOLON

declaration_statement :
declaration <----

simple_statement :
declaration_statement <----
expression_statement
selection_statement
switch_statement
case_label
iteration_statement
jump_statement

statement :
compound_statement
simple_statement <----

statement_list :
statement <----
statement_list statement

compound_statement_no_new_scope :
LEFT_BRACE RIGHT_BRACE
LEFT_BRACE statement_list RIGHT_BRACE <----

function_definition :
function_prototype compound_statement_no_new_scope <----
```

Related to:

- https://github.com/KhronosGroup/glslang/issues/605
- https://github.com/KhronosGroup/glslang/issues/1970

Contributor guide

Open the contributing guide

Research direction

Start with the GLSL Shading Language Version 4.60.8 grammar sections cited in the issue and review the related glslang issues 605 and 1970. Establish whether function-scoped local-size layout declarations are valid for alternative compute entry points, then document the official behavior and any required clarification.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.