Generate bindings for uniforms that are not wrapped in a struct Glslang no longer assigns bindings to loose uniforms that are not part of a struct. (see https://github.com/KhronosGroup/glslang/pull/4066) However, Flutter depends on the previous behavior. By default the spirv-cross Metal back end will set the indexes of uniforms based on the order in which they are used within the shader. But Flutter's runtime shader API requires that indexes be set based on where they were declared in the shader. So ImpellerC's Metal back end remaps the uniforms to the desired locations by calling the spirv-cross CompilerMSL::add_msl_resource_binding API. CompilerMSL::add_msl_resource_binding identifies each uniform by its binding. Flutter supports non-struct uniforms on Metal, and thus Flutter requires that every uniform have a unique binding so that it can perform the remapping. This patch restores the legacy behavior where bindings are assigned to all uniforms regardless of whether they are structs. Change-Id: I93e730c21772a19e72af8db77247df1184faaee8
diff --git a/glslang/MachineIndependent/iomapper.cpp b/glslang/MachineIndependent/iomapper.cpp index f37a070..23cc360 100644 --- a/glslang/MachineIndependent/iomapper.cpp +++ b/glslang/MachineIndependent/iomapper.cpp
@@ -1429,6 +1429,11 @@ if (isTensorType(type)) { return EResTensor; } + // Flutter patch: Flutter depends on the legacy behavior where non-struct uniforms + // are assigned unique bindings. + if (isUniformType(type)) { + return EResUbo; + } return EResCount; }
diff --git a/glslang/MachineIndependent/iomapper.h b/glslang/MachineIndependent/iomapper.h index b297cab..05727b8 100644 --- a/glslang/MachineIndependent/iomapper.h +++ b/glslang/MachineIndependent/iomapper.h
@@ -126,6 +126,12 @@ (type.getSampler().isTexture() || type.getSampler().isSubpass())); } + // Flutter patch: Flutter depends on the legacy behavior where non-struct uniforms + // are assigned unique bindings. + static bool isUniformType(const glslang::TType& type) { + return type.getQualifier().storage == EvqUniform; + } + static bool isUboType(const glslang::TType& type) { return type.getQualifier().storage == EvqUniform && type.isStruct(); }