Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spirv: Support initializers on uniforms #1588

Merged
merged 1 commit into from
Jun 4, 2020

Conversation

infapi00
Copy link
Contributor

If a uniform has an initializer it will now be given as the optional
initializer operand to the OpVariable instruction.

Fixes: #1259

Signed-off-by: Neil Roberts nroberts@igalia.com (the code)
Signed-off-by: Alejandro Piñeiro apinheiro@igalia.com (the tests)

@CLAassistant
Copy link

CLAassistant commented Nov 19, 2018

CLA assistant check
All committers have signed the CLA.

@johnkslang
Copy link
Member

What is the specification language backing this change?

Note, you can't really initialize uniforms from a shader; at best it is side-band information, but where does it say this is the way to do that?

@infapi00
Copy link
Contributor Author

What is the specification language backing this change?

Note, you can't really initialize uniforms from a shader; at best it is side-band information, but where does it say this is the way to do that?

Note that as the original issue #1259 already clarified, we are talking about OpenGL/ARB_gl_spirv here. So, from GLSL 4.60 spec, section 4.3.5, "Uniform Variables":

The link-time initial value is either the value of the variable’s
initializer, if present, or 0 if no initializer is present. Opaque types cannot have initializers, or a
compile-time error results.
Example declarations are:

uniform vec4 lightPosition;
uniform vec3 color = vec3(0.7, 0.7, 0.2); // value assigned at link time

Do you want me to update the commit on expilcitly mention that this would be only for OpenGL, and/or include the spec quote?

@johnkslang
Copy link
Member

What's missing is how a SPIR-V OpVariable initializer turns into pre-initialized memory.

Are you assuming that drivers will scan the SPIR-V looking for these? Or, something else?

@johnkslang
Copy link
Member

johnkslang commented Nov 20, 2018

Note that in GLSL, these do not become run-time assignments in the shader, they become side-band data to the driver, and not part of the shader.

@infapi00
Copy link
Contributor Author

What's missing is how a SPIR-V OpVariable initializer turns into pre-initialized memory.

Are you assuming that drivers will scan the SPIR-V looking for these? Or, something else?

The patch is assuming a runtime assignment. But as you are saying below ...

Note that it GLSL, these to not become run-time assignments in the shader, they become side-band data to the driver, and not part of the shader.

... that's true, and a good point.

I get now your original concern, sorry the misunderstanding. After checking the different specs (ARB_gl_spirv/SPIR-V) it is right that there isn't anything supporting this fix.

But in general, there isn't anything about how uniform initializers should be mapped on SPIR-V. This fix is doing a runtime assignment, basically because as far as I see, there is not a clear way to represent it in other way. And if we try to mimic GLSL/OpenGL behaviour, that is link assignment, as you are saying before that would mean scan the SPIR-V and do the uniform assignment, that seems to go somewhat in the opposite direction of how SPIR-V shaders should be linked.

So concluding: I think that it would be better to create a spec issue to try to clarify this.

@infapi00
Copy link
Contributor Author

So concluding: I think that it would be better to create a spec issue to try to clarify this.

In fact, before doing this. While researching for this spec issue, I found the following from the SPIR-V shader, section 3.7 Storage Class, UniformConstant;

UniformConstant Shared externally, visible across all functions in
all invocations in all work groups. Graphics uniform memory. OpenCL
constant memory. Variables declared with this storage class are
read-only. They may have initializers, as allowed by the client API

And from 3.32.8 Memory Instructions, OpVariable:

Initializer is optional. If Initializer is present, it will be the
initial value of the variable’s memory content. Initializer must be an
from a constant instruction or a global (module scope) OpVariable
instruction. Initializer must have the same type as the type pointed
to by Result Type.

So those two spec quotes justifies the implementation. What it is still pending is if we need to clarify how that is used. Looking at the Mesa driver, initializers are included on the internal IR while processing the SPIR-V shader, and then lowered to load a constant. That is basically the same final outcome with a GLSL shader.

Should I still create a spec issue to clarify the GLSL->SPIR-V mapping, or it is enough with those spec quotes?

@johnkslang
Copy link
Member

johnkslang commented Dec 8, 2018

Which client API are you doing this for? Have you seen that it allows this?

@infapi00
Copy link
Contributor Author

infapi00 commented Dec 8, 2018

Which client API are you doing this for? Have you seen that in allows this?

As issue #1259 mentions, we are doing this as part of the ARB_gl_spirv work for the Mesa driver. We try to reuse as much as possible GLSL tests from the piglit suite. Several of them use uniform initializers, and and when converted to SPIR-V, as the issue mentions, uniform initializers were ignored, so the tests fails as the values are not initialized.

Looking at the ARB_gl_spirv or GL_KHR_vulkan_glsl specs, we didn't find anything pointing that GLSL uniform initializers are not supported, although it is true that there isn't also any reference of how they should be mapped. So this commit uses the fact that UniformConstant/OpVariable allow initializers on the SPIR-V spec, as seemed the more straighforward way to support it.

Having said so, if you still think that the mapping is not clear, or even if the feature shouldn't be supported for this case, I could open a spec issue to try to clarify that.

@johnkslang
Copy link
Member

Okay, I didn't see an API protection in the code, but I guess you pick that up automatically, because only OpenGL allows default uniforms to begin with.

In the specification, the closest I see is this:

Corresponding features that GLSL keeps, despite GL_KHR_vulkan_glsl removal:
 . default uniforms (those not inside a uniform block)

I think it should be made more clear whether that includes initializers, and ask whether drivers are supporting that.

@infapi00
Copy link
Contributor Author

Okay, I didn't see an API protection in the code, but I guess you pick that up automatically, because only OpenGL allows default uniforms to begin with.

True. We could add some OpenGL checks if you prefer.

In the specification, the closest I see is this:

Corresponding features that GLSL keeps, despite GL_KHR_vulkan_glsl removal:
 . default uniforms (those not inside a uniform block)

I think it should be made more clear whether that includes initializers, and ask whether drivers are supporting that.

Ok, it makes sense. I think that at this point it is better to clarify this, instead of guessing if it needs to be supported or not. I will create a spec issue soon.

@infapi00
Copy link
Contributor Author

infapi00 commented Mar 1, 2019

Ok, it makes sense. I think that at this point it is better to clarify this, instead of guessing if it needs to be supported or not. I will create a spec issue soon.

The spec has been updated recently, in order to explicitly allow uniform initializers. Could it be possible to revisit this pull request now?

@johnkslang
Copy link
Member

Yes, of course.

Can you sign the CLA?

@infapi00
Copy link
Contributor Author

infapi00 commented Mar 2, 2019

Can you sign the CLA?

Done. It also seams that now there are conflicts with this branch. Will check if it is easy fix and update it now.

@infapi00
Copy link
Contributor Author

infapi00 commented Mar 2, 2019

Done. It also seams that now there are conflicts with this branch. Will check if it is easy fix and update it now.

Done too.

@infapi00
Copy link
Contributor Author

infapi00 commented Mar 2, 2019

Hmm, it is strange. I have just realized that it appears as I didn't sign the LCA. But if I click again the link in order to do that (as I did in the past), I arrive to a page that says that I already signed the agreement. Not sure if Im missing something.

@infapi00
Copy link
Contributor Author

Not sure if Im missing something.

Well, what I was missing is that although I made the pull request in behalf of @bpeel, as he is the author of the patch, he is the one that needs to sign the cla. Silly me. Sorry for that.

@bpeel has just signed it. Sorry for the delay.

@johnkslang
Copy link
Member

We need more tests that show, for example:

  • what happens in the cases where initializers were already handled by another path (make sure we don't initialize twice?)
  • what happens with specialization constants
  • what happens with more complex composites
  • ...

If a uniform has an initializer it will now be given as the optional
initializer operand to the OpVariable instruction.

Fixes: KhronosGroup#1259

Signed-off-by: Neil Roberts <nroberts@igalia.com> (the code)
Signed-off-by: Alejandro Piñeiro <apinheiro@igalia.com> (the tests)
Signed-off-by: Arcady Goldmints-Orlov <agoldmints@igalia.com>
@crzwdjk
Copy link

crzwdjk commented Apr 24, 2020

Hi, I'm taking over this merge request. I added some simple tests, is there anything else I should be testing?

@crzwdjk
Copy link

crzwdjk commented Apr 30, 2020

@johnkslang ping

1 similar comment
@crzwdjk
Copy link

crzwdjk commented May 22, 2020

@johnkslang ping

@johnkslang johnkslang merged commit ff6dcca into KhronosGroup:master Jun 4, 2020
tangent-vector pushed a commit to shader-slang/glslang that referenced this pull request Jul 29, 2020
* wait time increased for the install

* Fix build on CMake 2.8, and fix Web build

And suppress some warnings that are too verbose in Web builds.

* update README

* test names updated

* rayQueryEXT assignment is allowed.

* rayQueryEXT function parameter

* rayQuery test cases added

* compute and fragment shader test_cases added for rayQuery

* const rayFlag defs used in the test cases in stead of numerical values

* .travis updated to origin, rayQueryCheck removed

* spirv.hpp reverted to commit f368dcb

* copyright notice changes removed from unchanged files

* copyright notice changes removed from unchanged files

* copyright notice changes removed from unchanged files

* switch format update

* Add missing braces to if condition

The indentation implies this was the intention. Noticed the issue while trying to compile our code with -Werror -Wall

* pass-by-reference updates

* pass by reference updates

* accelerationStructureEXT - issue KhronosGroup#2152

* accelerationStructureEXT - issue KhronosGroup#2152

* Update spirv-tools known_good to latest stable

* opposite inner condition

* bitwise on boolean

* unused var

* printf format

* Fix KhronosGroup#2163: improve comments for addProcess() and the preamble.

* Remove unused variables.

This CL removes two unused variables from the initialization code.

* Error assigns to objects of rayQueryEXT type.

* Bump revision.

* Build warning: Fix KhronosGroup#2167: Remove nested reuse of 'unreachable'.

* Shader interface matching rework to fix KhronosGroup#2136 (KhronosGroup#2156)

* rework how shader interface block naming rules are handled

* Fixes 2136

According to the spec, shader interfaces (uniform blocks, buffer
blocks, input blocks, output blocks) all should be matched up via
their block names across all compilation units, not instance names.
Also, all block names can be re-used between all 4 interface types
without conflict. This change makes it so all of these blocks are
matched and remapped using block name and not by instance name.
Additional the rule that matched uniform and buffer blocks must
either be anonymous or named (but not nessearily the same name) is
now imposed.

* add warning if instance names differ between matched shader interfaces

* Add test cases from KhronosGroup#2137 which is now fixed as well.

* replace some tab characters with spaces

* buffer blocks and uniform blocks now share the same block namespace

* Remove extra semicolons (KhronosGroup#2170)

This is causing downstream users compiler errors if they have Werror or other
particularly restrictive flags turned on.

* Error message: Finish addressing KhronosGroup#2097, better texture error message.

* Add support for EXT_ray_flags_primitive_culling. (KhronosGroup#2173)

Fixes issue KhronosGroup#2169.

* Get rid of all warnings with MSVC and clang-cl (KhronosGroup#2177)

* Fix KhronosGroup#2178: Allow specialization constants for texel offsets.

* Support multiple swizzled out operands (KhronosGroup#2175)

Swizzled out operands were added in bbbd9a2. This was sufficient
for most tests, but we ran into problems with umulExtended and
imulExtended, which have two.

This CL converts the tracking values to vectors so multiple operands
can be supported.

Test: KHR-GLES31.core.shader_bitfield_operation.*
Test: ctest

* Add support for extension GL_ARB_shader_bit_encoding (KhronosGroup#2183)

* Add support for extension GL_ARB_shader_image_size (KhronosGroup#2185)

* xcode warnings fix (KhronosGroup#2188)

* TPpToken: Fix compiling on clang-10 (KhronosGroup#2189)

* Add support for extension GL_ARB_shader_storage_buffer_object (KhronosGroup#2184)

Enable below features for GL Core version 420:
* layout qualifier "std430"
* storage qualifier "buffer"
* atomic memory functions

* Move to latest SPIR-V header, and bump glslang revision.

* Note about Build Status.

* Move to SPIR-V 1.5 Rev. 3, bump revision, remove a status from README.

* Add support for extension GL_ARB_shading_language_packing (KhronosGroup#2192)

* Remove unused Es310Desktop430 (KhronosGroup#2200)

This variable is no longer used, remove.

* Add support for extension GL_ARB_texture_query_lod. (KhronosGroup#2194)

* Add support for extension GL_ARB_vertex_attrib_64bit (KhronosGroup#2193)

* Fix KhronosGroup#2201: Improve const and copy constructor for TVarLivePair.

* Add support for extension GL_EXT_shader_implicit_conversions
Updated extension management in TIntermediate class.

* Add support for extension GL_EXT_shader_integer_mix (KhronosGroup#2203)

* Add support for es extension GL_EXT_blend_func_extended
* Introduces builtin variables gl_SecondaryFragColorEXT and gl_SecondaryFragDataEXT
* Introduces builtin constant gl_MaxDualSourceDrawBuffersEXT
* enables support for layout qualifier "index" in es profile

* GLSL: Separate out swizzle handling (potentially fixing bugs).

Noticed this when looking at swizzles.  It's at least better structure,
removing hard-to-see early returns, which might be contributing to bugs.

* Fix KhronosGroup#2191: Error check for indexing reference containing unsize array.

* Explicitly mark some enums as unsigned

This allows casting from and to any unsigned value, previously this was
undefined behavior.

This fixes ubsan complaining in `TParseContext::layoutQualifierCheck`,
where `~EShLangComputeMask` is used.

* Fix Web build

* Address KhronosGroup#2211: Improve the copy constructor of TVarLivePair.

* Move to newer version of SPIRV-Tools

* Update tests according to spirv-opt update

We refactored function inlining pass of spirv-opt and it results in
different numbering of result ids in SPIR-V code. This commit updates
test cases to avoid a test failure according to the spirv-opt update.

* Update known good

* Bump version.

* Reserve unused std140 uniform block in reflection, and fix uniform block matrix layout (KhronosGroup#2041)

According to the spec glsl4.60.7:
4.4.5. Uniform and Shader Storage Block Layout Qualifiers:
"The packed qualifier overrides only std140, std430, and shared; other qualifiers are inherited.
When packed is used, no shareable layout is guaranteed. The compiler and linker can optimize
memory use based on what variables actively get used and on other criteria. Offsets must be
queried, as there is no other way of guaranteeing where (and which) variables reside within the
block"

we should reserve std140 block and shared block in reflection.

According to the spec glsl4.60.7:
4.4.5. Uniform and Shader Storage Block Layout Qualifiers:
"The row_major and column_major qualifiers only affect the layout of matrices, including all
matrices contained in structures and arrays they are applied to, to all depths of nesting. These
qualifiers can be applied to other types, but will have no effect."

We need ensure all matrix block member been effect.

Support EShMsgKeepUncalled in reflection

EShMsgKeepUncalled  is a link message for link program.
We need only one option to control uncalled function optimization.
If we set EShMsgKeepUncalled as false in link time, linker won't be keep the uncall function sequence in AST,  and if we set EShMsgKeepUncalled as true in link time, linker will keep all uncalled function sequence in AST.
So, in reflecte time, we just only travers all function sequence. It make EShMsgKeepUncalled  only work at linker, and can effect reflection.

Recursively layout packing to "block member"

layout packing isn't set recursively, it causes TReflection::getOffsets doesn't work correctly.

* Bump version.

* Flatten all interface variables (KhronosGroup#2217)

Specifically, add flattening of arrayed io for geometry and
tesselation shaders. Previously some interface structs just had
builtins split out which caused some interfaces to not be exactly
the same as that of flattened adjacent stages, affecting validation
and correctness.

This obviates builtin splitting. That will be removed in a followup
commit. It was left in for this commit to better exhibit the functional
changes that were made.

Fixes KhronosGroup#1660.

* Add check for DOUBLE in low versions (KhronosGroup#2223)

Add check for DOUBLE in low versions, fix issue KhronosGroup#2206

* Code refine. (KhronosGroup#2227)

* Build: Fix KhronosGroup#2228, by correcting the type used.

* Fix KhronosGroup#2227, which was coded incorrectly, to be simpler/safer.

* Add an option to make Exceptions enabled (KhronosGroup#2239)

* Add an option to make Exceptions enabled

* /EHsc enable exceptions since vs2003

* fix incorrect error when multiple compilation units don't declare layouts (KhronosGroup#2238)

when using multiple compilation units, input/output layouts don't need
to be declared in every unit.

* Do not build glslang-testsuite when ENABLE_CTEST is disabled (KhronosGroup#2240)

* Replace incorrect uint32_t with correct int vars (KhronosGroup#2235)

* Add support for primitive culling layout qualifier. (KhronosGroup#2220)

* Add support for primitive culling layout qualifier.

* Add error checks for primitive flags and negative test.

* Reorder member init to match decl order (KhronosGroup#2241)

Fixes field reorder warning.

* Update spirv tools (KhronosGroup#2246)

* Update known good SPIRV-Tools

* Update test expectations

* Update SPIRV-Tools to stable. Also SPIRV-Headers to TOT. (KhronosGroup#2250)

* Fix missing patch decoration for TessFactor PCF arg (KhronosGroup#2249)

Fixes KhronosGroup#1553

* fix warning unused parameter in release build (KhronosGroup#2251)

* EXT_ray_tracing requires spv1.4 (KhronosGroup#2237)

* EXT_ray_tracing requires spv1.4

* Fix typo.

* Add extension data table.

* Updated feedback #2.

* Remove install to the SPIRV/ folder. (KhronosGroup#2256)

This CL updates the build scripts to only install to glslang/SPIRV
instead of also installing to the SPIRV/ folder. The deprecation notice
is also removed.

Note, this may cause downstream build issues if include directories have
not been updated

Fixes KhronosGroup#1964 KhronosGroup#2216

* Update news for header location change and recommendation.

* Add default descriptorset decoration for acceleration structure (KhronosGroup#2257)

variables.

* HLSL: fix handling of uniform qualifier in entry point parameters (KhronosGroup#2254)

* HLSL: Fix handling of uniforms in entry point parameters

* HLSL: fix handling of "uniform in"

* Tests: Update baseResults of hlsl.function.frag.out for KhronosGroup#2254

* HLSL: fix uniforms in function parameters for opaque types

* HLSL: Recognize POSITION semantic et al in DX9 compatibility mode (KhronosGroup#2255)

* HLSL: Add better diagnostic when using in/out qualifiers in global scope (KhronosGroup#2258)

* Add SPIR-V capabilities needed for spec constants (KhronosGroup#2199)

Fixes KhronosGroup#2198.

* spirv: Support initializers on uniforms (KhronosGroup#1588)

If a uniform has an initializer it will now be given as the optional
initializer operand to the OpVariable instruction.

Fixes: KhronosGroup#1259

Signed-off-by: Neil Roberts <nroberts@igalia.com> (the code)
Signed-off-by: Alejandro Piñeiro <apinheiro@igalia.com> (the tests)
Signed-off-by: Arcady Goldmints-Orlov <agoldmints@igalia.com>

Co-authored-by: Neil Roberts <nroberts@igalia.com>

* Add Shared/Std140 SSBO process & top-level array elements related (KhronosGroup#2231)

* Add Shared/Std140 SSBO process & top-level array elements related
process

1.Add process options for shared/std140 ssbo, following ubo process
2.Add IO Variables reflection option, would keep all input/output
variables in reflection
3.Add Top-level related process, fix top-level array size issues,
following spec
4.Split ssbo/ubo reflection options, merge blowup expanding all into
function blowupActiveAggregate to allow other functions keep same entry
format.

Add options in StandAlone and test symbols.

1. Add options in StandAlone for std140/shared ubo/ssbo and all io variables reflection.
2. Add test for ssbo. When EShReflectionSharedStd140SSBO turns on, generated symbol and output would be different, to remind the difference. Defaultly disabled and nothing would change, nor blocking normal test.

* Add options in runtest script, refresh test results.

Add options in StandAlone:
--reflect-all-io-variables --reflect-shared-std140-ubo --reflect-shared-std140-ssbo

refresh test results.
Now the index, size of unsized array are expected.

* Fix xfb stride limit issue (KhronosGroup#2088)

* Fix xfb_stride limit issue

Unsized array can't apply to transform trace. layout qualifier "offset" require GL_ARB_enhanced_layouts enable or glsl core version > 440.

* Add negative test for xfb limit

* update case result

* Fix compile information issue

Fix compile information issue and test comment issue.

* remove es profile condition, use profileRequires to limit.

* Fix xfb_stride limit issue

Unsized array can't apply to transform trace. layout qualifier "offset" require GL_ARB_enhanced_layouts enable or glsl core version > 440.
Add negative test for xfb limit

* Move es profile check out of version number check

* Adjust error information and related cases

remove the new version check, refine original version check.

* Revert condition for vulkan, and remove redundant test code.

* Use correct type for var storing returned value (KhronosGroup#2263)

* Fix KhronosGroup#2264: OpEntryPoint incorrectly including function parameters.

* Bump code gen version, due to removal of OpEntryPoint operands.

* Fix signed / unsigned mismatch warning (KhronosGroup#2266)

* C Interface: Split SPIR-V C interface to own file

This breaks a cyclic dependency between the SPIRV and glslang build targets.

* HLSL: Fix incorrect case in name of DX9-style cube sampler type (KhronosGroup#2265)

* HLSL: Remove support for having GLSL versions of HLSL intrinsics.

Related to PR KhronosGroup#2265.

* Remove unused function, BaseTypeName (KhronosGroup#2272)

* Remove unused variable. (KhronosGroup#2273)

The `isMat` variable is no longer used in the HLSL parser. Removed.

* CMake: Fold HLSL source into glslang

... and stub the HLSL target.

Fixes the building of shared libraries.

This breaks the cyclic dependency between the `glslang` and `hlsl` targets (by essentially removing the `hlsl` target).

The `BUILD.gn` and `BUILD.bazel` build rules already pull the `HLSL` source into the `glslang` target.

`Android.mk` is the only remaining build config that has a dedicated `HLSL` target, but this is explicity static and does not suffer the same link-time issues with the cyclic dependency (we may wish to stub this target too).

Related issue: KhronosGroup#1484, KhronosGroup#2147
Related PR: KhronosGroup#2267

* Bump version.

* Move hlsl/ source to glslang/HLSL/

Now that the HLSL source files are part of the `glslang` target (KhronosGroup#2271), it makes sense for these to sit in the `glslang` directory.

Changed the case of the directory from `hlsl` to `HLSL` to better match the sibling directories.

* Bump version numbers.

* Build: use better MSVC subfolder names for the previous build changes.

* Add -g0 command line argument

Analogous to gcc, -g0 would strip all debug info.  This is done
regardless of whether optimizations are enabled.

Signed-off-by: Shahbaz Youssefi <ShabbyX@gmail.com>

* Switch ndk_test from gnustl_static to c++_static

gnustl_static is no longer supported.

* Add kokoro configs for android-ndk and cmake

* Update README.md

* Use OpFUnordNotEqual for floating-point !=

The normal IEEE not equal operation tests whether operands are unordered
or not equal (so comparison with a NaN returns true). This corresponds
to the SPIR-V OpFUnordNotEqual, so change to using that.

* Update test results to expect OpFUnordNotEqual

* Update SPIR-V generator version

Change to 10 to reflect the change to generating unordered !=
operations.

* Update test expected files with new magic number

Updating the SPIR-V generator version number changes the output of all
the SPIR-V tests.

* Fixed msvc 2019 nmake compiler warnings with RTTI.
By default cmake generates cxx_flags with `/GR` parameter.
I updated CMAKE_CXX_FLAGS string and replaced `/GR` -> `/GR-`

How to reproduce:

Visual Studio 2019 x64 command port

mkdir build-msvc2019
cd build-msvc2019
cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_LIBDIR=install ..
nmake

COMPILATION BEFORE:

Scanning dependencies of target OSDependent
[  1%] Building CXX object glslang/OSDependent/Windows/CMakeFiles/OSDependent.dir/ossource.cpp.obj
cl : Command line warning D9025 : overriding '/GR' with '/GR-'
ossource.cpp
[  3%] Linking CXX static library OSDependent.lib
[  3%] Built target OSDependent
Scanning dependencies of target OGLCompiler
[  4%] Building CXX object OGLCompilersDLL/CMakeFiles/OGLCompiler.dir/InitializeDll.cpp.obj
cl : Command line warning D9025 : overriding '/GR' with '/GR-'
InitializeDll.cpp
[  6%] Linking CXX static library OGLCompiler.lib
[  6%] Built target OGLCompiler
Scanning dependencies of target glslang
[  7%] Building CXX object glslang/CMakeFiles/glslang.dir/MachineIndependent/glslang_tab.cpp.obj
cl : Command line warning D9025 : overriding '/GR' with '/GR-'
glslang_tab.cpp
[  9%] Building CXX object glslang/CMakeFiles/glslang.dir/MachineIndependent/attribute.cpp.obj
cl : Command line warning D9025 : overriding '/GR' with '/GR-'

FLAGS BEFORE:

-- CMAKE_C_FLAGS:   /DWIN32 /D_WINDOWS /W3
-- CMAKE_CXX_FLAGS: /DWIN32 /D_WINDOWS /W3 /GR /EHsc
-- CMAKE_CXX_FLAGS_DEBUG:   /MDd /Zi /Ob0 /Od /RTC1
-- CMAKE_CXX_FLAGS_RELEASE: /MD /O2 /Ob2 /DNDEBUG

COMPILATION AFTER:

[  1%] Building CXX object glslang/OSDependent/Windows/CMakeFiles/OSDependent.dir/ossource.cpp.obj
ossource.cpp
[  3%] Linking CXX static library OSDependent.lib
[  3%] Built target OSDependent
[  4%] Building CXX object OGLCompilersDLL/CMakeFiles/OGLCompiler.dir/InitializeDll.cpp.obj
InitializeDll.cpp
[  6%] Linking CXX static library OGLCompiler.lib
[  6%] Built target OGLCompiler
[  7%] Building CXX object glslang/CMakeFiles/glslang.dir/MachineIndependent/glslang_tab.cpp.obj
glslang_tab.cpp
[  9%] Building CXX object glslang/CMakeFiles/glslang.dir/MachineIndependent/attribute.cpp.obj

FLAGS AFTER:

-- CMAKE_C_FLAGS:   /DWIN32 /D_WINDOWS /W3
-- CMAKE_CXX_FLAGS: /DWIN32 /D_WINDOWS /W3 /GR- /EHsc
-- CMAKE_CXX_FLAGS_DEBUG:   /MDd /Zi /Ob0 /Od /RTC1
-- CMAKE_CXX_FLAGS_RELEASE: /MD /O2 /Ob2 /DNDEBUG

* Kokoro: Split linux cmake cfgs into static/shared

Allows for testing of generation of both static libraries and shared objects.

The old configs are staying in place until I'm confident everything is working correctly.

Issues: KhronosGroup#1421, KhronosGroup#1484, KhronosGroup#2283

* HLSL: Fix #pragma pack_matrix(row_major) not work on global uniforms

* Add pack_matrix test

* SPV: Partially address KhronosGroup#2293: correct "const in" precision matching.

Track whether formal parameters declare reduced precision and match
that with arguments, and if they differ, make a copy to promote the
precision.

* SPV: Fix KhronosGroup#2293: keep relaxed precision on arg passed to relaxed param

When arguments are copied to make space for a writable formal parameter,
and the formal parameter is relaxed precision, make the copy also
relaxed precision.

* Remove root kokoro/linux-*-cmake configs

These have been superseded by the `static` and `shared` variants in the respective subdirectories.

Issue: KhronosGroup#2283

* CMake: Error on unresolved symbols

Issue: KhronosGroup#1484

* CMake: Compile with -fPIC when building SOs

Without this embedding static libraries into shared libraries may result in link time errors.

Issue: KhronosGroup#2283

* Fixed GCC -Wunused-parameter in hlslParseables.cpp.

Warnings before fix:

[3/7] Building CXX object glslang/CMakeFiles/glslang.dir/HLSL/hlslParseables.cpp.o
../glslang/HLSL/hlslParseables.cpp: In function ‘bool {anonymous}::IsValid(const char*, char, char, char, char, int, int)’:
../glslang/HLSL/hlslParseables.cpp:334:45: warning: unused parameter ‘retOrder’ [-Wunused-parameter]
  334 | inline bool IsValid(const char* cname, char retOrder, char retType, char argOrder, char argType, int dim0, int dim1)
      |                                        ~~~~~^~~~~~~~
../glslang/HLSL/hlslParseables.cpp:334:60: warning: unused parameter ‘retType’ [-Wunused-parameter]
  334 | inline bool IsValid(const char* cname, char retOrder, char retType, char argOrder, char argType, int dim0, int dim1)
      |                                                       ~~~~~^~~~~~~
../glslang/HLSL/hlslParseables.cpp:334:89: warning: unused parameter ‘argType’ [-Wunused-parameter]
  334 | inline bool IsValid(const char* cname, char retOrder, char retType, char argOrder, char argType, int dim0, int dim1)
      |                                                                                    ~~~~~^~~~~~~
../glslang/HLSL/hlslParseables.cpp:334:112: warning: unused parameter ‘dim1’ [-Wunused-parameter]
  334 | inline bool IsValid(const char* cname, char retOrder, char retType, char argOrder, char argType, int dim0, int dim1)
      |                                                                                                            ~~~~^~~~

* SPV: RelaxedPrecision: Generalize fix KhronosGroup#2293 to cover more operations.

This simplifies and enforces use of precision in many more places,
to help avoid accidental loss of RelaxedPrecision through intermediate
operations. Known fixes are:
- ?:
- function return values with mis-matched precision
- precision of function return values when a copy was needed to fix types

* SPV: RelaxedPrecision: use the result precision for texture sampling.

Fix KhronosGroup#2298.

The AST has two precisions, an operation precision and a result precision.
Actual use of GLSL with mediump samplers wants the result precision, so
pick that up instead of the operation precision.

* CMake: break up glslang into smaller static libs

Add `GenericCodeGen` and `MachineIndependent` static library targets.
Privately import both of these into the `glslang` target.
Privately import `MachineIndependent` into the  `SPIRV` target.

This is done to break the dependency of `libglslang.so` non-public APIs from `libspirv.so`,
which will become problematic once `glslang` hides its non-public symbols.

| File                      | Before     |     After  |
|---------------------------|-----------:|-----------:|
| `libGenericCodeGen.a`     |  -         |   `527716` |
| `libglslang.a`            | `68175944` |   `512938` |
| `libHLSL.a`               |     `1428` |     `1428` |
| `libMachineIndependent.a` |  -         | `67132202` |
| `libOGLCompiler.a`        |    `75908` |    `75908` |
| `libOSDependent.a`        |    `23768` |    `23768` |
| `libSPIRV.a`              | `15710210` | `15710210` |
| `libSPVRemapper.a`        |  `3250894` |  `3250894` |

| File                                    | Before     |     After  |
|-----------------------------------------|-----------:|-----------:|
| `libglslang-default-resource-limits.so` |   `117032` |   `117032` |
| `libglslang.so`                         | `22380688` | `22368216` |
| `libHLSL.so`                            |     `7520` |     `7520` |
| `libOGLCompiler.a`                      |    `75908` |    `75908` |
| `libOSDependent.a`                      |    `23768` |    `23768` |
| `libSPIRV.so`                           |  `7288336` | `28151016` |
| `libSPVRemapper.so`                     |  `1940208` |  `1940208` |

Issues: KhronosGroup#2283, KhronosGroup#1484

* glslang: Only export public interface for SOs

Default to `-fvisibility=hidden`, and annotate the public glslang interface with `GLSLANG_EXPORT` to change the visibility of these cherry-picked symbols to default.
This is also used by Windows builds for `__declspec(dllexport)`-ing the public DLL interface.

This allows us to classify API changes into those that are publicly backwards compatible, and those that are not.

Note that `libSPIRV` will likely need similar treatment.

Issues: KhronosGroup#2283, KhronosGroup#1484

* HLSL: Catch error cases earlier, preventing a later assert.

Related to KhronosGroup/SPIRV-Cross#1414.
The real problem is either using DX10 semantics for DX9 or missing
functionality in DX10 parsing.

* Add additional licenses in use to LICENSE.txt

Ideally we'd unify the licenses in use by changing the licenses in the file headers to BSD-3-clause.

Until then, let's correctly list all the licenses currently in use.

Issue: KhronosGroup#2305

* Tests: More broadly use automapping binding/location.

This adds or changes binding/location decorations in 100s of shaders.
It also allows more output (spv.register.autoassign.rangetest.frag)
due to allowing ioMap() to fail.

* SPIRV-Tools and tests: Update to location-validation in SPIRV-Tools.

This introduces five new "Validation failures":
- baseResults/hlsl.semantic.vert: issue with gl_ClipDistance/CullDistance
- baseResults/spv.430.vert: issue gl_ClipDistance
- baseResults/spv.450.tesc: still unknown
- baseResults/spv.dataOut.frag: gl_FragData should not be supported, problem with front end
- baseResults/spv.meshShaderPerViewUserDefined.mesh: seems okay, maybe a problem with SPIRV-Tools

* Bump revision.

* Add missing copyright headers

Add copyright headers to build files and scripts.
Simplifies automated scanning for bad license headers.

* Fix GLSLANG_IS_SHARED_LIBRARY define

It was incorrectly always being set, causing linker warnings for MSVC builds.
Also simplify the preprocessor nesting in `glslang\Public\ShaderLang.h`

* Add config for license-checker and Kokoro scripts.

The `license-checker` is a tool that verifies each file has contains a permitted license header.

See https://github.com/ben-clayton/license-checker for more information.

* Kokoro: Correct the `build_file' path to build.sh

* License headers: s/Google/The Khronos Group

This was a copy-paste screwup, where the first line of the copyright had the company name was updated, but the company name mid way though was not.

* Don't use add_link_options() on old CMake versions

Fixes: KhronosGroup#2315

* gn: Optionally disable optimizations and HLSL

To reduce the binary size of ANGLE, a gn override is added
(glslang_angle) which:

- Controls whether ENABLE_OPT=1 is set
- Customizes the build for the Vulkan backend of ANGLE.  As a first
  step, this removes HLSL functionality which together with no
  optimization shave ~2.5MB off of ANGLE's binary size.

Upcoming changes will add a macro for GLSLANG_ANGLE similar to
GLSLANG_WEB that will strip features from glslang to support only what
ANGLE needs.

Signed-off-by: Shahbaz Youssefi <ShabbyX@gmail.com>

* Add GLSLANG_BUILD_PIC CMake flag

Enables `-fPIC` compiler flag even when building statically.
This is helpful for statically linking a `glslang` target into a shared library.

Simplifies the workarounds seen in google/shaderc#1093 to a `set(GLSLANG_BUILD_PIC 1)`.

* gn: Fix `gn gen --check` by adding missing dependency

Signed-off-by: Shahbaz Youssefi <ShabbyX@gmail.com>

* gn: Fix dawn tests in Chromium

Dawn tests use shaderc, which assumes glslang has HLSL support.  This
change makes HLSL support also follow template arguments, and changes
the target names such that glslang_sources will remain the "has all
features" target and the new glslang_lib_sources would be what ANGLE
would use.

Signed-off-by: Shahbaz Youssefi <ShabbyX@gmail.com>

* Add --quiet option.

Being quiet should have been the default, but I guess it's too late
now to change it.

* Add new rules to .gitignore

`.vscode/` ignores Visual Studio Code user config files
`bazel-*` ignores bazel build system symlinks.
`out/` ignores the default output directory for Visual Studio generated files.

* Add new static targets to VS solution folders

`GenericCodeGen` and `MachineIndependent` were missing from the generated visual studio solutions. Add these.

* Remove GLSLANG_BUILD_PIC flag

On closer inspection, it appears that nearly all the targets use the `POSITION_INDEPENDENT_CODE` target option anyway.
Simplify all this away by always being PIC.

* Use CMake's builtin functionality for PCHs

`glslang_pch()` did manual mangling of the compiler flags to enable pre-compiled headers.
I couldn't get this approach to work with the `MachineIndependent` subdirectory, but fortunately CMake has added first-class support for precompiled headers in 3.16, which does work with subdirectories.

Moved `glslang_pch()` to the other global function declarations.

`glslang_pch()` is a no-op when using CMake earlier than `3.16`.

CMake's PCH implementation does not need the `pch.cpp` files, so just remove them.

* Make sure glslang_angle has a definition in BUILD.gn

Set the value to false if the environment doesn't declare this variable.

* Use GLSLANG_ANGLE to strip features to what ANGLE requires

This change strips a few features similar to GLSLANG_WEB but doesn't
remove every detail like the latter.  It also hardcodes profile/version
to core/450.

In particular, TBuiltIns::initialize is specialized to remove most of
what is not supported or won't be supported by ANGLE.  The result of
this function is parsed with TParseContext::parseShaderStrings which is
a performance bottleneck.

This change shaves about 300KB off of ANGLE's binary size and reduces
the cost of SetupBuiltinSymbolTable to nearly a sixth.

Signed-off-by: Shahbaz Youssefi <ShabbyX@gmail.com>

* Customize glslang.y to GLSLANG_ANGLE

glslang.y is specialized to remove what is not supported or won't be
supported by ANGLE.

This change shaves about 125KB off of ANGLE's binary size with minor
improvement to the cost of SetupBuiltinSymbolTable.

Signed-off-by: Shahbaz Youssefi <ShabbyX@gmail.com>

* Generate build information from CHANGES.md

This PR significantly reworks the way glslang is versioned.

Instead of committing changes to the `GLSLANG_MINOR_VERSION` define in
`glslang/Public/ShaderLang.h`, and using `make-revision` to generate
`GLSLANG_PATCH_LEVEL` in `glslang/Include/revision.h`, all version
information is now derived from the new `CHANGES.md` file.

`CHANGES.md` acts as the single source of truth for glslang version
information, along with a convenient place to put all release notes for
each notable change made.

`CHANGES.md` is parsed using the new `build_info.py` python script.
This script can read basic template files to produce new source files,
which it does to read the new `build_info.h.tmpl` to generate (at build
time) a glslang private header at
`<build-dir>/include/glslang/build_info.h`.
I've written generators for each of the CMake, Bazel, gn, and
`Android.mk` build scripts.

The new version code conforms to the Semantic Versioning 2.0 spec.

This new version is also used by the CMake rules to produce versioned
shared objects, including a major-versioned SONAME.

New APIs:
---------

* `glslang::GetVersion()` returns a `Version` struct with the version
  major, minor, patch and flavor.

Breaking API changes:
---------------------

* The public defines `GLSLANG_MINOR_VERSION` and `GLSLANG_PATCH_LEVEL`
  have been entirely removed.
* `glslang/Public/ShaderLang.h` and `glslang/Include/revision.h` have
  been deleted.
* Instead, `<build-dir>/include/glslang/build_info.h` is created in
  the build directory, and `<build-dir>/include` is a CMake `PUBLIC`
  (dependee-inherited) include directory for the glslang targets.
* `<build-dir>/include/glslang/build_info.h` contains the following
   new #defines:
   `GLSLANG_VERSION_MAJOR`, `GLSLANG_VERSION_MINOR`,
   `GLSLANG_VERSION_PATCH`, `GLSLANG_VERSION_FLAVOR`,
   `GLSLANG_VERSION_GREATER_THAN(major, minor, patch)`,
   `GLSLANG_VERSION_GREATER_OR_EQUAL_TO(major, minor, patch)`,
   `GLSLANG_VERSION_LESS_THAN(major, minor, patch)`,
   `GLSLANG_VERSION_LESS_OR_EQUAL_TO(major, minor, patch)`
*  The CMake install output directory contains a copy of
   `build_info.h` at: `include/glslang/build_info.h`
*  Python3 is now always required to build glslang (likely always
   required for transitive dependency builds).

* Attempt to fix chromium builds

It would seem that `glslang_sources` has a private dependency on `glslang_build_info`, so `glslang_validator` cannot transitively `#include` the generated `glslang/build_info.h` header.

Add `glslang_build_info` as a direct dependency to `glslang_validator`.
Also remove the duplicate dependency on `glslang_build_info` in `glslang_sources_common`

Note: This is a speculative fix as I can build Chromium fine without these changes.
Not sure what's different between these configs.

* Fix CMake rules when nesting CMake projects

`${CMAKE_SOURCE_DIR}` points to the outer project root, not the current directory.

Fixes building of `glslang` when included into another CMake project.

* Common: include standard headers before doing any defines

currently, due to

```c++
\#if (defined(_MSC_VER) && _MSC_VER < 1900 /*vs2015*/) || defined MINGW_HAS_SECURE_API
    #include <basetsd.h>
    #ifndef snprintf
    #define snprintf sprintf_s
    #endif
    #define safe_vsprintf(buf,max,format,args) vsnprintf_s((buf), (max), (max), (format), (args))
```

defining `snprintf` to `sprintf_s` essentially unconditionally, this will break the
stdio.h+cstdio system header for mingw-w64 g++ in msys2 with shaderc
google/shaderc#1065

an alternative change would be
https://raw.githubusercontent.com/shinchiro/mpv-winbuild-cmake/master/packages/glslang-0001-fix-gcc-10.1-error.patch
in which the `|| defined MINGW_HAS_SECURE_API` part is removed

Signed-off-by: Christopher Degawa <ccom@randomderp.com>

* Add missing comma from license-checker.cfg

Fixes license checker presubmit.

* Fix KhronosGroup#2329: don't use invalid initializers.

* Fix a couple lines that were too long, to retrigger bots.

* Revert "Merge pull request KhronosGroup#2330 from ShabbyX/optimize_for_angle"

This reverts commit 1ee5d1c, reversing
changes made to 906d48a.

* Fix comma in licence checker.

* Kokoro: Print test output to stdout

* CMake: Move project() to top of CMakeLists.txt

Also remove `NOTICE` from message() about PCHs - it seems to print this in the actual message, contrary to the documentation where it is used as a severity.

* Add bison license to LICENSE.txt

* Non-determinism: Remove test file that seems to trigger non-determinism.

This problem needs to be fixed, but in parallel, we need to see master
and any other changes to it passing all tests.

The removed test is ray-tracing centric, and may indicate non-determinism
in recent code added for that functionality.

* Fix recently found non-determinism with gl_WorldToObject3x4EXT.

* Give build_info.py the executable bit

* runtests: Check error codes, set LD_LIBRARY_PATH

`glslangValidator` will only return [the codes 0..6](https://github.com/KhronosGroup/glslang/blob/b481744aea1ecf52ee4591afaa0f5e270b9d1636/StandAlone/StandAlone.cpp#L117-L125). Fail the test if anything else is returned (like due to the exe crashing).

Also set `LD_LIBRARY_PATH` to contain the `lib` directory before calling glslang.

* GLSL/SPV: Propagaet precision qualifier from function to return value.

When a return value's type has no precision qualification (e.g., the return
expression is formed from a constructor), and the formal function return type
has a precision qualification, back propagate that from the return type to the
type of the return value's expression.

* Add new rules for update of license-checker

`license-checker` will be updated to support `**` based wildcards. As part of this, `license-checker` will now traverse into subdirectories that would previously be excluded when the parent directory is excluded.

This change adds new rules that work with both the old version and new, to ease migration.

* Update license-checker.cfg with simplified rules

`license-checker` has been updated to support `**` wildcards simplifying the ruless, and multiple license configs.

Add a new config for the bison generated files to ensure their licenses don't change.

* build_info: Fix parsing of versions with no flavor

* Finalize glslang 10.15.3847

* Start glslang 11.0.0

* Drop support for VS2013

This was scheduled for today - 20th July 2020.

Updates Appveyor configs to use VS2015 instead.

* also search global variables assignment for live variables

when traversing the AST to find live UBOs etc, also traverse
references to global module-level variables, incase they are
being filled in from UBOs etc.

* Simplify PoolAlloc with use of thread_local.

glslang is using C++ 11, which has first class support for variables of the `thread_local` storage class.

By dropping the use of the `OS_[GS]etTLSValue`, we can simplify the logic, and have it support a thread-local default allocator if none is provided.

Issue: KhronosGroup#2346

* Deprecate InitializeDll functions

These were only used for TThreadPool, which now uses `thread_local`.

* SPV: Update to the latest SPIR-V headers.

* Limit visibility of symbols for internal libraries

Also remove `SPIRV/doc.cpp` from the `SPVRemapper` target as this
is part of `SPIRV`, causing ODR violations. Instead have
`SPVRemapper` link against `SPIRV`.

Fixes ODR violations.

* Add changes for SPV_EXT_shader_atomic_float_add

* Update spirv-tools known-good to most recent stable

Co-authored-by: Neslisah Torosdagli <neslisah.torosdagli@amd.com>
Co-authored-by: Kai Ninomiya <kainino@chromium.org>
Co-authored-by: John Kessenich <johnkslang@users.noreply.github.com>
Co-authored-by: Geoffrey Martin-Noble <gcmn@google.com>
Co-authored-by: Neslisah Torosdagli <neslimsah@yahoo.com>
Co-authored-by: Greg Fischer <greg@lunarg.com>
Co-authored-by: ntfs.hard <ntfs.hard@gmail.com>
Co-authored-by: John Kessenich <cepheus@frii.com>
Co-authored-by: dan sinclair <dsinclair@google.com>
Co-authored-by: alelenv <alele@nvidia.com>
Co-authored-by: Malcolm Bechard <mbechard@users.noreply.github.com>
Co-authored-by: Ryan Harrison <rharrison@google.com>
Co-authored-by: alelenv <40001162+alelenv@users.noreply.github.com>
Co-authored-by: Malacath-92 <h.baensch.92@gmail.com>
Co-authored-by: Cody Northrop <cnorthrop@google.com>
Co-authored-by: pmistryNV <63069047+pmistryNV@users.noreply.github.com>
Co-authored-by: MennoVink <mennovink20@hotmail.com>
Co-authored-by: Phillip Stephens <antidote.crk@gmail.com>
Co-authored-by: dan sinclair <dj2@everburning.com>
Co-authored-by: Pankaj Mistry <pmistry@nvidia.com>
Co-authored-by: Sebastian Neubauer <sebastian.neubauer@amd.com>
Co-authored-by: Felix Maier <xilefmai@gmail.com>
Co-authored-by: Jaebaek Seo <duke.acacia@gmail.com>
Co-authored-by: Roy.li <lryer@msn.com>
Co-authored-by: Chow <laddoc@outlook.com>
Co-authored-by: nihui <shuizhuyuanluo@126.com>
Co-authored-by: David Neto <dneto@google.com>
Co-authored-by: alan-baker <alanbaker@google.com>
Co-authored-by: rdb <rdb@users.noreply.github.com>
Co-authored-by: Ricardo Garcia <47594367+rg3igalia@users.noreply.github.com>
Co-authored-by: Alejandro Piñeiro <apinheiro@igalia.com>
Co-authored-by: Neil Roberts <nroberts@igalia.com>
Co-authored-by: Ben Clayton <bclayton@google.com>
Co-authored-by: Shahbaz Youssefi <ShabbyX@gmail.com>
Co-authored-by: Graeme Leese <gleese@broadcom.com>
Co-authored-by: Evgeny Proydakov <e.proydakov@gmail.com>
Co-authored-by: lriki <lriki.net@gmail.com>
Co-authored-by: Marcin Ślusarz <marcin.slusarz@intel.com>
Co-authored-by: Christopher Degawa <ccom@randomderp.com>
Co-authored-by: Malcolm Bechard <malcolm@derivative.ca>
Co-authored-by: johnkslang <john@johnkgo.com>
Co-authored-by: Vikram Kushwaha <vkushwaha@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Uniform initializers are silently ignored in the generated SPIR-V
5 participants