This change adds GLSLANG_EXPORT in a couple more places, as well as
adding a new symbol visibility annotation GLSLANG_EXPORT_FOR_TESTS which
is defined the same as GLSLANG_EXPORT but documents the intention that
the symbols marked with it are only meant to be used by glslang's test
suite and do not form part of the public API and are thus not subject to
ABI stability guarantees.
Windows requires symbols to be explicitly exported from DLLs, this
change simply marks the entire spirvbin_t class as exported.
The macros from visibility.h are included inline to get around include
path issues.
This patch tries to attach debug location of a branch/return instruction to its predecessor or the closing brace. If none could be found, no debug info should be emitted.
Symbols in the SPIRV/ directory that are meant to be part of the public
API of glslangnow have GLSLANG_EXPORT annotations that make sure they
will be accessible when building glslang as a shared library if
-fvisibility=hidden is enabled.
Some downstream projects may only link to e.g. the glslang::SPIRV
library and rely on transitive dependencies to pull in everything else.
To keep this working, the SPIRV and MachineIndependent library stubs are
now linked against the glslang library.
Apply memory decorations from GLSL source to the top-level OpVariable.
Previously, these decorations would only be applied to individual
members. While this is correct behavior, it is more convenient for some
front ends to see the decorations (specifically ReadOnly and WriteOnly)
applied to the whole variable rather than individual members.
Without the change `glslang` build fails on upcoming `gcc-15` as:
In file included from /build/source/SPIRV/GlslangToSpv.cpp:45:
SPIRV/SpvBuilder.h:248:30: error: 'uint32_t' has not been declared
248 | Id makeDebugLexicalBlock(uint32_t line);
| ^~~~~~~~
This option increases the max_id_bound in the optimizer to 0x3FFFFFFF, and then runs a
compact-id pass if the final result has a max_id greater than the standard limit of 0x3FFFFF.
Nonsemantic instructions aren't allowed before an OpPhi, so don't emit
line and debug scope instructions when the instruction being emitted is
an OpPhi.
In C++, enums can only represent "in range" values. If the backing
type is not specified, then the result of using bitwise negation on
an enum is not gaurenteed to be in range, resulting in UB.
This was caught by UBSAN, stack trace is as follows:
0. 0x000000000426e391 in spv::operator& (a=spv::MemoryAccessMaskNone,
b=(spv::MemoryAccessVolatileMask | spv::MemoryAccessAlignedMask | spv::MemoryAccessNontemporalMask | spv::MemoryAccessMakePointerVisibleMask | spv::MemoryAccessNonPrivatePointerMask | spv::MemoryAccessAliasScopeINTELMaskMask | spv::MemoryAccessNoAliasINTELMaskMask | unknown: 0xfffcffc0)) at SPIRV/spirv.hpp:2804
1. 0x00000000041e81e0 in (anonymous namespace)::TGlslangToSpvTraverser::accessChainLoad (this=0x7fffffffcbb8, type=...) at SPIRV/GlslangToSpv.cpp:5127
2. 0x00000000041bc059 in (anonymous namespace)::TGlslangToSpvTraverser::visitBinary (this=0x7fffffffcbb8, node=0x5f6a6c8) at SPIRV/GlslangToSpv.cpp:2192
3. 0x0000000003db8660 in glslang::TIntermBinary::traverse (this=0x5f6a6c8, it=0x7fffffffcbb8) at glslang/glslang/MachineIndependent/IntermTraverse.cpp:92
4. 0x0000000003db952e in glslang::TIntermAggregate::traverse (this=0x5f6a7d8, it=0x7fffffffcbb8) at glslang/glslang/MachineIndependent/IntermTraverse.cpp:175
5. 0x00000000042082db in (anonymous namespace)::TGlslangToSpvTraverser::makeGlobalInitializers (this=0x7fffffffcbb8, initializers=...) at SPIRV/GlslangToSpv.cpp:5618
6. 0x00000000041c511f in (anonymous namespace)::TGlslangToSpvTraverser::visitAggregate (this=0x7fffffffcbb8, visit=glslang::EvPreVisit, node=0x5f6a9b8) at SPIRV/GlslangToSpv.cpp:2907
7. 0x0000000003db8fb9 in glslang::TIntermAggregate::traverse (this=0x5f6a9b8, it=0x7fffffffcbb8) at glslang/glslang/MachineIndependent/IntermTraverse.cpp:159
8. 0x00000000041acc04 in glslang::GlslangToSpv (intermediate=..., spirv=..., logger=0x7fffffffdc38, options=0x7fffffffdc2f) at SPIRV/GlslangToSpv.cpp:10398
9. 0x0000000003bfd6f1 in CompileAndLinkShaderUnits (compUnits=...) at StandAlone/StandAlone.cpp:1547
10. 0x0000000003bfe2f8 in CompileAndLinkShaderFiles (Worklist=...) at StandAlone/StandAlone.cpp:1640
11. 0x0000000003bfec2c in singleMain () at StandAlone/StandAlone.cpp:1713
12. 0x0000000003bff4dd in main (argc=5, argv=0x7fffffffe3d8) at StandAlone/StandAlone.cpp:1767
It is invalid if the same decoration is applied to the same id multiple
times. This adds a check before adding a decoration that the decoration
is not already in the list. If it is, then the duplicate is not added.
Fixes#3627
A type can't have a negative number of constituents, components, rows,
or columns. Therefore, the utility functions to query said information
on types and values should return unsigned int rather than int.
This makes things consistent between when glslang is installed and imported versus when it's included as nested CMake project.
You can now use `glslang::glslang` in both cases instead of needing the non-namespaced version sometimes and the namespaced one other times.
Resolves one of the problems discussed in https://github.com/KhronosGroup/glslang/issues/3509
SPIR-V requires that any instruction using the result of an
OpSampledImage instruction be in the same block as the OpSampledImage.
This is hard to guarantee in code generation but easy to fix after the
fact, by simply inserting a new OpSampledImage before the user of its
result if needed, with the new instruction having the same operands as
the original OpSampledImage.
This change adds a new pass to spv::Builder::postProcess that does this.
This might leave the original OpSampledImage instructions "orphaned"
with no users of their result ID, but dead code elimination would take
care of those further down the line.
This function is used to import SPIR-V extended instruction set. It
mistakenly treated the name of SPIR-V extended instruction set as the
name of SPIR-V extension. For example, when we have such code
getExtBuiltins("NonSemantic.DebugBreak")
'NonSemantic.DebugBreak' is added to SPIR-V extension. Rather, the
SPIR-V extension name should be 'SPV_KHR_non_semantics_info'. Therefore,
we must avoid this since the name of SPIR-V extended instruction set is
not necessarily equal to that of relevant SPIR-V extension. Adding a
SPIR-V extension must be done by calling addExtension() explicitly
outside this function.
This change also fixes disassembly issues of debugBreak().
This is intended so that downstream projects consuming glslang with FetchContent or similar means can use `-Wimplicit-fallthrough` without getting warning spam.
I've used my best judgement to determine whether the implicit fallthrough was desired, or was simply unreachable code.
`std::unreachable` is unavailable until C++23, but I saw places where `default: assert(0);` was used, so copied that.
There were a few places where some code might actually have been reachable and intended to return a value that represented an error, so someone should double check that kind of thing.