Title: [271334] trunk/Source/ThirdParty/ANGLE
Revision
271334
Author
[email protected]
Date
2021-01-08 16:10:24 -0800 (Fri, 08 Jan 2021)

Log Message

Failures of attribute location conformance tests with Metal backend
https://bugs.webkit.org/show_bug.cgi?id=220137

Patch by Kyle Piddington <[email protected]> on 2021-01-08
Reviewed by Dean Jackson.

* src/compiler/translator/TranslatorMetalDirect/EmitMetal.cpp:
(GenMetalTraverser::emitAttributeDeclaration):
* src/libANGLE/renderer/metal/mtl_glslang_mtl_utils.mm:
(rx::mtl::updateShaderAttributes):
(rx::mtl::GlslangGetMSL):

Modified Paths

Diff

Modified: trunk/Source/ThirdParty/ANGLE/ChangeLog (271333 => 271334)


--- trunk/Source/ThirdParty/ANGLE/ChangeLog	2021-01-09 00:03:32 UTC (rev 271333)
+++ trunk/Source/ThirdParty/ANGLE/ChangeLog	2021-01-09 00:10:24 UTC (rev 271334)
@@ -1,3 +1,16 @@
+2021-01-08  Kyle Piddington  <[email protected]>
+
+        Failures of attribute location conformance tests with Metal backend
+        https://bugs.webkit.org/show_bug.cgi?id=220137
+
+        Reviewed by Dean Jackson.
+
+        * src/compiler/translator/TranslatorMetalDirect/EmitMetal.cpp:
+        (GenMetalTraverser::emitAttributeDeclaration):
+        * src/libANGLE/renderer/metal/mtl_glslang_mtl_utils.mm:
+        (rx::mtl::updateShaderAttributes):
+        (rx::mtl::GlslangGetMSL):
+
 2021-01-04  Fujii Hironori  <[email protected]>
 
         [WinCairo][CMake][MSBuild][ANGLE] entry_points_*.h was generated twice both in LibGLESv2EntryPointsHeaders and GLESv2 projects

Modified: trunk/Source/ThirdParty/ANGLE/src/compiler/translator/TranslatorMetalDirect/EmitMetal.cpp (271333 => 271334)


--- trunk/Source/ThirdParty/ANGLE/src/compiler/translator/TranslatorMetalDirect/EmitMetal.cpp	2021-01-09 00:03:32 UTC (rev 271333)
+++ trunk/Source/ThirdParty/ANGLE/src/compiler/translator/TranslatorMetalDirect/EmitMetal.cpp	2021-01-09 00:10:24 UTC (rev 271334)
@@ -1226,7 +1226,7 @@
     EmitVariableDeclarationConfig evdConfig;
     evdConfig.disableStructSpecifier = true;
     emitVariableDeclaration(VarDecl(field), evdConfig);
-    mOut << " [[attribute(" << annotationIndices.attribute++ << ")]]";
+    mOut << rx::mtl::kUnassignedAttributeString;
 }
 
 void GenMetalTraverser::emitStructDeclaration(const TType &type)

Modified: trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_common.h (271333 => 271334)


--- trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_common.h	2021-01-09 00:03:32 UTC (rev 271333)
+++ trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_common.h	2021-01-09 00:10:24 UTC (rev 271334)
@@ -25,6 +25,7 @@
 #include "libANGLE/ImageIndex.h"
 #include "libANGLE/Version.h"
 #include "libANGLE/angletypes.h"
+#include "libANGLE/renderer/metal/mtl_constants.h"
 
 #if TARGET_OS_IPHONE
 #    if !defined(__IPHONE_11_0)
@@ -118,73 +119,11 @@
 
 namespace mtl
 {
-
-// NOTE(hqle): support variable max number of vertex attributes
-constexpr uint32_t kMaxVertexAttribs = gl::MAX_VERTEX_ATTRIBS;
-// NOTE(hqle): support variable max number of render targets
-constexpr uint32_t kMaxRenderTargets = 4;
-
-constexpr uint32_t kMaxShaderUBOs = 12;
-constexpr uint32_t kMaxUBOSize    = 16384;
-
-constexpr uint32_t kMaxShaderXFBs = gl::IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS;
-
-// The max size of a buffer that will be allocated in shared memory.
-// NOTE(hqle): This is just a hint. There is no official document on what is the max allowed size
-// for shared memory.
-constexpr size_t kSharedMemBufferMaxBufSizeHint = 128 * 1024;
-
-constexpr size_t kDefaultAttributeSize = 4 * sizeof(float);
-
-// Metal limits
-constexpr uint32_t kMaxShaderBuffers     = 31;
-constexpr uint32_t kMaxShaderSamplers    = 16;
-constexpr size_t kInlineConstDataMaxSize = 4 * 1024;
-constexpr size_t kDefaultUniformsMaxSize = kInlineConstDataMaxSize;
-constexpr uint32_t kMaxViewports         = 1;
-
-constexpr uint32_t kVertexAttribBufferStrideAlignment = 4;
-// Alignment requirement for offset passed to setVertex|FragmentBuffer
-#if TARGET_OS_OSX || TARGET_OS_MACCATALYST
-constexpr uint32_t kUniformBufferSettingOffsetMinAlignment = 256;
-#else
-constexpr uint32_t kUniformBufferSettingOffsetMinAlignment = 4;
-#endif
-constexpr uint32_t kIndexBufferOffsetAlignment       = 4;
-constexpr uint32_t kArgumentBufferOffsetAlignment    = kUniformBufferSettingOffsetMinAlignment;
-constexpr uint32_t kTextureToBufferBlittingAlignment = 256;
-
-// Font end binding limits
-constexpr uint32_t kMaxGLSamplerBindings = 2 * kMaxShaderSamplers;
-constexpr uint32_t kMaxGLUBOBindings     = 2 * kMaxShaderUBOs;
-
-// Binding index start for vertex data buffers:
-constexpr uint32_t kVboBindingIndexStart = 0;
-
-// Binding index for default attribute buffer:
-constexpr uint32_t kDefaultAttribsBindingIndex = kVboBindingIndexStart + kMaxVertexAttribs;
-// Binding index for driver uniforms:
-constexpr uint32_t kDriverUniformsBindingIndex = kDefaultAttribsBindingIndex + 1;
-// Binding index for default uniforms:
-constexpr uint32_t kDefaultUniformsBindingIndex = kDefaultAttribsBindingIndex + 3;
-// Binding index for Transform Feedback Buffers (4)
-constexpr uint32_t kTransformFeedbackBindingIndex = kDefaultUniformsBindingIndex + 1;
-// Binding index for shadow samplers' compare modes
-constexpr uint32_t kShadowSamplerCompareModesBindingIndex = kTransformFeedbackBindingIndex + 4;
-// Binding index for UBO's argument buffer
-constexpr uint32_t kUBOArgumentBufferBindingIndex = kShadowSamplerCompareModesBindingIndex + 1;
-
-constexpr uint32_t kStencilMaskAll = 0xff;  // Only 8 bit stencil is supported
-
 // This special constant is used to indicate that a particular vertex descriptor's buffer layout
 // index is unused.
 constexpr MTLVertexStepFunction kVertexStepFunctionInvalid =
     static_cast<MTLVertexStepFunction>(0xff);
 
-constexpr float kEmulatedAlphaValue = 1.0f;
-
-constexpr uint32_t kOcclusionQueryResultSize = sizeof(uint64_t);
-
 // Work-around the enum is not available on macOS
 #if TARGET_OS_OSX || TARGET_OS_MACCATALYST
 constexpr MTLBlitOption kBlitOptionRowLinearPVRTC = MTLBlitOptionNone;

Modified: trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_constants.h (271333 => 271334)


--- trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_constants.h	2021-01-09 00:03:32 UTC (rev 271333)
+++ trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_constants.h	2021-01-09 00:10:24 UTC (rev 271334)
@@ -27,6 +27,13 @@
 constexpr uint32_t kMaxShaderUBOs = 12;
 constexpr uint32_t kMaxUBOSize    = 16384;
 
+constexpr uint32_t kMaxShaderXFBs = gl::IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS;
+
+// The max size of a buffer that will be allocated in shared memory.
+// NOTE(hqle): This is just a hint. There is no official document on what is the max allowed size
+// for shared memory.
+constexpr size_t kSharedMemBufferMaxBufSizeHint = 128 * 1024;
+
 constexpr size_t kDefaultAttributeSize = 4 * sizeof(float);
 
 // Metal limits
@@ -44,6 +51,7 @@
 constexpr uint32_t kUniformBufferSettingOffsetMinAlignment = 4;
 #endif
 constexpr uint32_t kIndexBufferOffsetAlignment       = 4;
+constexpr uint32_t kArgumentBufferOffsetAlignment    = kUniformBufferSettingOffsetMinAlignment;
 constexpr uint32_t kTextureToBufferBlittingAlignment = 256;
 
 // Font end binding limits
@@ -66,8 +74,17 @@
 // Binding index for UBO's argument buffer
 constexpr uint32_t kUBOArgumentBufferBindingIndex = kShadowSamplerCompareModesBindingIndex + 1;
 
-constexpr uint32_t kStencilMaskAll = 0xff;  // Only 8 bits stencil is supported
+constexpr uint32_t kStencilMaskAll = 0xff;  // Only 8 bit stencil is supported
 
+static const char * kUnassignedAttributeString = " __unassigned_attribute__";
+
+
+constexpr float kEmulatedAlphaValue = 1.0f;
+
+constexpr uint32_t kOcclusionQueryResultSize = sizeof(uint64_t);
+
+
+
 }  // namespace mtl
 }  // namespace rx
 #endif

Modified: trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_glslang_mtl_utils.mm (271333 => 271334)


--- trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_glslang_mtl_utils.mm	2021-01-09 00:03:32 UTC (rev 271333)
+++ trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_glslang_mtl_utils.mm	2021-01-09 00:10:24 UTC (rev 271334)
@@ -10,6 +10,7 @@
 #include "compiler/translator/TranslatorMetalDirect.h"
 #include "libANGLE/renderer/metal/ShaderMtl.h"
 #include "libANGLE/renderer/metal/mtl_glslang_mtl_utils.h"
+#include "common/utilities.h"
 
 namespace rx
 {
@@ -145,6 +146,47 @@
     return translatorMetalDirect->getTranslatorMetalReflection();
 }
 
+std::string updateShaderAttributes(std::string shaderSourceIn, const gl::ProgramState &programState)
+{
+    // Build string to attrib map.
+    const auto & programAttributes = programState.getProgramInputs();
+    std::ostringstream stream;
+    std::unordered_map<std::string, uint32_t> attributeBindings;
+    for(auto & attribute : programAttributes)
+    {
+        const int regs = gl::VariableRegisterCount(attribute.type);
+        if(regs > 1)
+        {
+            for(int i = 0; i < regs; i++)
+            {
+                stream.str("");
+                stream << attribute.name << "_" << std::to_string(i) << kUnassignedAttributeString;
+                attributeBindings.insert({std::string(stream.str()), i+attribute.location});
+            }
+        }
+        else
+        {
+            stream.str("");
+            stream << attribute.name << kUnassignedAttributeString;
+            attributeBindings.insert({std::string(stream.str()),attribute.location});
+        }
+    }
+
+    //Rewrite attributes
+    std::string outputSource = shaderSourceIn;
+    for(auto it = attributeBindings.begin(); it!=attributeBindings.end(); ++it)
+    {
+        std::size_t attribFound= outputSource.find(it->first);
+        if(attribFound != std::string::npos)
+        {
+            stream.str("");
+            stream << "[[attribute(" << it->second << ")]]";
+            outputSource = outputSource.replace(attribFound+it->first.length()-strlen(kUnassignedAttributeString), strlen(kUnassignedAttributeString), stream.str());
+        }
+    }
+    return outputSource;
+}
+
 angle::Result GlslangGetMSL(const gl::Context *glContext,
                             const gl::ProgramState &programState,
                             const gl::Caps &glCaps,
@@ -191,6 +233,17 @@
     {
         (*mslCodeOut)[type]                         = shaderSources[type];
         (*mslShaderInfoOut)[type].metalShaderSource = shaderSources[type];
+        std::string source;
+        if(type == gl::ShaderType::Vertex)
+        {
+            source = updateShaderAttributes(shaderSources[type], programState);
+        }
+        else
+        {
+            source = shaderSources[type];
+        }
+        (*mslCodeOut)[type]                         = source;
+        (*mslShaderInfoOut)[type].metalShaderSource = source;
         gl::Shader *shader                        = programState.getAttachedShader(type);
         sh::TranslatorMetalReflection *reflection = getReflectionFromShader(shader);
         // Retrieve automatic texture slot assignments
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to