Skip to content

Implement GL_EXT_spirv_intrinsics_variadic and GL_EXT_spirv_intrinsics_string#4321

Open
rdb wants to merge 2 commits into
KhronosGroup:mainfrom
rdb:spirv-intrinsics-extensions
Open

Implement GL_EXT_spirv_intrinsics_variadic and GL_EXT_spirv_intrinsics_string#4321
rdb wants to merge 2 commits into
KhronosGroup:mainfrom
rdb:spirv-intrinsics-extensions

Conversation

@rdb

@rdb rdb commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

These implement the extensions discussed in KhronosGroup/GLSL#331 that extend GL_EXT_spirv_intrinsics. These are necessary to be able to represent functions like debugPrintfEXT.

This is one PR with separate commits per extension; let me know if I should split this into two PRs instead, but I figured this might be easier since they both touch the parser.

Example

#version 460

#extension GL_EXT_spirv_intrinsics : enable
#extension GL_EXT_spirv_intrinsics_variadic : enable
#extension GL_EXT_spirv_intrinsics_string : enable

spirv_instruction(extensions = ["SPV_KHR_non_semantic_info"],
                  set = "NonSemantic.DebugPrintf", id = 1)
void debugPrintf(spirv_string format, ...);

void main()
{
    debugPrintf("x = %f\n", 1.0);
}

Variadics support

Implements GL_EXT_spirv_intrinsics_variadic (KhronosGroup/GLSL#332). This builds upon the existing variadic parsing that was used for builtins, notably:

  • ... now lexes as a single ELLIPSIS token (so . . . is no longer accepted; doesn't affect existing uses)
  • Zero fixed parameters, like f(...) are now allowed
  • There's a overload tie-break between equivalent candidates if one is variadic and the other isn't, see issue 5
  • Implemented for the 120-330 case as well, which defers to selectFunction (probably worth a separate refactor so that all cases here use selectFunction, but that's out of scope)
  • Accepts spirv_literal and spirv_by_reference qualifiers on the variadic tail

String support

Implements GL_EXT_spirv_intrinsics_string (KhronosGroup/GLSL#333). Adds a new spirv_string type that is only valid in a parameter type of a spirv_instruction function declaration, which is mapped to EbtString.

It should be noted that glslang currently parses strings as a primary-expression, which is laxer than the specified grammar prescribes (which just allows it in a function argument). This basically allows parenthesized strings and the comma operator in relaxation of the spec. This is a pre-existing "issue" that my implementation inherits, because it also applies to GL_EXT_debug_printf, GL_EXT_abort, etc., none of which suggest that strings can be expressions or that such expressions are accepted by these calls.

Embedded NUL characters now cause an error across the board, not scoped to this extension; the previous behavior was silent truncation.

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.

1 participant