WebKit Bugzilla
Attachment 358984 Details for
Bug 193360
: [WHLSL] Add native function synthesis passes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
WIP
bug-193360-20190111230853.patch (text/plain), 88.87 KB, created by
Myles C. Maxfield
on 2019-01-11 23:08:54 PST
(
hide
)
Description:
WIP
Filename:
MIME Type:
Creator:
Myles C. Maxfield
Created:
2019-01-11 23:08:54 PST
Size:
88.87 KB
patch
obsolete
>Subversion Revision: 239896 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 356730a7c4c589b53975e25fd3d4ed56202479df..7cbe00bc54ae7c11d41c3c8099a4b956a9bf19d8 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,77 @@ >+2019-01-11 Myles C. Maxfield <mmaxfield@apple.com> >+ >+ [WHLSL] Add native function synthesis passes >+ https://bugs.webkit.org/show_bug.cgi?id=193360 >+ >+ Reviewed by Dean Jackson. >+ >+ This patch includes all the passes in prepare() that are between the name resolver and the >+ type checker. It involves a few small pieces: >+ >+ - CheckDuplicateFunctions which makes sure the same function isn't defined twice >+ - Intrinsics, which remembers all of the native types so they can be referred to by the >+ rest of the compiler >+ - RecursiveTypeChecker which makes sure types don't refer to themselves >+ - SynthesizeArrayOperatorLength which creates operator.length() functions for arrays >+ - SynthesizeConstructors which creates copy constructors and default constructors for all >+ types >+ - SynthesizeEnumerationFunctions which provides cast operators between enum types and their >+ base types >+ - SynthesizeStructureAccessors which provides getters, setters, and anders for each member >+ of a struct >+ >+ No new tests because it isn't hooked up yet. Not enough of the compiler exists to have any meaningful sort >+ of test. When enough of the compiler is present, I'll port the reference implementation's test suite. >+ >+ * Modules/webgpu/WHLSL/AST/WHLSLBuiltInSemantic.cpp: >+ (WebCore::WHLSL::AST::BuiltInSemantic::isAcceptableType const): >+ * Modules/webgpu/WHLSL/AST/WHLSLResourceSemantic.cpp: >+ (WebCore::WHLSL::AST::ResourceSemantic::isAcceptableType const): >+ * Modules/webgpu/WHLSL/WHLSLCheckDuplicateFunctions.cpp: Added. >+ (WebCore::WHLSL::checkDuplicateFunctions): >+ * Modules/webgpu/WHLSL/WHLSLCheckDuplicateFunctions.h: Copied from Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLResourceSemantic.cpp. >+ * Modules/webgpu/WHLSL/WHLSLIntrinsics.cpp: Added. >+ (WebCore::WHLSL::Intrinsics::Intrinsics): >+ (WebCore::WHLSL::Intrinsics::add): >+ (WebCore::WHLSL::Intrinsics::addPrimitive): >+ (WebCore::WHLSL::Intrinsics::addVector): >+ (WebCore::WHLSL::Intrinsics::addMatrix): >+ (WebCore::WHLSL::Intrinsics::addFullTexture): >+ (WebCore::WHLSL::Intrinsics::addDepthTexture): >+ (WebCore::WHLSL::Intrinsics::addTexture): >+ * Modules/webgpu/WHLSL/WHLSLIntrinsics.h: Added. >+ (WebCore::WHLSL::Intrinsics::voidType const): >+ (WebCore::WHLSL::Intrinsics::boolType const): >+ (WebCore::WHLSL::Intrinsics::intType const): >+ (WebCore::WHLSL::Intrinsics::uintType const): >+ (WebCore::WHLSL::Intrinsics::samplerType const): >+ (WebCore::WHLSL::Intrinsics::floatType const): >+ (WebCore::WHLSL::Intrinsics::float3Type const): >+ (WebCore::WHLSL::Intrinsics::float4Type const): >+ * Modules/webgpu/WHLSL/WHLSLProgram.h: >+ (WebCore::WHLSL::Program::append): >+ (WebCore::WHLSL::Program::intrinsics): >+ * Modules/webgpu/WHLSL/WHLSLRecursiveTypeChecker.cpp: Added. >+ (WebCore::WHLSL::checkRecursiveTypes): >+ * Modules/webgpu/WHLSL/WHLSLRecursiveTypeChecker.h: Copied from Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLResourceSemantic.cpp. >+ * Modules/webgpu/WHLSL/WHLSLSynthesizeArrayOperatorLength.cpp: Added. >+ (WebCore::WHLSL::FindArrayTypes::takeArrayTypes): >+ (WebCore::WHLSL::synthesizeArrayOperatorLength): >+ * Modules/webgpu/WHLSL/WHLSLSynthesizeArrayOperatorLength.h: Copied from Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLResourceSemantic.cpp. >+ * Modules/webgpu/WHLSL/WHLSLSynthesizeConstructors.cpp: Added. >+ (WebCore::WHLSL::FindAllTypes::takeUnnamedTypes): >+ (WebCore::WHLSL::FindAllTypes::takeNamedTypes): >+ (WebCore::WHLSL::synthesizeConstructors): >+ * Modules/webgpu/WHLSL/WHLSLSynthesizeConstructors.h: Copied from Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLResourceSemantic.cpp. >+ * Modules/webgpu/WHLSL/WHLSLSynthesizeEnumerationFunctions.cpp: Added. >+ (WebCore::WHLSL::synthesizeEnumerationFunctions): >+ * Modules/webgpu/WHLSL/WHLSLSynthesizeEnumerationFunctions.h: Copied from Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLResourceSemantic.cpp. >+ * Modules/webgpu/WHLSL/WHLSLSynthesizeStructureAccessors.cpp: Added. >+ (WebCore::WHLSL::synthesizeStructureAccessors): >+ * Modules/webgpu/WHLSL/WHLSLSynthesizeStructureAccessors.h: Copied from Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLResourceSemantic.cpp. >+ * Sources.txt: >+ * WebCore.xcodeproj/project.pbxproj: >+ > 2019-01-11 Myles C. Maxfield <mmaxfield@apple.com> > > [WHLSL] Implement the NameResolver >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLBuiltInSemantic.cpp b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLBuiltInSemantic.cpp >index e42ee479921594eec2e12e1f3126672318559735..414bd45a9a2af755a7f440b1fb0343403907313c 100644 >--- a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLBuiltInSemantic.cpp >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLBuiltInSemantic.cpp >@@ -29,6 +29,8 @@ > #if ENABLE(WEBGPU) > > #include "WHLSLFunctionDefinition.h" >+#include "WHLSLInferTypes.h" >+#include "WHLSLIntrinsics.h" > #include "WHLSLTypeReference.h" > > namespace WebCore { >@@ -37,10 +39,38 @@ namespace WHLSL { > > namespace AST { > >-bool BuiltInSemantic::isAcceptableType(const UnnamedType&, const Intrinsics&) const >+bool BuiltInSemantic::isAcceptableType(const UnnamedType& unnamedType, const Intrinsics& intrinsics) const > { >- // FIXME: Implement this >- return true; >+ switch (m_variable) { >+ case Variable::SVInstanceID: >+ return matches(unnamedType, intrinsics.uintType()); >+ case Variable::SVVertexID: >+ return matches(unnamedType, intrinsics.uintType()); >+ case Variable::PSize: >+ return matches(unnamedType, intrinsics.floatType()); >+ case Variable::SVPosition: >+ return matches(unnamedType, intrinsics.float4Type()); >+ case Variable::SVIsFrontFace: >+ return matches(unnamedType, intrinsics.boolType()); >+ case Variable::SVSampleIndex: >+ return matches(unnamedType, intrinsics.uintType()); >+ case Variable::SVInnerCoverage: >+ return matches(unnamedType, intrinsics.uintType()); >+ case Variable::SVTarget: >+ return matches(unnamedType, intrinsics.float4Type()); >+ case Variable::SVDepth: >+ return matches(unnamedType, intrinsics.floatType()); >+ case Variable::SVCoverage: >+ return matches(unnamedType, intrinsics.uintType()); >+ case Variable::SVDispatchThreadID: >+ return matches(unnamedType, intrinsics.float3Type()); >+ case Variable::SVGroupID: >+ return matches(unnamedType, intrinsics.float3Type()); >+ case Variable::SVGroupIndex: >+ return matches(unnamedType, intrinsics.uintType()); >+ case Variable::SVGroupThreadID: >+ return matches(unnamedType, intrinsics.float3Type()); >+ } > } > > bool BuiltInSemantic::isAcceptableForShaderItemDirection(ShaderItemDirection direction, const FunctionDefinition& functionDefinition) const >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLFloatLiteralType.cpp b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLFloatLiteralType.cpp >index 3325cc5d19505ac80cb9181fcb509fb54fcdbcc4..81c9ddeec77b7644f247d2cfaeb710f616085ea7 100644 >--- a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLFloatLiteralType.cpp >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLFloatLiteralType.cpp >@@ -40,7 +40,7 @@ namespace AST { > > FloatLiteralType::FloatLiteralType(Lexer::Token&& origin, float value) > : m_value(value) >- , m_preferredType(makeUniqueRef<TypeReference>(WTFMove(origin), String("float", String::ConstructFromLiteral), TypeArguments())) >+ , m_preferredType(makeUniqueRef<TypeReference>(WTFMove(origin), "float"_str, TypeArguments())) > { > } > >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLIndexExpression.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLIndexExpression.h >index ab897740f3f2fdf4c3dcc6be86ef3a0c2d7a4820..25ba6e78a59f7678862b8485048f9dea8f00b79e 100644 >--- a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLIndexExpression.h >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLIndexExpression.h >@@ -54,17 +54,17 @@ public: > > String getFunctionName() const override > { >- return String("operator[]", String::ConstructFromLiteral); >+ return "operator[]"_str; > } > > String setFunctionName() const override > { >- return String("operator&[]", String::ConstructFromLiteral); >+ return "operator&[]"_str; > } > > String andFunctionName() const override > { >- return String("operator[]=", String::ConstructFromLiteral); >+ return "operator[]="_str; > } > > Expression& indexExpression() { return static_cast<Expression&>(m_index); } >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteralType.cpp b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteralType.cpp >index 322364139b74fb6106a7bcf4359152649f9d087c..e87acdacab7927c49196dcb49f84b609c7f2b21b 100644 >--- a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteralType.cpp >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteralType.cpp >@@ -41,7 +41,7 @@ namespace AST { > > IntegerLiteralType::IntegerLiteralType(Lexer::Token&& origin, int value) > : m_value(value) >- , m_preferredType(makeUniqueRef<TypeReference>(WTFMove(origin), String("int", String::ConstructFromLiteral), TypeArguments())) >+ , m_preferredType(makeUniqueRef<TypeReference>(WTFMove(origin), "int"_str, TypeArguments())) > { > } > >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLResourceSemantic.cpp b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLResourceSemantic.cpp >index 65fbb33d39d13be428194a1da41f624bf23bda99..8440960c6e3b4872d9e93443fb88c7358ed36cbd 100644 >--- a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLResourceSemantic.cpp >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLResourceSemantic.cpp >@@ -29,6 +29,8 @@ > #if ENABLE(WEBGPU) > > #include "WHLSLArrayType.h" >+#include "WHLSLInferTypes.h" >+#include "WHLSLIntrinsics.h" > #include "WHLSLReferenceType.h" > #include "WHLSLTypeReference.h" > >@@ -38,10 +40,42 @@ namespace WHLSL { > > namespace AST { > >-bool ResourceSemantic::isAcceptableType(const UnnamedType&, const Intrinsics&) const >+bool ResourceSemantic::isAcceptableType(const UnnamedType& unnamedType, const Intrinsics& intrinsics) const > { >- // FIXME: Implement this >- return true; >+ switch (m_mode) { >+ case Mode::UnorderedAccessView: >+ if (is<ReferenceType>(unnamedType)) { >+ auto& referenceType = downcast<ReferenceType>(unnamedType); >+ return referenceType.addressSpace() == ReferenceType::AddressSpace::Constant || referenceType.addressSpace() == ReferenceType::AddressSpace::Device; >+ } >+ if (is<ArrayType>(unnamedType)) >+ return true; >+ if (is<TypeReference>(unnamedType)) { >+ auto& typeReference = downcast<TypeReference>(unnamedType); >+ ASSERT(typeReference.resolvedType()); >+ if (is<NativeTypeDeclaration>(*typeReference.resolvedType())) >+ return downcast<NativeTypeDeclaration>(*typeReference.resolvedType()).isTexture(); >+ } >+ return false; >+ case Mode::Texture: >+ if (is<ReferenceType>(unnamedType)) >+ return downcast<ReferenceType>(unnamedType).addressSpace() == ReferenceType::AddressSpace::Constant; >+ if (is<ArrayType>(unnamedType)) >+ return true; >+ if (is<TypeReference>(unnamedType)) { >+ auto& typeReference = downcast<TypeReference>(unnamedType); >+ ASSERT(typeReference.resolvedType()); >+ if (is<NativeTypeDeclaration>(*typeReference.resolvedType())) >+ return downcast<NativeTypeDeclaration>(*typeReference.resolvedType()).isTexture(); >+ } >+ return false; >+ case Mode::Buffer: >+ if (is<ReferenceType>(unnamedType)) >+ return downcast<ReferenceType>(unnamedType).addressSpace() == ReferenceType::AddressSpace::Constant; >+ return is<ArrayType>(unnamedType); >+ case Mode::Sampler: >+ return matches(unnamedType, intrinsics.samplerType()); >+ } > } > > bool ResourceSemantic::isAcceptableForShaderItemDirection(ShaderItemDirection direction, const FunctionDefinition&) const >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteralType.cpp b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteralType.cpp >index bf31a3c6e79ad52100283d7dfe82b46fa6636fa2..01f31979146bc7c4ce835cb8f5f5ddc42f0a1ec8 100644 >--- a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteralType.cpp >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteralType.cpp >@@ -42,7 +42,7 @@ namespace AST { > > UnsignedIntegerLiteralType::UnsignedIntegerLiteralType(Lexer::Token&& origin, unsigned value) > : m_value(value) >- , m_preferredType(makeUniqueRef<TypeReference>(WTFMove(origin), String("uint", String::ConstructFromLiteral), TypeArguments())) >+ , m_preferredType(makeUniqueRef<TypeReference>(WTFMove(origin), "uint"_str, TypeArguments())) > { > } > >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLCheckDuplicateFunctions.cpp b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLCheckDuplicateFunctions.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..57b462e0c1f37ad3ca2c72c998eeb5d36dd2cdb8 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLCheckDuplicateFunctions.cpp >@@ -0,0 +1,112 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#include "config.h" >+#include "WHLSLCheckDuplicateFunctions.h" >+ >+#if ENABLE(WEBGPU) >+ >+#include "WHLSLArrayReferenceType.h" >+#include "WHLSLArrayType.h" >+#include "WHLSLInferTypes.h" >+#include "WHLSLTypeReference.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+bool checkDuplicateFunctions(const Program& program) >+{ >+ Vector<std::reference_wrapper<const AST::FunctionDeclaration>> functions; >+ for (auto& functionDefinition : program.functionDefinitions()) >+ functions.append(static_cast<const AST::FunctionDefinition&>(functionDefinition)); >+ for (auto& nativeFunctionDeclaration : program.nativeFunctionDeclarations()) >+ functions.append(static_cast<const AST::NativeFunctionDeclaration&>(nativeFunctionDeclaration)); >+ >+ std::sort(functions.begin(), functions.end(), [](const AST::FunctionDeclaration& a, const AST::FunctionDeclaration& b) -> bool { >+ if (a.name().length() < b.name().length()) >+ return true; >+ if (a.name().length() > b.name().length()) >+ return false; >+ for (unsigned i = 0; i < a.name().length(); ++i) { >+ if (a.name()[i] < b.name()[i]) >+ return true; >+ if (a.name()[i] > b.name()[i]) >+ return false; >+ } >+ return false; >+ }); >+ for (size_t i = 0; i < functions.size(); ++i) { >+ for (size_t j = i + 1; j < functions.size(); ++i) { >+ if (functions[i].get().name() != functions[j].get().name()) >+ break; >+ if (is<AST::NativeFunctionDeclaration>(functions[i].get()) && is<AST::NativeFunctionDeclaration>(functions[j].get())) >+ continue; >+ if (functions[i].get().parameters().size() != functions[j].get().parameters().size()) >+ continue; >+ if (functions[i].get().isCast() && !matches(functions[i].get().type(), functions[j].get().type())) >+ continue; >+ bool same = true; >+ for (size_t k = 0; k < functions[i].get().parameters().size(); ++k) { >+ if (!matches(*functions[i].get().parameters()[k].type(), *functions[j].get().parameters()[k].type())) { >+ same = false; >+ break; >+ } >+ } >+ if (same) >+ return false; >+ } >+ >+ if (functions[i].get().name() == "operator&[]" && functions[i].get().parameters().size() == 2 >+ && is<AST::ArrayReferenceType>(static_cast<const AST::UnnamedType&>(*functions[i].get().parameters()[0].type()))) { >+ auto& type = static_cast<const AST::UnnamedType&>(*functions[i].get().parameters()[1].type()); >+ if (is<AST::TypeReference>(type)) { >+ if (auto* resolvedType = downcast<AST::TypeReference>(type).resolvedType()) { >+ if (is<AST::NativeTypeDeclaration>(*resolvedType)) { >+ auto& nativeTypeDeclaration = downcast<AST::NativeTypeDeclaration>(*resolvedType); >+ if (nativeTypeDeclaration.name() == "uint") >+ return false; >+ } >+ } >+ } >+ } else if (functions[i].get().name() == "operator.length" && functions[i].get().parameters().size() == 1 >+ && (is<AST::ArrayReferenceType>(static_cast<const AST::UnnamedType&>(*functions[i].get().parameters()[0].type())) >+ || is<AST::ArrayType>(static_cast<const AST::UnnamedType&>(*functions[i].get().parameters()[0].type())))) >+ return false; >+ else if (functions[i].get().name() == "operator==" >+ && functions[i].get().parameters().size() == 2 >+ && is<AST::ReferenceType>(static_cast<const AST::UnnamedType&>(*functions[i].get().parameters()[0].type())) >+ && is<AST::ReferenceType>(static_cast<const AST::UnnamedType&>(*functions[i].get().parameters()[1].type())) >+ && matches(static_cast<const AST::UnnamedType&>(*functions[i].get().parameters()[0].type()), static_cast<const AST::UnnamedType&>(*functions[i].get().parameters()[1].type()))) >+ return false; >+ } >+ return true; >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLCheckDuplicateFunctions.h b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLCheckDuplicateFunctions.h >new file mode 100644 >index 0000000000000000000000000000000000000000..c1caf55c56db8c5f1bbb471900394c43e340196f >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLCheckDuplicateFunctions.h >@@ -0,0 +1,43 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#pragma once >+ >+#if ENABLE(WEBGPU) >+ >+#include "WHLSLProgram.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+bool checkDuplicateFunctions(const Program&); >+ >+} >+ >+} >+ >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLIntrinsics.cpp b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLIntrinsics.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..77c7fffff1c4408bb77cf89f1bd7ea63714d5355 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLIntrinsics.cpp >@@ -0,0 +1,425 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#include "config.h" >+#include "WHLSLIntrinsics.h" >+ >+#if ENABLE(WEBGPU) >+ >+#include "WHLSLConstantExpression.h" >+#include "WHLSLTypeArgument.h" >+#include "WHLSLTypeReference.h" >+#include <algorithm> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+Intrinsics::Intrinsics() >+ : m_textureTypeNames { "Texture1D"_str, "RWTexture1D"_str, "Texture1DArray"_str, "RWTexture1DArray"_str, "Texture2D"_str, "RWTexture2D"_str, "Texture2DArray"_str, "RWTexture2DArray"_str, "Texture3D"_str, "RWTexture3D"_str, "TextureCube"_str } >+ , m_textureInnerTypeNames { "uchar"_str, "ushort"_str, "uint"_str, "char"_str, "short"_str, "int"_str, "half"_str, "float"_str } >+ , m_depthTextureInnerTypes { "half"_str, "float"_str } >+{ >+ ASSERT(m_textureTypeNames.size() == 11); // fullTextures hardcodes the length of this array. >+ ASSERT(m_textureInnerTypeNames.size() == 8); // fullTextures hardcodes the length of this array. >+ ASSERT(m_depthTextureInnerTypes.size() == 2); // textureDepth2D & friends hardcodes the length of this array. >+} >+ >+void Intrinsics::add(AST::NativeFunctionDeclaration&) >+{ >+ // FIXME: Populate this. >+} >+ >+bool Intrinsics::addPrimitive(AST::NativeTypeDeclaration& nativeTypeDeclaration) >+{ >+ if (nativeTypeDeclaration.typeArguments().size()) >+ return false; >+ >+ if (nativeTypeDeclaration.name() == "void") >+ m_voidType = &nativeTypeDeclaration; >+ else if (nativeTypeDeclaration.name() == "bool") >+ m_boolType = &nativeTypeDeclaration; >+ else if (nativeTypeDeclaration.name() == "uchar") { >+ nativeTypeDeclaration.setIsInt(); >+ nativeTypeDeclaration.setIsNumber(); >+ nativeTypeDeclaration.setCanRepresentInteger([](int x) { >+ return x >= 0 && x <= 0xFF; >+ }); >+ nativeTypeDeclaration.setCanRepresentUnsignedInteger([](unsigned x) { >+ return x <= 0xFF; >+ }); >+ nativeTypeDeclaration.setCanRepresentFloat([](float x) { >+ return static_cast<float>(static_cast<uint8_t>(x)) == x; >+ }); >+ nativeTypeDeclaration.setSuccessor([](int64_t x) -> int64_t { >+ return static_cast<uint8_t>(x + 1); >+ }); >+ nativeTypeDeclaration.setFormatValueFromInteger([](int x) -> int64_t { >+ return static_cast<uint8_t>(x); >+ }); >+ nativeTypeDeclaration.setFormatValueFromUnsignedInteger([](unsigned x) -> int64_t { >+ return static_cast<uint8_t>(x); >+ }); >+ nativeTypeDeclaration.setIterateAllValues([](const std::function<bool(int64_t)>& callback) { >+ for (int64_t i = 0; i < 0x100; ++i) { >+ if (callback(i)) >+ break; >+ } >+ }); >+ m_ucharType = &nativeTypeDeclaration; >+ } else if (nativeTypeDeclaration.name() == "ushort") { >+ nativeTypeDeclaration.setIsInt(); >+ nativeTypeDeclaration.setIsNumber(); >+ nativeTypeDeclaration.setCanRepresentInteger([](int x) { >+ return x >= 0 && x <= 0xFFFF; >+ }); >+ nativeTypeDeclaration.setCanRepresentUnsignedInteger([](unsigned x) { >+ return x <= 0xFFFF; >+ }); >+ nativeTypeDeclaration.setCanRepresentFloat([](float x) { >+ return static_cast<float>(static_cast<uint16_t>(x)) == x; >+ }); >+ nativeTypeDeclaration.setSuccessor([](int64_t x) -> int64_t { >+ return static_cast<uint16_t>(x + 1); >+ }); >+ nativeTypeDeclaration.setFormatValueFromInteger([](int x) -> int64_t { >+ return static_cast<uint16_t>(x); >+ }); >+ nativeTypeDeclaration.setFormatValueFromUnsignedInteger([](unsigned x) -> int64_t { >+ return static_cast<uint16_t>(x); >+ }); >+ nativeTypeDeclaration.setIterateAllValues([](const std::function<bool(int64_t)>& callback) { >+ for (int64_t i = 0; i < 0x10000; ++i) { >+ if (callback(i)) >+ break; >+ } >+ }); >+ m_ushortType = &nativeTypeDeclaration; >+ } else if (nativeTypeDeclaration.name() == "uint") { >+ nativeTypeDeclaration.setIsInt(); >+ nativeTypeDeclaration.setIsNumber(); >+ nativeTypeDeclaration.setCanRepresentInteger([](int x) { >+ return x >= 0; >+ }); >+ nativeTypeDeclaration.setCanRepresentUnsignedInteger([](unsigned) { >+ return true; >+ }); >+ nativeTypeDeclaration.setCanRepresentFloat([](float x) { >+ return static_cast<float>(static_cast<uint32_t>(x)) == x; >+ }); >+ nativeTypeDeclaration.setSuccessor([](int64_t x) -> int64_t { >+ return static_cast<uint32_t>(x + 1); >+ }); >+ nativeTypeDeclaration.setFormatValueFromInteger([](int x) -> int64_t { >+ return static_cast<uint32_t>(x); >+ }); >+ nativeTypeDeclaration.setFormatValueFromUnsignedInteger([](unsigned x) -> int64_t { >+ return static_cast<uint32_t>(x); >+ }); >+ nativeTypeDeclaration.setIterateAllValues([](const std::function<bool(int64_t)>& callback) { >+ for (int64_t i = 0; i < 0x100000000; ++i) { >+ if (callback(i)) >+ break; >+ } >+ }); >+ m_uintType = &nativeTypeDeclaration; >+ } else if (nativeTypeDeclaration.name() == "char") { >+ nativeTypeDeclaration.setIsInt(); >+ nativeTypeDeclaration.setIsNumber(); >+ nativeTypeDeclaration.setIsSigned(); >+ nativeTypeDeclaration.setCanRepresentInteger([](int x) { >+ return x >= -128 && x <= 127; >+ }); >+ nativeTypeDeclaration.setCanRepresentUnsignedInteger([](unsigned x) { >+ return x <= 127; >+ }); >+ nativeTypeDeclaration.setCanRepresentFloat([](float x) { >+ return static_cast<float>(static_cast<int8_t>(x)) == x; >+ }); >+ nativeTypeDeclaration.setSuccessor([](int64_t x) -> int64_t { >+ return static_cast<int8_t>(x + 1); >+ }); >+ nativeTypeDeclaration.setFormatValueFromInteger([](int x) -> int64_t { >+ return static_cast<int8_t>(x); >+ }); >+ nativeTypeDeclaration.setFormatValueFromUnsignedInteger([](unsigned x) -> int64_t { >+ return static_cast<int8_t>(x); >+ }); >+ nativeTypeDeclaration.setIterateAllValues([](const std::function<bool(int64_t)>& callback) { >+ for (int64_t i = -128; i < 128; ++i) { >+ if (callback(i)) >+ break; >+ } >+ }); >+ m_charType = &nativeTypeDeclaration; >+ } else if (nativeTypeDeclaration.name() == "short") { >+ nativeTypeDeclaration.setIsInt(); >+ nativeTypeDeclaration.setIsNumber(); >+ nativeTypeDeclaration.setIsSigned(); >+ nativeTypeDeclaration.setCanRepresentInteger([](int x) { >+ return x >= -32768 && x <= 32767; >+ }); >+ nativeTypeDeclaration.setCanRepresentUnsignedInteger([](unsigned x) { >+ return x <= 32767; >+ }); >+ nativeTypeDeclaration.setCanRepresentFloat([](float x) { >+ return static_cast<float>(static_cast<int16_t>(x)) == x; >+ }); >+ nativeTypeDeclaration.setSuccessor([](int64_t x) -> int64_t { >+ return static_cast<int16_t>(x + 1); >+ }); >+ nativeTypeDeclaration.setFormatValueFromInteger([](int x) -> int64_t { >+ return static_cast<int16_t>(x); >+ }); >+ nativeTypeDeclaration.setFormatValueFromUnsignedInteger([](unsigned x) -> int64_t { >+ return static_cast<int16_t>(x); >+ }); >+ nativeTypeDeclaration.setIterateAllValues([](const std::function<bool(int64_t)>& callback) { >+ for (int64_t i = -32768; i < 32768; ++i) { >+ if (callback(i)) >+ break; >+ } >+ }); >+ m_shortType = &nativeTypeDeclaration; >+ } else if (nativeTypeDeclaration.name() == "int") { >+ nativeTypeDeclaration.setIsInt(); >+ nativeTypeDeclaration.setIsNumber(); >+ nativeTypeDeclaration.setIsSigned(); >+ nativeTypeDeclaration.setCanRepresentInteger([](int) { >+ return true; >+ }); >+ nativeTypeDeclaration.setCanRepresentUnsignedInteger([](unsigned x) { >+ return x <= 2147483647; >+ }); >+ nativeTypeDeclaration.setCanRepresentFloat([](float x) { >+ return static_cast<float>(static_cast<int32_t>(x)) == x; >+ }); >+ nativeTypeDeclaration.setSuccessor([](int64_t x) -> int64_t { >+ return static_cast<int32_t>(x + 1); >+ }); >+ nativeTypeDeclaration.setFormatValueFromInteger([](int x) -> int64_t { >+ return static_cast<int32_t>(x); >+ }); >+ nativeTypeDeclaration.setFormatValueFromUnsignedInteger([](unsigned x) -> int64_t { >+ return static_cast<int32_t>(x); >+ }); >+ nativeTypeDeclaration.setIterateAllValues([](const std::function<bool(int64_t)>& callback) { >+ for (int64_t i = -2147483647; i < 2147483648; ++i) { >+ if (callback(i)) >+ break; >+ } >+ }); >+ m_intType = &nativeTypeDeclaration; >+ } else if (nativeTypeDeclaration.name() == "half") { >+ nativeTypeDeclaration.setIsNumber(); >+ nativeTypeDeclaration.setIsFloating(); >+ nativeTypeDeclaration.setCanRepresentInteger([](int) { >+ return true; >+ }); >+ nativeTypeDeclaration.setCanRepresentUnsignedInteger([](unsigned) { >+ return true; >+ }); >+ nativeTypeDeclaration.setCanRepresentFloat([](float) { >+ return true; >+ }); >+ m_halfType = &nativeTypeDeclaration; >+ } else if (nativeTypeDeclaration.name() == "float") { >+ nativeTypeDeclaration.setIsNumber(); >+ nativeTypeDeclaration.setIsFloating(); >+ nativeTypeDeclaration.setCanRepresentInteger([](int) { >+ return true; >+ }); >+ nativeTypeDeclaration.setCanRepresentUnsignedInteger([](unsigned) { >+ return true; >+ }); >+ nativeTypeDeclaration.setCanRepresentFloat([](float) { >+ return true; >+ }); >+ m_floatType = &nativeTypeDeclaration; >+ } else if (nativeTypeDeclaration.name() == "atomic_int") >+ m_atomicIntType = &nativeTypeDeclaration; >+ else if (nativeTypeDeclaration.name() == "atomic_uint") >+ m_atomicUintType = &nativeTypeDeclaration; >+ else if (nativeTypeDeclaration.name() == "sampler") >+ m_samplerType = &nativeTypeDeclaration; >+ else >+ ASSERT_NOT_REACHED(); >+ return true; >+} >+ >+bool Intrinsics::addVector(AST::NativeTypeDeclaration& nativeTypeDeclaration) >+{ >+ if (nativeTypeDeclaration.name() != "vector") >+ return false; >+ >+ ASSERT(nativeTypeDeclaration.typeArguments().size() == 2); >+ ASSERT(WTF::holds_alternative<UniqueRef<AST::TypeReference>>(nativeTypeDeclaration.typeArguments()[0])); >+ ASSERT(WTF::holds_alternative<AST::ConstantExpression>(nativeTypeDeclaration.typeArguments()[1])); >+ auto& innerType = static_cast<AST::TypeReference&>(WTF::get<UniqueRef<AST::TypeReference>>(nativeTypeDeclaration.typeArguments()[0])); >+ auto& lengthExpression = WTF::get<AST::ConstantExpression>(nativeTypeDeclaration.typeArguments()[1]); >+ ASSERT(!innerType.typeArguments().size()); >+ AST::NativeTypeDeclaration** array; >+ if (innerType.name() == "bool") >+ array = m_vectorBool; >+ else if (innerType.name() == "uchar") >+ array = m_vectorUchar; >+ else if (innerType.name() == "ushort") >+ array = m_vectorUshort; >+ else if (innerType.name() == "uint") >+ array = m_vectorUint; >+ else if (innerType.name() == "char") >+ array = m_vectorChar; >+ else if (innerType.name() == "short") >+ array = m_vectorShort; >+ else if (innerType.name() == "int") >+ array = m_vectorInt; >+ else if (innerType.name() == "half") >+ array = m_vectorHalf; >+ else if (innerType.name() == "float") >+ array = m_vectorFloat; >+ else >+ ASSERT_NOT_REACHED(); >+ int length = lengthExpression.integerLiteral().value(); >+ ASSERT(length >= 2 && length <= 4); >+ nativeTypeDeclaration.setIsVector(); >+ array[length - 2] = &nativeTypeDeclaration; >+ return true; >+} >+ >+bool Intrinsics::addMatrix(AST::NativeTypeDeclaration& nativeTypeDeclaration) >+{ >+ if (nativeTypeDeclaration.name() != "matrix") >+ return false; >+ >+ ASSERT(nativeTypeDeclaration.typeArguments().size() == 3); >+ ASSERT(WTF::holds_alternative<UniqueRef<AST::TypeReference>>(nativeTypeDeclaration.typeArguments()[0])); >+ ASSERT(WTF::holds_alternative<AST::ConstantExpression>(nativeTypeDeclaration.typeArguments()[1])); >+ ASSERT(WTF::holds_alternative<AST::ConstantExpression>(nativeTypeDeclaration.typeArguments()[2])); >+ auto& innerType = static_cast<AST::TypeReference&>(WTF::get<UniqueRef<AST::TypeReference>>(nativeTypeDeclaration.typeArguments()[0])); >+ auto& rowExpression = WTF::get<AST::ConstantExpression>(nativeTypeDeclaration.typeArguments()[1]); >+ auto& columnExpression = WTF::get<AST::ConstantExpression>(nativeTypeDeclaration.typeArguments()[2]); >+ ASSERT(!innerType.typeArguments().size()); >+ AST::NativeTypeDeclaration* (*array)[3]; >+ if (innerType.name() == "half") >+ array = m_matrixHalf; >+ if (innerType.name() == "float") >+ array = m_matrixFloat; >+ int row = rowExpression.integerLiteral().value(); >+ ASSERT(row >= 2 && row <= 4); >+ int column = columnExpression.integerLiteral().value(); >+ ASSERT(column >= 2 && column <= 4); >+ nativeTypeDeclaration.setIsMatrix(); >+ array[row - 2][column - 2] = &nativeTypeDeclaration; >+ return true; >+} >+ >+bool Intrinsics::addFullTexture(AST::NativeTypeDeclaration& nativeTypeDeclaration, AST::TypeReference& innerType) >+{ >+ unsigned textureTypeIndex = m_textureTypeNames.size(); >+ for (unsigned i = 0; i < m_textureTypeNames.size(); ++i) { >+ if (nativeTypeDeclaration.name() == m_textureTypeNames[i]) >+ textureTypeIndex = i; >+ } >+ if (textureTypeIndex == m_textureTypeNames.size()) >+ return false; >+ >+ unsigned innerTypeIndex = m_textureInnerTypeNames.size(); >+ unsigned vectorLength; >+ for (unsigned i = 0; i < m_textureInnerTypeNames.size(); ++i) { >+ if (innerType.name().startsWith(m_textureInnerTypeNames[i])) { >+ textureTypeIndex = i; >+ if (innerType.name() == m_textureInnerTypeNames[i]) >+ vectorLength = 1; >+ else { >+ ASSERT(innerType.name().length() == m_textureInnerTypeNames[i].length() + 1); >+ ASSERT(innerType.name()[innerType.name().length() - 1] == '2' >+ || innerType.name()[innerType.name().length() - 1] == '3' >+ || innerType.name()[innerType.name().length() - 1] == '4'); >+ vectorLength = innerType.name()[innerType.name().length() - 1] - '0'; >+ } >+ } >+ } >+ ASSERT(innerTypeIndex != m_textureInnerTypeNames.size()); >+ nativeTypeDeclaration.setIsTexture(); >+ m_fullTextures[textureTypeIndex][innerTypeIndex][vectorLength - 1] = &nativeTypeDeclaration; >+ return true; >+} >+ >+bool Intrinsics::addDepthTexture(AST::NativeTypeDeclaration& nativeTypeDeclaration, AST::TypeReference& innerType) >+{ >+ AST::NativeTypeDeclaration** texture; >+ if (nativeTypeDeclaration.name() == "TextureDepth2D") >+ texture = m_textureDepth2D; >+ else if (nativeTypeDeclaration.name() == "RWTextureDepth2D") >+ texture = m_rwTextureDepth2D; >+ else if (nativeTypeDeclaration.name() == "TextureDepth2DArray") >+ texture = m_textureDepth2DArray; >+ else if (nativeTypeDeclaration.name() == "RWTextureDepth2DArray") >+ texture = m_rwTextureDepth2DArray; >+ else if (nativeTypeDeclaration.name() == "TextureDepthCube") >+ texture = m_textureDepthCube; >+ else >+ ASSERT_NOT_REACHED(); >+ unsigned innerTypeIndex = m_depthTextureInnerTypes.size(); >+ for (unsigned i = 0; i < m_depthTextureInnerTypes.size(); ++i) { >+ if (innerType.name() == m_depthTextureInnerTypes[i]) >+ innerTypeIndex = i; >+ } >+ ASSERT(innerTypeIndex != m_depthTextureInnerTypes.size()); >+ nativeTypeDeclaration.setIsTexture(); >+ texture[innerTypeIndex] = &nativeTypeDeclaration; >+ return true; >+} >+ >+void Intrinsics::addTexture(AST::NativeTypeDeclaration& nativeTypeDeclaration) >+{ >+ ASSERT(nativeTypeDeclaration.typeArguments().size() == 1); >+ ASSERT(WTF::holds_alternative<UniqueRef<AST::TypeReference>>(nativeTypeDeclaration.typeArguments()[0])); >+ auto& innerType = static_cast<AST::TypeReference&>(WTF::get<UniqueRef<AST::TypeReference>>(nativeTypeDeclaration.typeArguments()[0])); >+ ASSERT(!innerType.typeArguments().size()); >+ if (addFullTexture(nativeTypeDeclaration, innerType)) { >+ m_textureSet.add(&nativeTypeDeclaration); >+ return; >+ } >+ if (addDepthTexture(nativeTypeDeclaration, innerType)) >+ m_textureSet.add(&nativeTypeDeclaration); >+} >+ >+void Intrinsics::add(AST::NativeTypeDeclaration& nativeTypeDeclaration) >+{ >+ if (addPrimitive(nativeTypeDeclaration)) >+ return; >+ if (addVector(nativeTypeDeclaration)) >+ return; >+ if (addMatrix(nativeTypeDeclaration)) >+ return; >+ addTexture(nativeTypeDeclaration); >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLIntrinsics.h b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLIntrinsics.h >new file mode 100644 >index 0000000000000000000000000000000000000000..ad36f281087acd8da601256714a4ff4512fd1588 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLIntrinsics.h >@@ -0,0 +1,151 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#pragma once >+ >+#if ENABLE(WEBGPU) >+ >+#include "WHLSLNativeFunctionDeclaration.h" >+#include "WHLSLNativeTypeDeclaration.h" >+#include <cstring> >+#include <wtf/HashSet.h> >+#include <wtf/StdLibExtras.h> >+#include <wtf/Vector.h> >+#include <wtf/text/WTFString.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+class Intrinsics { >+public: >+ Intrinsics(); >+ >+ void add(AST::NativeFunctionDeclaration&); >+ void add(AST::NativeTypeDeclaration&); >+ >+ AST::NativeTypeDeclaration& voidType() const >+ { >+ ASSERT(m_voidType); >+ return *m_voidType; >+ } >+ >+ AST::NativeTypeDeclaration& boolType() const >+ { >+ ASSERT(m_boolType); >+ return *m_boolType; >+ } >+ >+ AST::NativeTypeDeclaration& intType() const >+ { >+ ASSERT(m_intType); >+ return *m_intType; >+ } >+ >+ AST::NativeTypeDeclaration& uintType() const >+ { >+ ASSERT(m_uintType); >+ return *m_uintType; >+ } >+ >+ AST::NativeTypeDeclaration& samplerType() const >+ { >+ ASSERT(m_samplerType); >+ return *m_samplerType; >+ } >+ >+ AST::NativeTypeDeclaration& floatType() const >+ { >+ ASSERT(m_floatType); >+ return *m_floatType; >+ } >+ >+ AST::NativeTypeDeclaration& float3Type() const >+ { >+ ASSERT(m_vectorFloat[1]); >+ return *m_vectorFloat[1]; >+ } >+ >+ AST::NativeTypeDeclaration& float4Type() const >+ { >+ ASSERT(m_vectorFloat[2]); >+ return *m_vectorFloat[2]; >+ } >+ >+private: >+ bool addPrimitive(AST::NativeTypeDeclaration&); >+ bool addVector(AST::NativeTypeDeclaration&); >+ bool addMatrix(AST::NativeTypeDeclaration&); >+ bool addFullTexture(AST::NativeTypeDeclaration&, AST::TypeReference&); >+ bool addDepthTexture(AST::NativeTypeDeclaration&, AST::TypeReference&); >+ void addTexture(AST::NativeTypeDeclaration&); >+ >+ HashSet<const AST::NativeTypeDeclaration*> m_textureSet; >+ >+ AST::NativeTypeDeclaration* m_voidType; >+ AST::NativeTypeDeclaration* m_boolType; >+ AST::NativeTypeDeclaration* m_ucharType; >+ AST::NativeTypeDeclaration* m_ushortType; >+ AST::NativeTypeDeclaration* m_uintType; >+ AST::NativeTypeDeclaration* m_charType; >+ AST::NativeTypeDeclaration* m_shortType; >+ AST::NativeTypeDeclaration* m_intType; >+ AST::NativeTypeDeclaration* m_halfType; >+ AST::NativeTypeDeclaration* m_floatType; >+ AST::NativeTypeDeclaration* m_atomicIntType; >+ AST::NativeTypeDeclaration* m_atomicUintType; >+ AST::NativeTypeDeclaration* m_samplerType; >+ >+ AST::NativeTypeDeclaration* m_vectorBool[3]; >+ AST::NativeTypeDeclaration* m_vectorUchar[3]; >+ AST::NativeTypeDeclaration* m_vectorUshort[3]; >+ AST::NativeTypeDeclaration* m_vectorUint[3]; >+ AST::NativeTypeDeclaration* m_vectorChar[3]; >+ AST::NativeTypeDeclaration* m_vectorShort[3]; >+ AST::NativeTypeDeclaration* m_vectorInt[3]; >+ AST::NativeTypeDeclaration* m_vectorHalf[3]; >+ AST::NativeTypeDeclaration* m_vectorFloat[3]; >+ >+ AST::NativeTypeDeclaration* m_matrixHalf[3][3]; >+ AST::NativeTypeDeclaration* m_matrixFloat[3][3]; >+ >+ Vector<String> m_textureTypeNames; >+ Vector<String> m_textureInnerTypeNames; >+ >+ AST::NativeTypeDeclaration* m_fullTextures[11][8][4]; >+ >+ Vector<String> m_depthTextureInnerTypes; >+ AST::NativeTypeDeclaration* m_textureDepth2D[2]; >+ AST::NativeTypeDeclaration* m_rwTextureDepth2D[2]; >+ AST::NativeTypeDeclaration* m_textureDepth2DArray[2]; >+ AST::NativeTypeDeclaration* m_rwTextureDepth2DArray[2]; >+ AST::NativeTypeDeclaration* m_textureDepthCube[2]; >+}; >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp >index 6bf18e69afc5c8fe50d745e54d9626ddc0d50e0f..48fa9302208afefeee7e648cbcf5d37363b63e2c 100644 >--- a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp >@@ -197,7 +197,7 @@ void NameResolver::visit(AST::CallExpression& callExpression) > else { > if (auto* types = m_nameContext.getTypes(callExpression.name())) { > if (types->size() == 1) { >- if (auto* functions = m_nameContext.getFunctions(String("operator cast", String::ConstructFromLiteral))) { >+ if (auto* functions = m_nameContext.getFunctions("operator cast"_str)) { > callExpression.setCastData((*types)[0].get()); > callExpression.setOverloads(*functions); > } >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLProgram.h b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLProgram.h >index 0dcf3f5b8933eb4edaa73a1a5f1a824057e8a799..c93a767f8fd94f8b2c7eb5c73e51d4b31517cc74 100644 >--- a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLProgram.h >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLProgram.h >@@ -29,6 +29,7 @@ > > #include "WHLSLEnumerationDefinition.h" > #include "WHLSLFunctionDefinition.h" >+#include "WHLSLIntrinsics.h" > #include "WHLSLNameContext.h" > #include "WHLSLNativeFunctionDeclaration.h" > #include "WHLSLNativeTypeDeclaration.h" >@@ -72,16 +73,19 @@ public: > bool append(AST::NativeFunctionDeclaration&& nativeFunctionDeclaration) > { > m_nativeFunctionDeclarations.append(makeUniqueRef<AST::NativeFunctionDeclaration>(WTFMove(nativeFunctionDeclaration))); >+ m_intrinsics.add(static_cast<AST::NativeFunctionDeclaration&>(m_nativeFunctionDeclarations.last())); > return m_nameContext.add(static_cast<AST::NativeFunctionDeclaration&>(m_nativeFunctionDeclarations.last())); > } > > bool append(AST::NativeTypeDeclaration&& nativeTypeDeclaration) > { > m_nativeTypeDeclarations.append(makeUniqueRef<AST::NativeTypeDeclaration>(WTFMove(nativeTypeDeclaration))); >+ m_intrinsics.add(static_cast<AST::NativeTypeDeclaration&>(m_nativeTypeDeclarations.last())); > return m_nameContext.add(static_cast<AST::NativeTypeDeclaration&>(m_nativeTypeDeclarations.last())); > } > > NameContext& nameContext() { return m_nameContext; } >+ Intrinsics& intrinsics() { return m_intrinsics; } > Vector<UniqueRef<AST::TypeDefinition>>& typeDefinitions() { return m_typeDefinitions; } > Vector<UniqueRef<AST::StructureDefinition>>& structureDefinitions() { return m_structureDefinitions; } > Vector<UniqueRef<AST::EnumerationDefinition>>& enumerationDefinitions() { return m_enumerationDefinitions; } >@@ -93,6 +97,7 @@ public: > > private: > NameContext m_nameContext; >+ Intrinsics m_intrinsics; > Vector<UniqueRef<AST::TypeDefinition>> m_typeDefinitions; > Vector<UniqueRef<AST::StructureDefinition>> m_structureDefinitions; > Vector<UniqueRef<AST::EnumerationDefinition>> m_enumerationDefinitions; >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLRecursiveTypeChecker.cpp b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLRecursiveTypeChecker.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..f1118d0a956eb580e49d5bba375ef2e4618eb03e >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLRecursiveTypeChecker.cpp >@@ -0,0 +1,105 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#include "config.h" >+#include "WHLSLRecursiveTypeChecker.h" >+ >+#if ENABLE(WEBGPU) >+ >+#include "WHLSLVisitor.h" >+#include <wtf/HashSet.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+class RecursiveTypeChecker : public Visitor { >+public: >+ ~RecursiveTypeChecker() = default; >+ >+ void visit(AST::TypeDefinition& typeDefinition) override >+ { >+ auto addResult = m_types.add(&typeDefinition); >+ if (addResult.isNewEntry) { >+ setError(); >+ return; >+ } >+ >+ checkErrorAndVisit(typeDefinition); >+ >+ auto success = m_types.remove(&typeDefinition); >+ ASSERT_UNUSED(success, success); >+ } >+ >+ void visit(AST::StructureDefinition& structureDefinition) override >+ { >+ auto addResult = m_types.add(&structureDefinition); >+ if (addResult.isNewEntry) { >+ setError(); >+ return; >+ } >+ >+ checkErrorAndVisit(structureDefinition); >+ >+ auto success = m_types.remove(&structureDefinition); >+ ASSERT_UNUSED(success, success); >+ } >+ >+ void visit(AST::TypeReference& typeReference) override >+ { >+ auto addResult = m_types.add(&typeReference); >+ if (addResult.isNewEntry) { >+ setError(); >+ return; >+ } >+ >+ for (auto& typeArgument : typeReference.typeArguments()) >+ checkErrorAndVisit(typeArgument); >+ checkErrorAndVisit(*typeReference.resolvedType()); >+ >+ auto success = m_types.remove(&typeReference); >+ ASSERT_UNUSED(success, success); >+ } >+ >+ void visit(AST::ReferenceType&) override >+ { >+ } >+ >+private: >+ HashSet<AST::Type*> m_types; >+}; >+ >+bool checkRecursiveTypes(Program& program) >+{ >+ RecursiveTypeChecker recursiveTypeChecker; >+ recursiveTypeChecker.checkErrorAndVisit(program); >+ return recursiveTypeChecker.error(); >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLRecursiveTypeChecker.h b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLRecursiveTypeChecker.h >new file mode 100644 >index 0000000000000000000000000000000000000000..fc970c724966d13910ab2aaae1567d7c105a3394 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLRecursiveTypeChecker.h >@@ -0,0 +1,43 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#pragma once >+ >+#if ENABLE(WEBGPU) >+ >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+class Program; >+ >+bool checkRecursiveTypes(Program&); >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeArrayOperatorLength.cpp b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeArrayOperatorLength.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..9d620fa11a7072f86b0e83db333b21db7eca1051 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeArrayOperatorLength.cpp >@@ -0,0 +1,81 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#include "config.h" >+#include "WHLSLSynthesizeArrayOperatorLength.h" >+ >+#if ENABLE(WEBGPU) >+ >+#include "WHLSLArrayType.h" >+#include "WHLSLProgram.h" >+#include "WHLSLTypeReference.h" >+#include "WHLSLVisitor.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+class FindArrayTypes : public Visitor { >+public: >+ ~FindArrayTypes() = default; >+ >+ void visit(AST::ArrayType& arrayType) override >+ { >+ m_arrayTypes.append(arrayType); >+ checkErrorAndVisit(arrayType); >+ } >+ >+ Vector<std::reference_wrapper<AST::ArrayType>>&& takeArrayTypes() >+ { >+ return WTFMove(m_arrayTypes); >+ } >+ >+private: >+ Vector<std::reference_wrapper<AST::ArrayType>> m_arrayTypes; >+}; >+ >+void synthesizeArrayOperatorLength(Program& program) >+{ >+ FindArrayTypes findArrayTypes; >+ findArrayTypes.checkErrorAndVisit(program); >+ auto arrayTypes = findArrayTypes.takeArrayTypes(); >+ >+ bool isOperator = true; >+ bool isRestricted = false; >+ >+ for (auto& arrayType : arrayTypes) { >+ AST::VariableDeclaration variableDeclaration(Lexer::Token(arrayType.get().origin()), AST::Qualifiers(), { arrayType.get().clone() }, String(), WTF::nullopt, WTF::nullopt); >+ AST::VariableDeclarations parameters; >+ parameters.append(WTFMove(variableDeclaration)); >+ AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(Lexer::Token(arrayType.get().origin()), AST::AttributeBlock(), WTF::nullopt, AST::TypeReference::wrap(Lexer::Token(arrayType.get().origin()), program.intrinsics().uintType()), "operator.length"_str, WTFMove(parameters), WTF::nullopt, isOperator), isRestricted); >+ program.append(WTFMove(nativeFunctionDeclaration)); >+ } >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeArrayOperatorLength.h b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeArrayOperatorLength.h >new file mode 100644 >index 0000000000000000000000000000000000000000..2012f2b0102acac51360b19ecb93ae5eb08a568e >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeArrayOperatorLength.h >@@ -0,0 +1,42 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#pragma once >+ >+#if ENABLE(WEBGPU) >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+class Program; >+ >+void synthesizeArrayOperatorLength(Program&); >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeConstructors.cpp b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeConstructors.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..85e2b881d9b40a3885e2930cc8cd71bb39d9c206 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeConstructors.cpp >@@ -0,0 +1,133 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#include "config.h" >+#include "WHLSLSynthesizeConstructors.h" >+ >+#if ENABLE(WEBGPU) >+ >+#include "WHLSLNativeFunctionDeclaration.h" >+#include "WHLSLProgram.h" >+#include "WHLSLTypeReference.h" >+#include "WHLSLVariableDeclaration.h" >+#include "WHLSLVisitor.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+class FindAllTypes : public Visitor { >+public: >+ ~FindAllTypes() = default; >+ >+ void visit(AST::PointerType& pointerType) override >+ { >+ m_unnamedTypes.append(pointerType); >+ checkErrorAndVisit(pointerType); >+ } >+ >+ void visit(AST::ArrayReferenceType& arrayReferenceType) override >+ { >+ m_unnamedTypes.append(arrayReferenceType); >+ checkErrorAndVisit(arrayReferenceType); >+ } >+ >+ void visit(AST::ArrayType& arrayType) override >+ { >+ m_unnamedTypes.append(arrayType); >+ checkErrorAndVisit(arrayType); >+ } >+ >+ void visit(AST::EnumerationDefinition& enumerationDefinition) override >+ { >+ m_namedTypes.append(enumerationDefinition); >+ checkErrorAndVisit(enumerationDefinition); >+ } >+ >+ void visit(AST::StructureDefinition& structureDefinition) override >+ { >+ m_namedTypes.append(structureDefinition); >+ checkErrorAndVisit(structureDefinition); >+ } >+ >+ void visit(AST::NativeTypeDeclaration& nativeTypeDeclaration) override >+ { >+ m_namedTypes.append(nativeTypeDeclaration); >+ checkErrorAndVisit(nativeTypeDeclaration); >+ } >+ >+ Vector<std::reference_wrapper<AST::UnnamedType>>&& takeUnnamedTypes() >+ { >+ return WTFMove(m_unnamedTypes); >+ } >+ >+ Vector<std::reference_wrapper<AST::NamedType>>&& takeNamedTypes() >+ { >+ return WTFMove(m_namedTypes); >+ } >+ >+private: >+ Vector<std::reference_wrapper<AST::UnnamedType>> m_unnamedTypes; >+ Vector<std::reference_wrapper<AST::NamedType>> m_namedTypes; >+}; >+ >+void synthesizeConstructors(Program& program) >+{ >+ FindAllTypes findAllTypes; >+ findAllTypes.checkErrorAndVisit(program); >+ auto m_unnamedTypes = findAllTypes.takeUnnamedTypes(); >+ auto m_namedTypes = findAllTypes.takeNamedTypes(); >+ >+ bool isOperator = true; >+ bool isRestricted = false; >+ >+ for (auto& unnamedType : m_unnamedTypes) { >+ AST::VariableDeclaration variableDeclaration(Lexer::Token(unnamedType.get().origin()), AST::Qualifiers(), { unnamedType.get().clone() }, String(), WTF::nullopt, WTF::nullopt); >+ AST::VariableDeclarations parameters; >+ parameters.append(WTFMove(variableDeclaration)); >+ AST::NativeFunctionDeclaration copyConstructor(AST::FunctionDeclaration(Lexer::Token(unnamedType.get().origin()), AST::AttributeBlock(), WTF::nullopt, unnamedType.get().clone(), "operator cast"_str, WTFMove(parameters), WTF::nullopt, isOperator), isRestricted); >+ program.append(WTFMove(copyConstructor)); >+ >+ AST::NativeFunctionDeclaration defaultConstructor(AST::FunctionDeclaration(Lexer::Token(unnamedType.get().origin()), AST::AttributeBlock(), WTF::nullopt, unnamedType.get().clone(), "operator cast"_str, AST::VariableDeclarations(), WTF::nullopt, isOperator), isRestricted); >+ program.append(WTFMove(defaultConstructor)); >+ } >+ >+ for (auto& namedType : m_namedTypes) { >+ AST::VariableDeclaration variableDeclaration(Lexer::Token(namedType.get().origin()), AST::Qualifiers(), { AST::TypeReference::wrap(Lexer::Token(namedType.get().origin()), namedType.get()) }, String(), WTF::nullopt, WTF::nullopt); >+ AST::VariableDeclarations parameters; >+ parameters.append(WTFMove(variableDeclaration)); >+ AST::NativeFunctionDeclaration copyConstructor(AST::FunctionDeclaration(Lexer::Token(namedType.get().origin()), AST::AttributeBlock(), WTF::nullopt, AST::TypeReference::wrap(Lexer::Token(namedType.get().origin()), namedType.get()), "operator cast"_str, WTFMove(parameters), WTF::nullopt, isOperator), isRestricted); >+ program.append(WTFMove(copyConstructor)); >+ >+ AST::NativeFunctionDeclaration defaultConstructor(AST::FunctionDeclaration(Lexer::Token(namedType.get().origin()), AST::AttributeBlock(), WTF::nullopt, AST::TypeReference::wrap(Lexer::Token(namedType.get().origin()), namedType.get()), "operator cast"_str, AST::VariableDeclarations(), WTF::nullopt, isOperator), isRestricted); >+ program.append(WTFMove(defaultConstructor)); >+ } >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeConstructors.h b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeConstructors.h >new file mode 100644 >index 0000000000000000000000000000000000000000..19a05bea623a9b9b0a9cff4b4f42ff701debd436 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeConstructors.h >@@ -0,0 +1,42 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#pragma once >+ >+#if ENABLE(WEBGPU) >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+class Program; >+ >+void synthesizeConstructors(Program&); >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeEnumerationFunctions.cpp b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeEnumerationFunctions.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..63fefb43dc7e059ea1e32cd928feaef6cc994610 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeEnumerationFunctions.cpp >@@ -0,0 +1,86 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#include "config.h" >+#include "WHLSLSynthesizeEnumerationFunctions.h" >+ >+#if ENABLE(WEBGPU) >+ >+#include "WHLSLProgram.h" >+#include "WHLSLTypeReference.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+void synthesizeEnumerationFunctions(Program& program) >+{ >+ bool isOperator = true; >+ bool isRestricted = false; >+ for (auto& enumerationDefinition : program.enumerationDefinitions()) { >+ { >+ AST::VariableDeclaration variableDeclaration1(Lexer::Token(enumerationDefinition->origin()), AST::Qualifiers(), { AST::TypeReference::wrap(Lexer::Token(enumerationDefinition->origin()), static_cast<AST::EnumerationDefinition&>(enumerationDefinition)) }, String(), WTF::nullopt, WTF::nullopt); >+ AST::VariableDeclaration variableDeclaration2(Lexer::Token(enumerationDefinition->origin()), AST::Qualifiers(), { AST::TypeReference::wrap(Lexer::Token(enumerationDefinition->origin()), static_cast<AST::EnumerationDefinition&>(enumerationDefinition)) }, String(), WTF::nullopt, WTF::nullopt); >+ AST::VariableDeclarations parameters; >+ parameters.append(WTFMove(variableDeclaration1)); >+ parameters.append(WTFMove(variableDeclaration2)); >+ AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(Lexer::Token(enumerationDefinition->origin()), AST::AttributeBlock(), WTF::nullopt, AST::TypeReference::wrap(Lexer::Token(enumerationDefinition->origin()), program.intrinsics().boolType()), "operator=="_str, WTFMove(parameters), WTF::nullopt, isOperator), isRestricted); >+ program.append(WTFMove(nativeFunctionDeclaration)); >+ } >+ >+ if (enumerationDefinition->type()) { >+ // FIXME: Handle a null base type. >+ { >+ AST::VariableDeclaration variableDeclaration(Lexer::Token(enumerationDefinition->origin()), AST::Qualifiers(), { AST::TypeReference::wrap(Lexer::Token(enumerationDefinition->origin()), static_cast<AST::EnumerationDefinition&>(enumerationDefinition)) }, String(), WTF::nullopt, WTF::nullopt); >+ AST::VariableDeclarations parameters; >+ parameters.append(WTFMove(variableDeclaration)); >+ AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(Lexer::Token(enumerationDefinition->origin()), AST::AttributeBlock(), WTF::nullopt, enumerationDefinition->type()->clone(), "operator.value"_str, WTFMove(parameters), WTF::nullopt, isOperator), isRestricted); >+ program.append(WTFMove(nativeFunctionDeclaration)); >+ } >+ >+ { >+ AST::VariableDeclaration variableDeclaration(Lexer::Token(enumerationDefinition->origin()), AST::Qualifiers(), { AST::TypeReference::wrap(Lexer::Token(enumerationDefinition->origin()), static_cast<AST::EnumerationDefinition&>(enumerationDefinition)) }, String(), WTF::nullopt, WTF::nullopt); >+ AST::VariableDeclarations parameters; >+ parameters.append(WTFMove(variableDeclaration)); >+ AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(Lexer::Token(enumerationDefinition->origin()), AST::AttributeBlock(), WTF::nullopt, enumerationDefinition->type()->clone(), "operator cast"_str, WTFMove(parameters), WTF::nullopt, isOperator), isRestricted); >+ program.append(WTFMove(nativeFunctionDeclaration)); >+ } >+ >+ { >+ AST::VariableDeclaration variableDeclaration(Lexer::Token(enumerationDefinition->origin()), AST::Qualifiers(), enumerationDefinition->type()->clone(), String(), WTF::nullopt, WTF::nullopt); >+ AST::VariableDeclarations parameters; >+ parameters.append(WTFMove(variableDeclaration)); >+ AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(Lexer::Token(enumerationDefinition->origin()), AST::AttributeBlock(), WTF::nullopt, { AST::TypeReference::wrap(Lexer::Token(enumerationDefinition->origin()), static_cast<AST::EnumerationDefinition&>(enumerationDefinition)) }, "operator cast"_str, WTFMove(parameters), WTF::nullopt, isOperator), isRestricted); >+ program.append(WTFMove(nativeFunctionDeclaration)); >+ } >+ } >+ } >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeEnumerationFunctions.h b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeEnumerationFunctions.h >new file mode 100644 >index 0000000000000000000000000000000000000000..2127fd11524c1c8328283c5bae923dfef01df5ad >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeEnumerationFunctions.h >@@ -0,0 +1,42 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#pragma once >+ >+#if ENABLE(WEBGPU) >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+class Program; >+ >+void synthesizeEnumerationFunctions(Program&); >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeStructureAccessors.cpp b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeStructureAccessors.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..b3422ddb359b5daaf5d192d54755f6e86d797856 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeStructureAccessors.cpp >@@ -0,0 +1,89 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#include "config.h" >+#include "WHLSLSynthesizeStructureAccessors.h" >+ >+#if ENABLE(WEBGPU) >+ >+#include "WHLSLPointerType.h" >+#include "WHLSLProgram.h" >+#include "WHLSLReferenceType.h" >+#include "WHLSLTypeReference.h" >+#include "WHLSLVariableDeclaration.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+void synthesizeStructureAccessors(Program& program) >+{ >+ bool isOperator = true; >+ bool isRestricted = false; >+ for (auto& structureDefinition : program.structureDefinitions()) { >+ for (auto& structureElement : structureDefinition->structureElements()) { >+ { >+ // The getter: operator.field >+ AST::VariableDeclaration variableDeclaration(Lexer::Token(structureElement.origin()), AST::Qualifiers(), { AST::TypeReference::wrap(Lexer::Token(structureElement.origin()), static_cast<AST::StructureDefinition&>(structureDefinition)) }, String(), WTF::nullopt, WTF::nullopt); >+ AST::VariableDeclarations parameters; >+ parameters.append(WTFMove(variableDeclaration)); >+ AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(Lexer::Token(structureElement.origin()), AST::AttributeBlock(), WTF::nullopt, structureElement.type().clone(), String::format("operator.%s", structureElement.name().utf8().data()), WTFMove(parameters), WTF::nullopt, isOperator), isRestricted); >+ program.append(WTFMove(nativeFunctionDeclaration)); >+ } >+ >+ { >+ // The setter: operator.field= >+ AST::VariableDeclaration variableDeclaration1(Lexer::Token(structureElement.origin()), AST::Qualifiers(), { AST::TypeReference::wrap(Lexer::Token(structureElement.origin()), static_cast<AST::StructureDefinition&>(structureDefinition)) }, String(), WTF::nullopt, WTF::nullopt); >+ AST::VariableDeclaration variableDeclaration2(Lexer::Token(structureElement.origin()), AST::Qualifiers(), { structureElement.type().clone() }, String(), WTF::nullopt, WTF::nullopt); >+ AST::VariableDeclarations parameters; >+ parameters.append(WTFMove(variableDeclaration1)); >+ parameters.append(WTFMove(variableDeclaration2)); >+ AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(Lexer::Token(structureElement.origin()), AST::AttributeBlock(), WTF::nullopt, AST::TypeReference::wrap(Lexer::Token(structureElement.origin()), static_cast<AST::StructureDefinition&>(structureDefinition)), String::format("operator.%s=", structureElement.name().utf8().data()), WTFMove(parameters), WTF::nullopt, isOperator), isRestricted); >+ program.append(WTFMove(nativeFunctionDeclaration)); >+ } >+ >+ // The ander: operator&.field >+ auto createAnder = [&](AST::ReferenceType::AddressSpace addressSpace) -> AST::NativeFunctionDeclaration { >+ auto argumentType = makeUniqueRef<AST::PointerType>(Lexer::Token(structureElement.origin()), addressSpace, AST::TypeReference::wrap(Lexer::Token(structureElement.origin()), static_cast<AST::StructureDefinition&>(structureDefinition))); >+ AST::VariableDeclaration variableDeclaration(Lexer::Token(structureElement.origin()), AST::Qualifiers(), { WTFMove(argumentType) }, String(), WTF::nullopt, WTF::nullopt); >+ AST::VariableDeclarations parameters; >+ parameters.append(WTFMove(variableDeclaration)); >+ auto returnType = makeUniqueRef<AST::PointerType>(Lexer::Token(structureElement.origin()), addressSpace, structureElement.type().clone()); >+ AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(Lexer::Token(structureElement.origin()), AST::AttributeBlock(), WTF::nullopt, WTFMove(returnType), String::format("operator&.%s", structureElement.name().utf8().data()), WTFMove(parameters), WTF::nullopt, isOperator), isRestricted); >+ return nativeFunctionDeclaration; >+ }; >+ program.append(createAnder(AST::ReferenceType::AddressSpace::Constant)); >+ program.append(createAnder(AST::ReferenceType::AddressSpace::Device)); >+ program.append(createAnder(AST::ReferenceType::AddressSpace::Threadgroup)); >+ program.append(createAnder(AST::ReferenceType::AddressSpace::Thread)); >+ } >+ } >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeStructureAccessors.h b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeStructureAccessors.h >new file mode 100644 >index 0000000000000000000000000000000000000000..bb9f2b9ad398a0ebf7948b56ad9c4d9304408cbf >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeStructureAccessors.h >@@ -0,0 +1,42 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#pragma once >+ >+#if ENABLE(WEBGPU) >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+class Program; >+ >+void synthesizeStructureAccessors(Program&); >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Sources.txt b/Source/WebCore/Sources.txt >index 06f32d19d82b79535e6d523a33fc4a76b84f324d..0d256353d74abd62663024bd8054c950e0738103 100644 >--- a/Source/WebCore/Sources.txt >+++ b/Source/WebCore/Sources.txt >@@ -309,6 +309,13 @@ Modules/webgpu/DOMWindowWebGPU.cpp > Modules/webgpu/WHLSL/WHLSLInferTypes.cpp > Modules/webgpu/WHLSL/WHLSLLexer.cpp > Modules/webgpu/WHLSL/WHLSLParser.cpp >+Modules/webgpu/WHLSL/WHLSLCheckDuplicateFunctions.cpp >+Modules/webgpu/WHLSL/WHLSLRecursiveTypeChecker.cpp >+Modules/webgpu/WHLSL/WHLSLSynthesizeArrayOperatorLength.cpp >+Modules/webgpu/WHLSL/WHLSLSynthesizeConstructors.cpp >+Modules/webgpu/WHLSL/WHLSLSynthesizeEnumerationFunctions.cpp >+Modules/webgpu/WHLSL/WHLSLSynthesizeStructureAccessors.cpp >+Modules/webgpu/WHLSL/WHLSLIntrinsics.cpp > Modules/webgpu/WHLSL/WHLSLNameContext.cpp > Modules/webgpu/WHLSL/WHLSLNameResolver.cpp > Modules/webgpu/WHLSL/WHLSLResolveOverloadImpl.cpp >diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >index 7a9e1df63ba78d7315fdcdb2969dae9643829358..6493844b88d5064341250b4ddd5fc05135b87777 100644 >--- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj >+++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >@@ -13332,6 +13332,20 @@ > C234A99A21E90F56003C984D /* WHLSLInferTypes.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLInferTypes.cpp; sourceTree = "<group>"; }; > C234A99B21E90F57003C984D /* WHLSLInferTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLInferTypes.h; sourceTree = "<group>"; }; > C234A99D21E910BD003C984D /* WHLSLResolvingType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLResolvingType.h; sourceTree = "<group>"; }; >+ C234A9A921E92C17003C984D /* WHLSLSynthesizeArrayOperatorLength.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLSynthesizeArrayOperatorLength.cpp; sourceTree = "<group>"; }; >+ C234A9AB21E92C18003C984D /* WHLSLRecursiveTypeChecker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLRecursiveTypeChecker.h; sourceTree = "<group>"; }; >+ C234A9AC21E92C19003C984D /* WHLSLSynthesizeEnumerationFunctions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLSynthesizeEnumerationFunctions.h; sourceTree = "<group>"; }; >+ C234A9AD21E92C19003C984D /* WHLSLRecursiveTypeChecker.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLRecursiveTypeChecker.cpp; sourceTree = "<group>"; }; >+ C234A9AE21E92C1A003C984D /* WHLSLCheckDuplicateFunctions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLCheckDuplicateFunctions.h; sourceTree = "<group>"; }; >+ C234A9AF21E92C1B003C984D /* WHLSLSynthesizeArrayOperatorLength.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLSynthesizeArrayOperatorLength.h; sourceTree = "<group>"; }; >+ C234A9B021E92C1C003C984D /* WHLSLSynthesizeConstructors.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLSynthesizeConstructors.cpp; sourceTree = "<group>"; }; >+ C234A9B121E92C1D003C984D /* WHLSLSynthesizeConstructors.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLSynthesizeConstructors.h; sourceTree = "<group>"; }; >+ C234A9B221E92C1F003C984D /* WHLSLCheckDuplicateFunctions.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLCheckDuplicateFunctions.cpp; sourceTree = "<group>"; }; >+ C234A9B321E92C21003C984D /* WHLSLSynthesizeEnumerationFunctions.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLSynthesizeEnumerationFunctions.cpp; sourceTree = "<group>"; }; >+ C234A9B421E92C22003C984D /* WHLSLSynthesizeStructureAccessors.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLSynthesizeStructureAccessors.cpp; sourceTree = "<group>"; }; >+ C234A9B521E92C23003C984D /* WHLSLSynthesizeStructureAccessors.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLSynthesizeStructureAccessors.h; sourceTree = "<group>"; }; >+ C234A9B621E92CC0003C984D /* WHLSLIntrinsics.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLIntrinsics.h; sourceTree = "<group>"; }; >+ C234A9B721E92CC1003C984D /* WHLSLIntrinsics.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLIntrinsics.cpp; sourceTree = "<group>"; }; > C21DF2E71D9E4E9900F5B24C /* CSSFontVariationValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSFontVariationValue.cpp; sourceTree = "<group>"; }; > C21DF2E81D9E4E9900F5B24C /* CSSFontVariationValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSFontVariationValue.h; sourceTree = "<group>"; }; > C234A98521E886A9003C984D /* WHLSLVisitor.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLVisitor.cpp; sourceTree = "<group>"; }; >@@ -25399,8 +25413,12 @@ > isa = PBXGroup; > children = ( > C21BF6F121CD898D00227979 /* AST */, >+ C234A9B221E92C1F003C984D /* WHLSLCheckDuplicateFunctions.cpp */, >+ C234A9AE21E92C1A003C984D /* WHLSLCheckDuplicateFunctions.h */, > C234A99A21E90F56003C984D /* WHLSLInferTypes.cpp */, > C234A99B21E90F57003C984D /* WHLSLInferTypes.h */, >+ C234A9B721E92CC1003C984D /* WHLSLIntrinsics.cpp */, >+ C234A9B621E92CC0003C984D /* WHLSLIntrinsics.h */, > C210E91121B4BD1000B7F83D /* WHLSLLexer.cpp */, > C210E91221B4BD1000B7F83D /* WHLSLLexer.h */, > C234A98D21E88884003C984D /* WHLSLNameContext.cpp */, >@@ -25410,10 +25428,20 @@ > C21BF73721CD8A0200227979 /* WHLSLParser.cpp */, > C21BF73821CD8A0300227979 /* WHLSLParser.h */, > C21BF73A21CD8D7000227979 /* WHLSLProgram.h */, >+ C234A9AD21E92C19003C984D /* WHLSLRecursiveTypeChecker.cpp */, >+ C234A9AB21E92C18003C984D /* WHLSLRecursiveTypeChecker.h */, > C234A99921E90F29003C984D /* WHLSLResolveOverloadImpl.cpp */, > C234A99721E90F28003C984D /* WHLSLResolveOverloadImpl.h */, > C234A99D21E910BD003C984D /* WHLSLResolvingType.h */, > C21BF74521CD969800227979 /* WHLSLStandardLibrary.txt */, >+ C234A9A921E92C17003C984D /* WHLSLSynthesizeArrayOperatorLength.cpp */, >+ C234A9AF21E92C1B003C984D /* WHLSLSynthesizeArrayOperatorLength.h */, >+ C234A9B021E92C1C003C984D /* WHLSLSynthesizeConstructors.cpp */, >+ C234A9B121E92C1D003C984D /* WHLSLSynthesizeConstructors.h */, >+ C234A9B321E92C21003C984D /* WHLSLSynthesizeEnumerationFunctions.cpp */, >+ C234A9AC21E92C19003C984D /* WHLSLSynthesizeEnumerationFunctions.h */, >+ C234A9B421E92C22003C984D /* WHLSLSynthesizeStructureAccessors.cpp */, >+ C234A9B521E92C23003C984D /* WHLSLSynthesizeStructureAccessors.h */, > C234A98521E886A9003C984D /* WHLSLVisitor.cpp */, > C234A98721E886AD003C984D /* WHLSLVisitor.h */, > );
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 193360
:
358932
|
358984
|
358994