diff --git a/Source/WebGPU/WGSL/MangleNames.cpp b/Source/WebGPU/WGSL/MangleNames.cpp index 4e0abb4d549c..0e29f61364a9 100644 --- a/Source/WebGPU/WGSL/MangleNames.cpp +++ b/Source/WebGPU/WGSL/MangleNames.cpp @@ -158,9 +158,11 @@ void NameManglerVisitor::visit(AST::Structure& structure) ASSERT_UNUSED(result, result.isNewEntry); } -void NameManglerVisitor::visit(AST::Variable& variable) +void NameManglerVisitor::visit(AST::Variable&) { - visitVariableDeclaration(variable, MangledName::Global); + // FIXME: we need to notify the API about these renames + // https://bugs.webkit.org/show_bug.cgi?id=250441 + // visitVariableDeclaration(variable, MangledName::Global); } void NameManglerVisitor::visit(AST::VariableStatement& variable) diff --git a/Source/WebGPU/WGSL/Metal/MetalFunctionWriter.cpp b/Source/WebGPU/WGSL/Metal/MetalFunctionWriter.cpp index 2e4f2cb28abd..5802a40535d3 100644 --- a/Source/WebGPU/WGSL/Metal/MetalFunctionWriter.cpp +++ b/Source/WebGPU/WGSL/Metal/MetalFunctionWriter.cpp @@ -96,6 +96,8 @@ class FunctionDefinitionWriter : public AST::Visitor { private: void visit(const Type*); + void visitGlobal(AST::Variable&); + void serializeVariable(AST::Variable&); StringBuilder& m_stringBuilder; CallGraph& m_callGraph; @@ -103,12 +105,15 @@ class FunctionDefinitionWriter : public AST::Visitor { std::optional m_structRole; std::optional m_entryPointStage; std::optional m_suffix; + unsigned m_functionConstantIndex { 0 }; }; void FunctionDefinitionWriter::write() { for (auto& structure : m_callGraph.ast().structures()) visit(structure); + for (auto& variable : m_callGraph.ast().variables()) + visitGlobal(variable); for (auto& entryPoint : m_callGraph.entrypoints()) visit(entryPoint.function); } @@ -180,6 +185,22 @@ void FunctionDefinitionWriter::visit(AST::Structure& structDecl) } void FunctionDefinitionWriter::visit(AST::Variable& variable) +{ + serializeVariable(variable); + m_stringBuilder.append(";\n"); +} + +void FunctionDefinitionWriter::visitGlobal(AST::Variable& variable) +{ + if (variable.flavor() != AST::VariableFlavor::Override) + return; + + m_stringBuilder.append("constant "); + serializeVariable(variable); + m_stringBuilder.append(" [[function_constant(", m_functionConstantIndex++, ")]];\n"); +} + +void FunctionDefinitionWriter::serializeVariable(AST::Variable& variable) { if (variable.maybeTypeName()) visit(*variable.maybeTypeName()); @@ -193,7 +214,6 @@ void FunctionDefinitionWriter::visit(AST::Variable& variable) m_stringBuilder.append(" = "); visit(*variable.maybeInitializer()); } - m_stringBuilder.append(";\n"); } void FunctionDefinitionWriter::visit(AST::Attribute& attribute)