KhronosGroup / KhronosGroup/glslang

Use sized types in SPIR-V generation

Open
#62 6 comments 0 reactions 0 assignees View on GitHub
enhancement SPIR-V
Dominant language
C++
Stars
3.6k
Forks
989
Avg merge
1d 2h
Merged PRs (30d)
31

Description

The SPIR-V generator currently uses `unsigned int` for all its internal representation. However there is no guarantee for this type to be 32 bits (one SPIR-V word) wide.

There are two solutions to this:
- Change the official Khronos headers to generate `uint32_t` for the `Id` typedef and underlying types for enums.
- Change the glslang code to only use `uint32_t` internally.

I would prefer the first option (together with other improvements to the C++ headers) but that requires changing the Khronos code generator and I have no idea whether that is public and if so where to find it/contribute to it (the Khronos bugtracker only has a section for the specification, not the interface files).

In any case, the glslang code as it is right now may produce faulty SPIR-V binaries or fail to load valid SPIR-V binaries if the condition `sizeof(unsigned int) * CHAR_BIT == 32` does not hold on the host platform. As a plus, if the platform does not have an exact 32 bit wide integer the code would fail to compile as the exactly sized typedefs are optional.

There may be similar issues with `float` and `double` if they don't follow the IEEE 754 standard or have unexpected sizes.

Contributor guide

Open the contributing guide

Research direction

The issue names no files, tests, or entry points. Start by locating the SPIR-V generator and the Khronos-generated headers, then trace where unsigned int, enum underlying types, float, and double are used. Done should mean the generator’s host-size assumptions are addressed and portability is covered by relevant build or validation checks.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.