WebKit Bugzilla
Attachment 371373 Details for
Bug 198163
: [WHLSL] Implement array references
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
WIP
file.txt (text/plain), 72.74 KB, created by
Myles C. Maxfield
on 2019-06-04 21:30:36 PDT
(
hide
)
Description:
WIP
Filename:
MIME Type:
Creator:
Myles C. Maxfield
Created:
2019-06-04 21:30:36 PDT
Size:
72.74 KB
patch
obsolete
>diff --git a/LayoutTests/webgpu/whlsl.html b/LayoutTests/webgpu/whlsl.html >index 965a641fc84..13726de8a38 100644 >--- a/LayoutTests/webgpu/whlsl.html >+++ b/LayoutTests/webgpu/whlsl.html >@@ -10,8 +10,8 @@ vertex float4 vertexShader(float4 position : attribute(0), float i : attribute(1 > return position; > } > >-fragment float4 fragmentShader(float4 position : SV_Position, constant float[] theBuffer : register(b0)) : SV_Target 0 { >- return float4(1.0, theBuffer[0], 1.0, 1.0); >+fragment float4 fragmentShader(float4 position : SV_Position) : SV_Target 0 { >+ return position; > } > `; > async function start() { >@@ -69,10 +69,10 @@ async function start() { > const vertexBuffer1 = device.createBuffer(vertexBuffer1Descriptor); > const vertexBuffer1ArrayBuffer = await vertexBuffer1.mapWriteAsync(); > const vertexBuffer1Float32Array = new Float32Array(vertexBuffer1ArrayBuffer); >- vertexBuffer1Float32Array[0] = 1; >- vertexBuffer1Float32Array[1] = 1; >- vertexBuffer1Float32Array[2] = 1; >- vertexBuffer1Float32Array[3] = 1; >+ vertexBuffer1Descriptor[0] = 1; >+ vertexBuffer1Descriptor[1] = 1; >+ vertexBuffer1Descriptor[2] = 1; >+ vertexBuffer1Descriptor[3] = 1; > vertexBuffer1.unmap(); > > const resourceBufferDescriptor = {size: Float32Array.BYTES_PER_ELEMENT, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.MAP_WRITE}; >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLPropertyAccessExpression.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLPropertyAccessExpression.h >index bb0c3012eeb..8f4aa0ea119 100644 >--- a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLPropertyAccessExpression.h >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLPropertyAccessExpression.h >@@ -99,7 +99,6 @@ public: > } > > Expression& base() { return m_base; } >- UniqueRef<Expression>& baseReference() { return m_base; } > UniqueRef<Expression> takeBase() { return WTFMove(m_base); } > > private: >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLEntryPointScaffolding.cpp b/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLEntryPointScaffolding.cpp >index da8c057857e..21974eb87d6 100644 >--- a/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLEntryPointScaffolding.cpp >+++ b/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLEntryPointScaffolding.cpp >@@ -32,7 +32,6 @@ > #include "WHLSLFunctionDefinition.h" > #include "WHLSLGatherEntryPointItems.h" > #include "WHLSLPipelineDescriptor.h" >-#include "WHLSLReferenceType.h" > #include "WHLSLResourceSemantic.h" > #include "WHLSLStageInOutSemantic.h" > #include "WHLSLStructureDefinition.h" >@@ -109,16 +108,7 @@ EntryPointScaffolding::EntryPointScaffolding(AST::FunctionDefinition& functionDe > for (size_t j = 0; j < m_layout[i].bindings.size(); ++j) { > NamedBinding namedBinding; > namedBinding.elementName = m_typeNamer.generateNextStructureElementName(); >- namedBinding.index = m_layout[i].bindings[j].internalName; >- WTF::visit(WTF::makeVisitor([&](UniformBufferBinding& uniformBufferBinding) { >- LengthInformation lengthInformation { m_typeNamer.generateNextStructureElementName(), m_generateNextVariableName(), uniformBufferBinding.lengthName }; >- namedBinding.lengthInformation = lengthInformation; >- }, [&](SamplerBinding&) { >- }, [&](TextureBinding&) { >- }, [&](StorageBufferBinding& storageBufferBinding) { >- LengthInformation lengthInformation { m_typeNamer.generateNextStructureElementName(), m_generateNextVariableName(), storageBufferBinding.lengthName }; >- namedBinding.lengthInformation = lengthInformation; >- }), m_layout[i].bindings[j].binding); >+ namedBinding.index = m_layout[i].bindings[j].name; // GPUBindGroupLayout::tryCreate() makes sure these don't collide. > namedBindGroup.namedBindings.uncheckedAppend(WTFMove(namedBinding)); > } > m_namedBindGroups.uncheckedAppend(WTFMove(namedBindGroup)); >@@ -147,16 +137,10 @@ String EntryPointScaffolding::resourceHelperTypes() > auto iterator = m_resourceMap.find(&m_layout[i].bindings[j]); > if (iterator == m_resourceMap.end()) > continue; >- auto& unnamedType = *m_entryPointItems.inputs[iterator->value].unnamedType; >- ASSERT(is<AST::ReferenceType>(unnamedType)); >- auto& referenceType = downcast<AST::ReferenceType>(unnamedType); >- auto mangledTypeName = m_typeNamer.mangledNameForType(referenceType.elementType()); >- auto addressSpace = toString(referenceType.addressSpace()); >+ auto mangledTypeName = m_typeNamer.mangledNameForType(*m_entryPointItems.inputs[iterator->value].unnamedType); > auto elementName = m_namedBindGroups[i].namedBindings[j].elementName; > auto index = m_namedBindGroups[i].namedBindings[j].index; >- stringBuilder.append(makeString(" ", addressSpace, " ", mangledTypeName, "* ", elementName, " [[id(", index, ")]];\n")); >- if (auto lengthInformation = m_namedBindGroups[i].namedBindings[j].lengthInformation) >- stringBuilder.append(makeString(" uint2 ", lengthInformation->elementName, " [[id(", lengthInformation->index, ")]];\n")); >+ stringBuilder.append(makeString(" ", mangledTypeName, ' ', elementName, " [[id(", index, ")]];\n")); > } > stringBuilder.append("};\n\n"); > } >@@ -273,28 +257,9 @@ String EntryPointScaffolding::unpackResourcesAndNamedBuiltIns() > auto iterator = m_resourceMap.find(&m_layout[i].bindings[j]); > if (iterator == m_resourceMap.end()) > continue; >- if (m_namedBindGroups[i].namedBindings[j].lengthInformation) { >- auto& path = m_entryPointItems.inputs[iterator->value].path; >- auto elementName = m_namedBindGroups[i].namedBindings[j].elementName; >- auto lengthElementName = m_namedBindGroups[i].namedBindings[j].lengthInformation->elementName; >- auto lengthTemporaryName = m_namedBindGroups[i].namedBindings[j].lengthInformation->temporaryName; >- >- auto& unnamedType = *m_entryPointItems.inputs[iterator->value].unnamedType; >- ASSERT(is<AST::ReferenceType>(unnamedType)); >- auto& referenceType = downcast<AST::ReferenceType>(unnamedType); >- auto mangledTypeName = m_typeNamer.mangledNameForType(referenceType.elementType()); >- >- stringBuilder.append(makeString("size_t ", lengthTemporaryName, " = ", variableName, '.', lengthElementName, ".x;\n")); >- stringBuilder.append(makeString(lengthTemporaryName, " = ", lengthTemporaryName, " << 32;\n")); >- stringBuilder.append(makeString(lengthTemporaryName, " = ", lengthTemporaryName, " | ", variableName, '.', lengthElementName, ".y;\n")); >- stringBuilder.append(makeString(lengthTemporaryName, " = ", lengthTemporaryName, " / sizeof(", mangledTypeName, ");\n")); >- stringBuilder.append(makeString("if (", lengthTemporaryName, " > 0xFFFFFFFF) ", lengthTemporaryName, " = 0xFFFFFFFF;\n")); >- stringBuilder.append(makeString(mangledInputPath(path), " = { ", variableName, '.', elementName, ", static_cast<uint32_t>(", lengthTemporaryName, ") };\n")); >- } else { >- auto& path = m_entryPointItems.inputs[iterator->value].path; >- auto elementName = m_namedBindGroups[i].namedBindings[j].elementName; >- stringBuilder.append(makeString(mangledInputPath(path), " = ", variableName, '.', elementName, ";\n")); >- } >+ auto& path = m_entryPointItems.inputs[iterator->value].path; >+ auto elementName = m_namedBindGroups[i].namedBindings[j].elementName; >+ stringBuilder.append(makeString(mangledInputPath(path), " = ", variableName, '.', elementName, ";\n")); > } > } > >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLEntryPointScaffolding.h b/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLEntryPointScaffolding.h >index 664f7fb4a23..2467e86ff86 100644 >--- a/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLEntryPointScaffolding.h >+++ b/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLEntryPointScaffolding.h >@@ -77,15 +77,9 @@ protected: > Layout& m_layout; > std::function<String()> m_generateNextVariableName; > >- struct LengthInformation { >- String elementName; >- String temporaryName; >- unsigned index; >- }; > struct NamedBinding { > String elementName; > unsigned index; >- Optional<LengthInformation> lengthInformation; > }; > struct NamedBindGroup { > String structName; >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLChecker.cpp b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLChecker.cpp >index 5fb76c90aee..d9c37ce27bb 100644 >--- a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLChecker.cpp >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLChecker.cpp >@@ -117,29 +117,29 @@ public: > } > }; > >-static AST::NativeFunctionDeclaration resolveWithOperatorAnderIndexer(Lexer::Token origin, AST::ArrayReferenceType& firstArgument, const Intrinsics& intrinsics) >+static AST::NativeFunctionDeclaration resolveWithOperatorAnderIndexer(AST::CallExpression& callExpression, AST::ArrayReferenceType& firstArgument, const Intrinsics& intrinsics) > { > const bool isOperator = true; >- auto returnType = makeUniqueRef<AST::PointerType>(Lexer::Token(origin), firstArgument.addressSpace(), firstArgument.elementType().clone()); >+ auto returnType = makeUniqueRef<AST::PointerType>(Lexer::Token(callExpression.origin()), firstArgument.addressSpace(), firstArgument.elementType().clone()); > AST::VariableDeclarations parameters; >- parameters.append(makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(origin), AST::Qualifiers(), firstArgument.clone(), String(), WTF::nullopt, WTF::nullopt)); >- parameters.append(makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(origin), AST::Qualifiers(), UniqueRef<AST::UnnamedType>(AST::TypeReference::wrap(Lexer::Token(origin), intrinsics.uintType())), String(), WTF::nullopt, WTF::nullopt)); >- return AST::NativeFunctionDeclaration(AST::FunctionDeclaration(Lexer::Token(origin), AST::AttributeBlock(), WTF::nullopt, WTFMove(returnType), String("operator&[]", String::ConstructFromLiteral), WTFMove(parameters), WTF::nullopt, isOperator)); >+ parameters.append(makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(callExpression.origin()), AST::Qualifiers(), firstArgument.clone(), String(), WTF::nullopt, WTF::nullopt)); >+ parameters.append(makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(callExpression.origin()), AST::Qualifiers(), UniqueRef<AST::UnnamedType>(AST::TypeReference::wrap(Lexer::Token(callExpression.origin()), intrinsics.uintType())), String(), WTF::nullopt, WTF::nullopt)); >+ return AST::NativeFunctionDeclaration(AST::FunctionDeclaration(Lexer::Token(callExpression.origin()), AST::AttributeBlock(), WTF::nullopt, WTFMove(returnType), String("operator&[]", String::ConstructFromLiteral), WTFMove(parameters), WTF::nullopt, isOperator)); > } > >-static AST::NativeFunctionDeclaration resolveWithOperatorLength(Lexer::Token origin, AST::UnnamedType& firstArgument, const Intrinsics& intrinsics) >+static AST::NativeFunctionDeclaration resolveWithOperatorLength(AST::CallExpression& callExpression, AST::UnnamedType& firstArgument, const Intrinsics& intrinsics) > { > const bool isOperator = true; >- auto returnType = AST::TypeReference::wrap(Lexer::Token(origin), intrinsics.uintType()); >+ auto returnType = AST::TypeReference::wrap(Lexer::Token(callExpression.origin()), intrinsics.uintType()); > AST::VariableDeclarations parameters; >- parameters.append(makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(origin), AST::Qualifiers(), firstArgument.clone(), String(), WTF::nullopt, WTF::nullopt)); >- return AST::NativeFunctionDeclaration(AST::FunctionDeclaration(Lexer::Token(origin), AST::AttributeBlock(), WTF::nullopt, WTFMove(returnType), String("operator.length", String::ConstructFromLiteral), WTFMove(parameters), WTF::nullopt, isOperator)); >+ parameters.append(makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(callExpression.origin()), AST::Qualifiers(), firstArgument.clone(), String(), WTF::nullopt, WTF::nullopt)); >+ return AST::NativeFunctionDeclaration(AST::FunctionDeclaration(Lexer::Token(callExpression.origin()), AST::AttributeBlock(), WTF::nullopt, WTFMove(returnType), String("operator.length", String::ConstructFromLiteral), WTFMove(parameters), WTF::nullopt, isOperator)); > } > >-static AST::NativeFunctionDeclaration resolveWithReferenceComparator(Lexer::Token origin, ResolvingType& firstArgument, ResolvingType& secondArgument, const Intrinsics& intrinsics) >+static AST::NativeFunctionDeclaration resolveWithReferenceComparator(AST::CallExpression& callExpression, ResolvingType& firstArgument, ResolvingType& secondArgument, const Intrinsics& intrinsics) > { > const bool isOperator = true; >- auto returnType = AST::TypeReference::wrap(Lexer::Token(origin), intrinsics.boolType()); >+ auto returnType = AST::TypeReference::wrap(Lexer::Token(callExpression.origin()), intrinsics.boolType()); > auto argumentType = firstArgument.visit(WTF::makeVisitor([](UniqueRef<AST::UnnamedType>& unnamedType) -> UniqueRef<AST::UnnamedType> { > return unnamedType->clone(); > }, [&](RefPtr<ResolvableTypeReference>&) -> UniqueRef<AST::UnnamedType> { >@@ -149,13 +149,13 @@ static AST::NativeFunctionDeclaration resolveWithReferenceComparator(Lexer::Toke > // We encountered "null == null". > // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198162 This can probably be generalized, using the "preferred type" infrastructure used by generic literals > ASSERT_NOT_REACHED(); >- return AST::TypeReference::wrap(Lexer::Token(origin), intrinsics.intType()); >+ return AST::TypeReference::wrap(Lexer::Token(callExpression.origin()), intrinsics.intType()); > })); > })); > AST::VariableDeclarations parameters; >- parameters.append(makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(origin), AST::Qualifiers(), argumentType->clone(), String(), WTF::nullopt, WTF::nullopt)); >- parameters.append(makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(origin), AST::Qualifiers(), UniqueRef<AST::UnnamedType>(WTFMove(argumentType)), String(), WTF::nullopt, WTF::nullopt)); >- return AST::NativeFunctionDeclaration(AST::FunctionDeclaration(Lexer::Token(origin), AST::AttributeBlock(), WTF::nullopt, WTFMove(returnType), String("operator==", String::ConstructFromLiteral), WTFMove(parameters), WTF::nullopt, isOperator)); >+ parameters.append(makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(callExpression.origin()), AST::Qualifiers(), argumentType->clone(), String(), WTF::nullopt, WTF::nullopt)); >+ parameters.append(makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(callExpression.origin()), AST::Qualifiers(), UniqueRef<AST::UnnamedType>(WTFMove(argumentType)), String(), WTF::nullopt, WTF::nullopt)); >+ return AST::NativeFunctionDeclaration(AST::FunctionDeclaration(Lexer::Token(callExpression.origin()), AST::AttributeBlock(), WTF::nullopt, WTFMove(returnType), String("operator==", String::ConstructFromLiteral), WTFMove(parameters), WTF::nullopt, isOperator)); > } > > enum class Acceptability { >@@ -164,9 +164,9 @@ enum class Acceptability { > No > }; > >-static Optional<AST::NativeFunctionDeclaration> resolveByInstantiation(const String& name, Lexer::Token origin, const Vector<std::reference_wrapper<ResolvingType>>& types, const Intrinsics& intrinsics) >+static Optional<AST::NativeFunctionDeclaration> resolveByInstantiation(AST::CallExpression& callExpression, const Vector<std::reference_wrapper<ResolvingType>>& types, const Intrinsics& intrinsics) > { >- if (name == "operator&[]" && types.size() == 2) { >+ if (callExpression.name() == "operator&[]" && types.size() == 2) { > auto* firstArgumentArrayRef = types[0].get().visit(WTF::makeVisitor([](UniqueRef<AST::UnnamedType>& unnamedType) -> AST::ArrayReferenceType* { > if (is<AST::ArrayReferenceType>(static_cast<AST::UnnamedType&>(unnamedType))) > return &downcast<AST::ArrayReferenceType>(static_cast<AST::UnnamedType&>(unnamedType)); >@@ -180,8 +180,8 @@ static Optional<AST::NativeFunctionDeclaration> resolveByInstantiation(const Str > return resolvableTypeReference->resolvableType().canResolve(intrinsics.uintType()); > })); > if (firstArgumentArrayRef && secondArgumentIsUint) >- return resolveWithOperatorAnderIndexer(origin, *firstArgumentArrayRef, intrinsics); >- } else if (name == "operator.length" && types.size() == 1) { >+ return resolveWithOperatorAnderIndexer(callExpression, *firstArgumentArrayRef, intrinsics); >+ } else if (callExpression.name() == "operator.length" && types.size() == 1) { > auto* firstArgumentReference = types[0].get().visit(WTF::makeVisitor([](UniqueRef<AST::UnnamedType>& unnamedType) -> AST::UnnamedType* { > if (is<AST::ArrayReferenceType>(static_cast<AST::UnnamedType&>(unnamedType))) > return &unnamedType; >@@ -190,8 +190,8 @@ static Optional<AST::NativeFunctionDeclaration> resolveByInstantiation(const Str > return nullptr; > })); > if (firstArgumentReference) >- return resolveWithOperatorLength(origin, *firstArgumentReference, intrinsics); >- } else if (name == "operator==" && types.size() == 2) { >+ return resolveWithOperatorLength(callExpression, *firstArgumentReference, intrinsics); >+ } else if (callExpression.name() == "operator==" && types.size() == 2) { > auto acceptability = [](ResolvingType& resolvingType) -> Acceptability { > return resolvingType.visit(WTF::makeVisitor([](UniqueRef<AST::UnnamedType>& unnamedType) -> Acceptability { > return is<AST::ReferenceType>(static_cast<AST::UnnamedType&>(unnamedType)) ? Acceptability::Yes : Acceptability::No; >@@ -210,7 +210,7 @@ static Optional<AST::NativeFunctionDeclaration> resolveByInstantiation(const Str > || (leftAcceptability == Acceptability::Yes && rightAcceptability == Acceptability::Maybe)) > success = true; > if (success) >- return resolveWithReferenceComparator(origin, types[0].get(), types[1].get(), intrinsics); >+ return resolveWithReferenceComparator(callExpression, types[0].get(), types[1].get(), intrinsics); > } > return WTF::nullopt; > } >@@ -969,29 +969,6 @@ void Checker::visit(AST::MakeArrayReferenceExpression& makeArrayReferenceExpress > assignType(makeArrayReferenceExpression, makeUniqueRef<AST::ArrayReferenceType>(Lexer::Token(makeArrayReferenceExpression.origin()), *leftAddressSpace, leftValueType->clone())); > } > >-static Optional<UniqueRef<AST::UnnamedType>> argumentTypeForAndOverload(AST::UnnamedType& baseType, AST::AddressSpace addressSpace) >-{ >- auto& unifyNode = baseType.unifyNode(); >- if (is<AST::NamedType>(unifyNode)) { >- auto& namedType = downcast<AST::NamedType>(unifyNode); >- return { makeUniqueRef<AST::PointerType>(Lexer::Token(namedType.origin()), addressSpace, AST::TypeReference::wrap(Lexer::Token(namedType.origin()), namedType)) }; >- } >- >- ASSERT(is<AST::UnnamedType>(unifyNode)); >- auto& unnamedType = downcast<AST::UnnamedType>(unifyNode); >- >- if (is<AST::ArrayReferenceType>(unnamedType)) >- return unnamedType.clone(); >- >- if (is<AST::ArrayType>(unnamedType)) >- return { makeUniqueRef<AST::ArrayReferenceType>(Lexer::Token(unnamedType.origin()), addressSpace, downcast<AST::ArrayType>(unnamedType).type().clone()) }; >- >- if (is<AST::PointerType>(unnamedType)) >- return WTF::nullopt; >- >- return { makeUniqueRef<AST::PointerType>(Lexer::Token(unnamedType.origin()), addressSpace, unnamedType.clone()) }; >-} >- > void Checker::finishVisiting(AST::PropertyAccessExpression& propertyAccessExpression, ResolvingType* additionalArgumentType) > { > auto baseInfo = recurseAndGetInfo(propertyAccessExpression.base()); >@@ -1015,35 +992,23 @@ void Checker::finishVisiting(AST::PropertyAccessExpression& propertyAccessExpres > AST::UnnamedType* anderReturnType = nullptr; > auto leftAddressSpace = baseInfo->typeAnnotation.leftAddressSpace(); > if (leftAddressSpace) { >- if (auto argumentTypeForAndOverload = WHLSL::argumentTypeForAndOverload(*baseUnnamedType, *leftAddressSpace)) { >- ResolvingType argumentType = { WTFMove(*argumentTypeForAndOverload) }; >- Vector<std::reference_wrapper<ResolvingType>> anderArgumentTypes { argumentType }; >- if (additionalArgumentType) >- anderArgumentTypes.append(*additionalArgumentType); >- if ((anderFunction = resolveFunctionOverloadImpl(propertyAccessExpression.possibleAnderOverloads(), anderArgumentTypes, nullptr))) >- anderReturnType = &downcast<AST::PointerType>(anderFunction->type()).elementType(); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198164 Enforce the return of anders will always be a pointer >- else if (auto newFunction = resolveByInstantiation(propertyAccessExpression.anderFunctionName(), propertyAccessExpression.origin(), anderArgumentTypes, m_intrinsics)) { >- m_program.append(WTFMove(*newFunction)); >- anderFunction = &m_program.nativeFunctionDeclarations().last(); >- anderReturnType = &downcast<AST::PointerType>(anderFunction->type()).elementType(); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198164 Enforce the return of anders will always be a pointer >- } >- } >+ ResolvingType argumentType = { makeUniqueRef<AST::PointerType>(Lexer::Token(propertyAccessExpression.origin()), *leftAddressSpace, baseUnnamedType->get().clone()) }; >+ Vector<std::reference_wrapper<ResolvingType>> anderArgumentTypes { argumentType }; >+ if (additionalArgumentType) >+ anderArgumentTypes.append(*additionalArgumentType); >+ if ((anderFunction = resolveFunctionOverloadImpl(propertyAccessExpression.possibleAnderOverloads(), anderArgumentTypes, nullptr))) >+ anderReturnType = &downcast<AST::PointerType>(anderFunction->type()).elementType(); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198164 Enforce the return of anders will always be a pointer > } > > AST::FunctionDeclaration* threadAnderFunction = nullptr; > AST::UnnamedType* threadAnderReturnType = nullptr; >- if (auto argumentTypeForAndOverload = WHLSL::argumentTypeForAndOverload(*baseUnnamedType, AST::AddressSpace::Thread)) { >+ { > ResolvingType argumentType = { makeUniqueRef<AST::PointerType>(Lexer::Token(propertyAccessExpression.origin()), AST::AddressSpace::Thread, baseUnnamedType->get().clone()) }; > Vector<std::reference_wrapper<ResolvingType>> threadAnderArgumentTypes { argumentType }; > if (additionalArgumentType) > threadAnderArgumentTypes.append(*additionalArgumentType); > if ((threadAnderFunction = resolveFunctionOverloadImpl(propertyAccessExpression.possibleAnderOverloads(), threadAnderArgumentTypes, nullptr))) > threadAnderReturnType = &downcast<AST::PointerType>(threadAnderFunction->type()).elementType(); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198164 Enforce the return of anders will always be a pointer >- else if (auto newFunction = resolveByInstantiation(propertyAccessExpression.anderFunctionName(), propertyAccessExpression.origin(), threadAnderArgumentTypes, m_intrinsics)) { >- m_program.append(WTFMove(*newFunction)); >- threadAnderFunction = &m_program.nativeFunctionDeclarations().last(); >- threadAnderReturnType = &downcast<AST::PointerType>(anderFunction->type()).elementType(); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198164 Enforce the return of anders will always be a pointer >- } > } > > if (leftAddressSpace && !anderFunction && !getterFunction) { >@@ -1469,7 +1434,7 @@ void Checker::visit(AST::CallExpression& callExpression) > ASSERT(callExpression.hasOverloads()); > auto* function = resolveFunctionOverloadImpl(*callExpression.overloads(), types, callExpression.castReturnType()); > if (!function) { >- if (auto newFunction = resolveByInstantiation(callExpression.name(), callExpression.origin(), types, m_intrinsics)) { >+ if (auto newFunction = resolveByInstantiation(callExpression, types, m_intrinsics)) { > m_program.append(WTFMove(*newFunction)); > function = &m_program.nativeFunctionDeclarations().last(); > } >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPipelineDescriptor.h b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPipelineDescriptor.h >index 5b37e3fb35a..f8f1745d3f2 100644 >--- a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPipelineDescriptor.h >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPipelineDescriptor.h >@@ -114,28 +114,18 @@ enum class ShaderStage : uint8_t { > Compute = 1 << 2 > }; > >-struct UniformBufferBinding { >- unsigned lengthName; >+enum class BindingType : uint8_t { >+ UniformBuffer, >+ Sampler, >+ Texture, >+ StorageBuffer, >+ // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198168 Add the dynamic types > }; > >-struct SamplerBinding { >-}; >- >-struct TextureBinding { >-}; >- >-struct StorageBufferBinding { >- unsigned lengthName; >-}; >- >-// FIXME: https://bugs.webkit.org/show_bug.cgi?id=198168 Add the dynamic types >- > struct Binding { >- using BindingDetails = Variant<UniformBufferBinding, SamplerBinding, TextureBinding, StorageBufferBinding>; > OptionSet<ShaderStage> visibility; >- BindingDetails binding; >- unsigned internalName; >- unsigned externalName; >+ BindingType bindingType; >+ unsigned name; > }; > > struct BindGroup { >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPrepare.cpp b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPrepare.cpp >index 0373acb645b..e3535a4c4d5 100644 >--- a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPrepare.cpp >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPrepare.cpp >@@ -55,7 +55,7 @@ namespace WebCore { > > namespace WHLSL { > >-static constexpr bool dumpASTBeforeEachPass = true; >+static constexpr bool dumpASTBeforeEachPass = false; > static constexpr bool dumpASTAfterParsing = false; > static constexpr bool dumpASTAtEnd = true; > static constexpr bool alwaysDumpPassFailures = false; >@@ -124,9 +124,7 @@ static Optional<Program> prepareShared(String& whlslSource) > RUN_PASS(check, program); > > checkLiteralTypes(program); >- dumpASTBetweenEachPassIfNeeded(program, "AST before resolveProperties"); > resolveProperties(program); >- dumpASTBetweenEachPassIfNeeded(program, "AST after resolveProperties"); > findHighZombies(program); > RUN_PASS(checkStatementBehavior, program); > RUN_PASS(checkRecursion, program); >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp >index af4c6db26b7..fd55934ac71 100644 >--- a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp >@@ -35,7 +35,6 @@ > #include "WHLSLDotExpression.h" > #include "WHLSLFunctionDeclaration.h" > #include "WHLSLFunctionDefinition.h" >-#include "WHLSLMakeArrayReferenceExpression.h" > #include "WHLSLMakePointerExpression.h" > #include "WHLSLPointerType.h" > #include "WHLSLReadModifyWriteExpression.h" >@@ -56,7 +55,7 @@ private: > void visit(AST::AssignmentExpression&) override; > void visit(AST::ReadModifyWriteExpression&) override; > >- void simplifyRightValue(AST::PropertyAccessExpression&); >+ bool simplifyRightValue(AST::PropertyAccessExpression&); > bool simplifyAbstractLeftValue(AST::AssignmentExpression&, AST::DotExpression&, UniqueRef<AST::Expression>&& right); > void simplifyLeftValue(AST::Expression&); > >@@ -66,14 +65,16 @@ private: > void PropertyResolver::visit(AST::DotExpression& dotExpression) > { > // Unless we're inside an AssignmentExpression or a ReadModifyWriteExpression, we're a right value. >- simplifyRightValue(dotExpression); >+ if (!simplifyRightValue(dotExpression)) >+ setError(); > } > > void PropertyResolver::visit(AST::IndexExpression& indexExpression) > { > checkErrorAndVisit(indexExpression.indexExpression()); > // Unless we're inside an AssignmentExpression or a ReadModifyWriteExpression, we're a right value. >- simplifyRightValue(indexExpression); >+ if (!simplifyRightValue(indexExpression)) >+ setError(); > } > > void PropertyResolver::visit(AST::FunctionDefinition& functionDefinition) >@@ -83,88 +84,12 @@ void PropertyResolver::visit(AST::FunctionDefinition& functionDefinition) > functionDefinition.block().statements().insert(0, makeUniqueRef<AST::VariableDeclarationsStatement>(Lexer::Token(m_variableDeclarations[0]->origin()), WTFMove(m_variableDeclarations))); > } > >-enum class WhichAnder { >- ThreadAnder, >- NonThreadAnder >-}; >- >-struct AnderCallArgumentResult { >- UniqueRef<AST::Expression> expression; >- Optional<UniqueRef<AST::VariableDeclaration>> variableDeclaration; >- WhichAnder whichAnder; >-}; >- >-template <typename ExpressionConstructor, typename TypeConstructor> >-static Optional<AnderCallArgumentResult> wrapAnderCallArgument(UniqueRef<AST::Expression>& expression, bool anderFunction, bool threadAnderFunction) >-{ >- if (auto addressSpace = expression->typeAnnotation().leftAddressSpace()) { >- if (!anderFunction) >- return WTF::nullopt; >- auto origin = expression->origin(); >- auto baseType = expression->resolvedType().clone(); >- auto makeArrayReference = makeUniqueRef<ExpressionConstructor>(Lexer::Token(origin), WTFMove(expression)); >- makeArrayReference->setType(makeUniqueRef<TypeConstructor>(WTFMove(origin), *addressSpace, WTFMove(baseType))); >- makeArrayReference->setTypeAnnotation(AST::RightValue()); >- return {{ WTFMove(makeArrayReference), WTF::nullopt, WhichAnder::NonThreadAnder }}; >- } >- if (threadAnderFunction) { >- auto origin = expression->origin(); >- auto baseType = expression->resolvedType().clone(); >- auto variableDeclaration = makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(origin), AST::Qualifiers(), baseType->clone(), String(), WTF::nullopt, WTF::nullopt); >- >- auto variableReference1 = makeUniqueRef<AST::VariableReference>(AST::VariableReference::wrap(variableDeclaration)); >- variableReference1->setType(baseType->clone()); >- variableReference1->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); >- >- auto assignmentExpression = makeUniqueRef<AST::AssignmentExpression>(Lexer::Token(origin), WTFMove(variableReference1), WTFMove(expression)); >- assignmentExpression->setType(baseType->clone()); >- assignmentExpression->setTypeAnnotation(AST::RightValue()); >- >- auto variableReference2 = makeUniqueRef<AST::VariableReference>(AST::VariableReference::wrap(variableDeclaration)); >- variableReference2->setType(baseType->clone()); >- variableReference2->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); >- >- auto expression = makeUniqueRef<ExpressionConstructor>(Lexer::Token(origin), WTFMove(variableReference2)); >- auto resultType = makeUniqueRef<TypeConstructor>(Lexer::Token(origin), AST::AddressSpace::Thread, WTFMove(baseType)); >- expression->setType(resultType->clone()); >- expression->setTypeAnnotation(AST::RightValue()); >- >- Vector<UniqueRef<AST::Expression>> expressions; >- expressions.append(WTFMove(assignmentExpression)); >- expressions.append(WTFMove(expression)); >- auto commaExpression = makeUniqueRef<AST::CommaExpression>(WTFMove(origin), WTFMove(expressions)); >- commaExpression->setType(WTFMove(resultType)); >- commaExpression->setTypeAnnotation(AST::RightValue()); >- return {{ WTFMove(commaExpression), { WTFMove(variableDeclaration) }, WhichAnder::ThreadAnder}}; >- } >- return WTF::nullopt; >-} >- >-static Optional<AnderCallArgumentResult> anderCallArgument(UniqueRef<AST::Expression>& expression, bool anderFunction, bool threadAnderFunction) >-{ >- auto& unifyNode = expression->resolvedType().unifyNode(); >- if (is<AST::UnnamedType>(unifyNode)) { >- auto& unnamedType = downcast<AST::UnnamedType>(unifyNode); >- ASSERT(!is<AST::PointerType>(unnamedType)); >- if (is<AST::ArrayReferenceType>(unnamedType)) >- return {{ WTFMove(expression), WTF::nullopt, WhichAnder::NonThreadAnder }}; >- if (is<AST::ArrayType>(unnamedType)) >- return wrapAnderCallArgument<AST::MakeArrayReferenceExpression, AST::ArrayReferenceType>(expression, anderFunction, threadAnderFunction); >- } >- return wrapAnderCallArgument<AST::MakePointerExpression, AST::PointerType>(expression, anderFunction, threadAnderFunction); >-} >- >-static Optional<UniqueRef<AST::Expression>> setterCall(AST::PropertyAccessExpression& propertyAccessExpression, AST::FunctionDeclaration* relevantAnder, UniqueRef<AST::Expression>&& newValue, const std::function<UniqueRef<AST::Expression>()>& leftValueFactory, AST::VariableDeclaration* indexVariable) >+static Optional<UniqueRef<AST::Expression>> setterCall(AST::PropertyAccessExpression& propertyAccessExpression, AST::FunctionDeclaration* relevantAnder, UniqueRef<AST::Expression>&& newValue, const std::function<UniqueRef<AST::Expression>()>& leftValueFactory, const std::function<UniqueRef<AST::Expression>()>& pointerToLeftValueFactory, AST::VariableDeclaration* indexVariable) > { > if (relevantAnder) { > // *operator&.foo(&v) = newValue >- auto leftValue = leftValueFactory(); >- auto argument = anderCallArgument(leftValue, true, true); >- ASSERT(argument); >- ASSERT(!argument->variableDeclaration); >- ASSERT(argument->whichAnder == WhichAnder::NonThreadAnder); > Vector<UniqueRef<AST::Expression>> arguments; >- arguments.append(WTFMove(argument->expression)); >+ arguments.append(pointerToLeftValueFactory()); > if (indexVariable) { > auto variableReference = makeUniqueRef<AST::VariableReference>(AST::VariableReference::wrap(*indexVariable)); > ASSERT(indexVariable->type()); >@@ -215,17 +140,12 @@ static Optional<UniqueRef<AST::Expression>> setterCall(AST::PropertyAccessExpres > return UniqueRef<AST::Expression>(WTFMove(assignmentExpression)); > } > >-static Optional<UniqueRef<AST::Expression>> getterCall(AST::PropertyAccessExpression& propertyAccessExpression, AST::FunctionDeclaration* relevantAnder, const std::function<UniqueRef<AST::Expression>()>& leftValueFactory, AST::VariableDeclaration* indexVariable) >+static Optional<UniqueRef<AST::Expression>> getterCall(AST::PropertyAccessExpression& propertyAccessExpression, AST::FunctionDeclaration* relevantAnder, const std::function<UniqueRef<AST::Expression>()>& leftValueFactory, const std::function<UniqueRef<AST::Expression>()>& pointerToLeftValueFactory, AST::VariableDeclaration* indexVariable) > { > if (relevantAnder) { > // *operator&.foo(&v) >- auto leftValue = leftValueFactory(); >- auto argument = anderCallArgument(leftValue, true, true); >- ASSERT(argument); >- ASSERT(!argument->variableDeclaration); >- ASSERT(argument->whichAnder == WhichAnder::NonThreadAnder); > Vector<UniqueRef<AST::Expression>> arguments; >- arguments.append(WTFMove(argument->expression)); >+ arguments.append(pointerToLeftValueFactory()); > if (indexVariable) { > auto variableReference = makeUniqueRef<AST::VariableReference>(AST::VariableReference::wrap(*indexVariable)); > ASSERT(indexVariable->type()); >@@ -248,7 +168,7 @@ static Optional<UniqueRef<AST::Expression>> getterCall(AST::PropertyAccessExpres > > // operator.foo(v) > ASSERT(propertyAccessExpression.getterFunction()); >- >+ > Vector<UniqueRef<AST::Expression>> arguments; > arguments.append(leftValueFactory()); > if (indexVariable) { >@@ -378,7 +298,7 @@ static Optional<ModifyResult> modify(AST::PropertyAccessExpression& propertyAcce > variableReference->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198169 Is this right? > return variableReference; > } >- >+ > auto variableReference = makeUniqueRef<AST::VariableReference>(AST::VariableReference::wrap(pointerVariable)); > ASSERT(pointerVariable->type()); > variableReference->setType(pointerVariable->type()->clone()); >@@ -390,6 +310,26 @@ static Optional<ModifyResult> modify(AST::PropertyAccessExpression& propertyAcce > dereferenceExpression->setTypeAnnotation(AST::LeftValue { downcast<AST::PointerType>(*pointerVariable->type()).addressSpace() }); > return dereferenceExpression; > }; >+ auto pointerToPreviousLeftValue = [&]() -> UniqueRef<AST::Expression> { >+ if (previous) { >+ auto variableReference = makeUniqueRef<AST::VariableReference>(AST::VariableReference::wrap(*previous)); >+ ASSERT(previous->type()); >+ variableReference->setType(previous->type()->clone()); >+ variableReference->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198169 Is this right? >+ >+ auto makePointerExpression = makeUniqueRef<AST::MakePointerExpression>(Lexer::Token(propertyAccessExpression.origin()), WTFMove(variableReference)); >+ ASSERT(previous->type()); >+ makePointerExpression->setType(makeUniqueRef<AST::PointerType>(Lexer::Token(propertyAccessExpression.origin()), AST::AddressSpace::Thread, previous->type()->clone())); >+ makePointerExpression->setTypeAnnotation(AST::RightValue()); >+ return makePointerExpression; >+ } >+ >+ auto variableReference = makeUniqueRef<AST::VariableReference>(AST::VariableReference::wrap(pointerVariable)); >+ ASSERT(pointerVariable->type()); >+ variableReference->setType(pointerVariable->type()->clone()); >+ variableReference->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198169 Is this right? >+ return variableReference; >+ }; > auto appendIndexAssignment = [&](AST::PropertyAccessExpression& propertyAccessExpression, Optional<UniqueRef<AST::VariableDeclaration>>& indexVariable) { > if (!indexVariable) > return; >@@ -415,7 +355,7 @@ static Optional<ModifyResult> modify(AST::PropertyAccessExpression& propertyAcce > appendIndexAssignment(propertyAccessExpression, indexVariable); > > AST::FunctionDeclaration* relevantAnder = i == chain.size() - 1 ? propertyAccessExpression.anderFunction() : propertyAccessExpression.threadAnderFunction(); >- auto callExpression = getterCall(propertyAccessExpression, relevantAnder, previousLeftValue, indexVariable ? &*indexVariable : nullptr); >+ auto callExpression = getterCall(propertyAccessExpression, relevantAnder, previousLeftValue, pointerToPreviousLeftValue, indexVariable ? &*indexVariable : nullptr); > > if (!callExpression) > return WTF::nullopt; >@@ -430,12 +370,12 @@ static Optional<ModifyResult> modify(AST::PropertyAccessExpression& propertyAcce > assignmentExpression->setTypeAnnotation(AST::RightValue()); > > expressions.append(WTFMove(assignmentExpression)); >- >+ > previous = &variableDeclaration; > } > appendIndexAssignment(chain[0], indexVariables[0]); > AST::FunctionDeclaration* relevantAnder = chain.size() == 1 ? propertyAccessExpression.anderFunction() : propertyAccessExpression.threadAnderFunction(); >- auto lastGetterCallExpression = getterCall(chain[0], relevantAnder, previousLeftValue, indexVariables[0] ? &*(indexVariables[0]) : nullptr); >+ auto lastGetterCallExpression = getterCall(chain[0], relevantAnder, previousLeftValue, pointerToPreviousLeftValue, indexVariables[0] ? &*(indexVariables[0]) : nullptr); > > // Step 3: > auto modificationResult = modification(WTFMove(lastGetterCallExpression)); >@@ -458,6 +398,17 @@ static Optional<ModifyResult> modify(AST::PropertyAccessExpression& propertyAcce > variableReference->setType(variableDeclaration.type()->clone()); > variableReference->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198169 Is this right? > return variableReference; >+ }, [&]() -> UniqueRef<AST::Expression> { >+ auto variableReference = makeUniqueRef<AST::VariableReference>(AST::VariableReference::wrap(variableDeclaration)); >+ ASSERT(variableDeclaration.type()); >+ variableReference->setType(variableDeclaration.type()->clone()); >+ variableReference->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198169 Is this right? >+ >+ auto makePointerExpression = makeUniqueRef<AST::MakePointerExpression>(Lexer::Token(propertyAccessExpression.origin()), WTFMove(variableReference)); >+ ASSERT(variableDeclaration.type()); >+ makePointerExpression->setType(makeUniqueRef<AST::PointerType>(Lexer::Token(propertyAccessExpression.origin()), AST::AddressSpace::Thread, variableDeclaration.type()->clone())); >+ makePointerExpression->setTypeAnnotation(AST::RightValue()); >+ return makePointerExpression; > }, indexVariable ? &*indexVariable : nullptr); > > if (!assignmentExpression) >@@ -485,6 +436,12 @@ static Optional<ModifyResult> modify(AST::PropertyAccessExpression& propertyAcce > dereferenceExpression->setType(downcast<AST::PointerType>(*pointerVariable->type()).elementType().clone()); > dereferenceExpression->setTypeAnnotation(AST::LeftValue { downcast<AST::PointerType>(*pointerVariable->type()).addressSpace() }); > return dereferenceExpression; >+ }, [&]() -> UniqueRef<AST::Expression> { >+ auto variableReference = makeUniqueRef<AST::VariableReference>(AST::VariableReference::wrap(pointerVariable)); >+ ASSERT(pointerVariable->type()); >+ variableReference->setType(pointerVariable->type()->clone()); >+ variableReference->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198169 Is this right? >+ return variableReference; > }, indexVariables[indexVariables.size() - 1] ? &*(indexVariables[indexVariables.size() - 1]) : nullptr); > > if (!assignmentExpression) >@@ -708,50 +665,94 @@ void PropertyResolver::visit(AST::ReadModifyWriteExpression& readModifyWriteExpr > m_variableDeclarations.append(WTFMove(newVariableDeclaration)); > } > >-static Optional<AnderCallArgumentResult> anderCallArgument(AST::PropertyAccessExpression& propertyAccessExpression) >-{ >- return anderCallArgument(propertyAccessExpression.baseReference(), propertyAccessExpression.anderFunction(), propertyAccessExpression.threadAnderFunction()); >-} >- >-void PropertyResolver::simplifyRightValue(AST::PropertyAccessExpression& propertyAccessExpression) >+bool PropertyResolver::simplifyRightValue(AST::PropertyAccessExpression& propertyAccessExpression) > { > Lexer::Token origin = propertyAccessExpression.origin(); > > checkErrorAndVisit(propertyAccessExpression.base()); > >- if (auto argument = anderCallArgument(propertyAccessExpression)) { >- auto* anderFunction = argument->whichAnder == WhichAnder::ThreadAnder ? propertyAccessExpression.threadAnderFunction() : propertyAccessExpression.anderFunction(); >- ASSERT(anderFunction); >- auto origin = propertyAccessExpression.origin(); >+ auto& base = propertyAccessExpression.base(); >+ if (auto leftAddressSpace = base.typeAnnotation().leftAddressSpace()) { >+ if (auto* anderFunction = propertyAccessExpression.anderFunction()) { >+ auto makePointerExpression = makeUniqueRef<AST::MakePointerExpression>(Lexer::Token(origin), propertyAccessExpression.takeBase()); >+ makePointerExpression->setType(makeUniqueRef<AST::PointerType>(Lexer::Token(origin), *leftAddressSpace, base.resolvedType().clone())); >+ makePointerExpression->setTypeAnnotation(AST::RightValue()); >+ >+ Vector<UniqueRef<AST::Expression>> arguments; >+ arguments.append(WTFMove(makePointerExpression)); >+ if (is<AST::IndexExpression>(propertyAccessExpression)) >+ arguments.append(downcast<AST::IndexExpression>(propertyAccessExpression).takeIndex()); >+ auto callExpression = makeUniqueRef<AST::CallExpression>(Lexer::Token(origin), String(anderFunction->name()), WTFMove(arguments)); >+ callExpression->setType(anderFunction->type().clone()); >+ callExpression->setTypeAnnotation(AST::RightValue()); >+ callExpression->setFunction(*anderFunction); >+ >+ auto* dereferenceExpression = AST::replaceWith<AST::DereferenceExpression>(propertyAccessExpression, WTFMove(origin), WTFMove(callExpression)); >+ dereferenceExpression->setType(downcast<AST::PointerType>(anderFunction->type()).elementType().clone()); >+ dereferenceExpression->setTypeAnnotation(AST::LeftValue { downcast<AST::PointerType>(anderFunction->type()).addressSpace() }); >+ return true; >+ } >+ } >+ >+ if (propertyAccessExpression.getterFunction()) { >+ auto& getterFunction = *propertyAccessExpression.getterFunction(); > Vector<UniqueRef<AST::Expression>> arguments; >- arguments.append(WTFMove(argument->expression)); >+ arguments.append(propertyAccessExpression.takeBase()); > if (is<AST::IndexExpression>(propertyAccessExpression)) > arguments.append(downcast<AST::IndexExpression>(propertyAccessExpression).takeIndex()); >- auto callExpression = makeUniqueRef<AST::CallExpression>(Lexer::Token(origin), String(anderFunction->name()), WTFMove(arguments)); >- callExpression->setType(anderFunction->type().clone()); >+ auto* callExpression = AST::replaceWith<AST::CallExpression>(propertyAccessExpression, WTFMove(origin), String(getterFunction.name()), WTFMove(arguments)); >+ callExpression->setFunction(getterFunction); >+ callExpression->setType(getterFunction.type().clone()); > callExpression->setTypeAnnotation(AST::RightValue()); >- callExpression->setFunction(*anderFunction); >+ return true; >+ } > >- auto* dereferenceExpression = AST::replaceWith<AST::DereferenceExpression>(propertyAccessExpression, WTFMove(origin), WTFMove(callExpression)); >- dereferenceExpression->setType(downcast<AST::PointerType>(anderFunction->type()).elementType().clone()); >- dereferenceExpression->setTypeAnnotation(AST::LeftValue { downcast<AST::PointerType>(anderFunction->type()).addressSpace() }); >+ // We have an ander, but no left value to call it on. Let's save the value into a temporary variable to create a left value. >+ // This is effectively inlining the functions the spec says are generated. >+ ASSERT(propertyAccessExpression.threadAnderFunction()); >+ auto* threadAnderFunction = propertyAccessExpression.threadAnderFunction(); > >- if (auto& variableDeclaration = argument->variableDeclaration) >- m_variableDeclarations.append(WTFMove(*variableDeclaration)); >+ auto variableDeclaration = makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(origin), AST::Qualifiers(), base.resolvedType().clone(), String(), WTF::nullopt, WTF::nullopt); > >- return; >- } >+ auto variableReference1 = makeUniqueRef<AST::VariableReference>(AST::VariableReference::wrap(variableDeclaration)); >+ variableReference1->setType(base.resolvedType().clone()); >+ variableReference1->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); >+ >+ auto assignmentExpression = makeUniqueRef<AST::AssignmentExpression>(Lexer::Token(origin), WTFMove(variableReference1), propertyAccessExpression.takeBase()); >+ assignmentExpression->setType(base.resolvedType().clone()); >+ assignmentExpression->setTypeAnnotation(AST::RightValue()); >+ >+ auto variableReference2 = makeUniqueRef<AST::VariableReference>(AST::VariableReference::wrap(variableDeclaration)); >+ variableReference2->setType(base.resolvedType().clone()); >+ variableReference2->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); >+ >+ auto makePointerExpression = makeUniqueRef<AST::MakePointerExpression>(Lexer::Token(origin), WTFMove(variableReference2)); >+ makePointerExpression->setType(makeUniqueRef<AST::PointerType>(Lexer::Token(origin), AST::AddressSpace::Thread, base.resolvedType().clone())); >+ makePointerExpression->setTypeAnnotation(AST::RightValue()); > >- ASSERT(propertyAccessExpression.getterFunction()); >- auto& getterFunction = *propertyAccessExpression.getterFunction(); > Vector<UniqueRef<AST::Expression>> arguments; >- arguments.append(propertyAccessExpression.takeBase()); >+ arguments.append(WTFMove(makePointerExpression)); > if (is<AST::IndexExpression>(propertyAccessExpression)) > arguments.append(downcast<AST::IndexExpression>(propertyAccessExpression).takeIndex()); >- auto* callExpression = AST::replaceWith<AST::CallExpression>(propertyAccessExpression, WTFMove(origin), String(getterFunction.name()), WTFMove(arguments)); >- callExpression->setFunction(getterFunction); >- callExpression->setType(getterFunction.type().clone()); >+ auto callExpression = makeUniqueRef<AST::CallExpression>(Lexer::Token(origin), String(threadAnderFunction->name()), WTFMove(arguments)); >+ callExpression->setType(threadAnderFunction->type().clone()); > callExpression->setTypeAnnotation(AST::RightValue()); >+ callExpression->setFunction(*threadAnderFunction); >+ >+ auto dereferenceExpression = makeUniqueRef<AST::DereferenceExpression>(WTFMove(origin), WTFMove(callExpression)); >+ dereferenceExpression->setType(downcast<AST::PointerType>(threadAnderFunction->type()).elementType().clone()); >+ dereferenceExpression->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); >+ >+ Vector<UniqueRef<AST::Expression>> expressions; >+ expressions.append(WTFMove(assignmentExpression)); >+ expressions.append(WTFMove(dereferenceExpression)); >+ auto* commaExpression = AST::replaceWith<AST::CommaExpression>(propertyAccessExpression, WTFMove(origin), WTFMove(expressions)); >+ commaExpression->setType(downcast<AST::PointerType>(threadAnderFunction->type()).elementType().clone()); >+ commaExpression->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); >+ >+ m_variableDeclarations.append(WTFMove(variableDeclaration)); >+ return true; >+ > } > > class LeftValueSimplifier : public Visitor { >@@ -770,14 +771,14 @@ void LeftValueSimplifier::finishVisiting(AST::PropertyAccessExpression& property > > Lexer::Token origin = propertyAccessExpression.origin(); > auto* anderFunction = propertyAccessExpression.anderFunction(); >- >- auto argument = anderCallArgument(propertyAccessExpression); >- ASSERT(argument); >- ASSERT(!argument->variableDeclaration); >- ASSERT(argument->whichAnder == WhichAnder::NonThreadAnder); >+ auto& base = propertyAccessExpression.base(); >+ auto leftAddressSpace = *propertyAccessExpression.base().typeAnnotation().leftAddressSpace(); >+ auto makePointerExpression = makeUniqueRef<AST::MakePointerExpression>(Lexer::Token(origin), propertyAccessExpression.takeBase()); >+ makePointerExpression->setType(makeUniqueRef<AST::PointerType>(Lexer::Token(origin), leftAddressSpace, base.resolvedType().clone())); >+ makePointerExpression->setTypeAnnotation(AST::RightValue()); > > Vector<UniqueRef<AST::Expression>> arguments; >- arguments.append(WTFMove(argument->expression)); >+ arguments.append(WTFMove(makePointerExpression)); > if (is<AST::IndexExpression>(propertyAccessExpression)) > arguments.append(downcast<AST::IndexExpression>(propertyAccessExpression).takeIndex()); > auto callExpression = makeUniqueRef<AST::CallExpression>(Lexer::Token(origin), String(anderFunction->name()), WTFMove(arguments)); >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSemanticMatcher.cpp b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSemanticMatcher.cpp >index 5002ee526c5..7a551bf2802 100644 >--- a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSemanticMatcher.cpp >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLSemanticMatcher.cpp >@@ -55,17 +55,19 @@ static AST::FunctionDefinition* findEntryPoint(Vector<UniqueRef<AST::FunctionDef > return &*iterator; > }; > >-static bool matchMode(Binding::BindingDetails bindingType, AST::ResourceSemantic::Mode mode) >+static bool matchMode(BindingType bindingType, AST::ResourceSemantic::Mode mode) > { >- return WTF::visit(WTF::makeVisitor([&](UniformBufferBinding) -> bool { >+ switch (bindingType) { >+ case BindingType::UniformBuffer: > return mode == AST::ResourceSemantic::Mode::Buffer; >- }, [&](SamplerBinding) -> bool { >+ case BindingType::Sampler: > return mode == AST::ResourceSemantic::Mode::Sampler; >- }, [&](TextureBinding) -> bool { >+ case BindingType::Texture: > return mode == AST::ResourceSemantic::Mode::Texture; >- }, [&](StorageBufferBinding) -> bool { >+ default: >+ ASSERT(bindingType == BindingType::StorageBuffer); > return mode == AST::ResourceSemantic::Mode::UnorderedAccessView; >- }), bindingType); >+ } > } > > static Optional<HashMap<Binding*, size_t>> matchResources(Vector<EntryPointItem>& entryPointItems, Layout& layout, ShaderStage shaderStage) >@@ -85,9 +87,9 @@ static Optional<HashMap<Binding*, size_t>> matchResources(Vector<EntryPointItem> > if (!WTF::holds_alternative<AST::ResourceSemantic>(semantic)) > continue; > auto& resourceSemantic = WTF::get<AST::ResourceSemantic>(semantic); >- if (!matchMode(binding.binding, resourceSemantic.mode())) >+ if (!matchMode(binding.bindingType, resourceSemantic.mode())) > continue; >- if (binding.externalName != resourceSemantic.index()) >+ if (binding.name != resourceSemantic.index()) > continue; > if (space != resourceSemantic.space()) > continue; >diff --git a/Source/WebCore/Modules/webgpu/WebGPUBindGroupDescriptor.cpp b/Source/WebCore/Modules/webgpu/WebGPUBindGroupDescriptor.cpp >index 3e510c574f3..9851567e7c1 100644 >--- a/Source/WebCore/Modules/webgpu/WebGPUBindGroupDescriptor.cpp >+++ b/Source/WebCore/Modules/webgpu/WebGPUBindGroupDescriptor.cpp >@@ -111,7 +111,7 @@ Optional<GPUBindGroupDescriptor> WebGPUBindGroupDescriptor::tryCreateGPUBindGrou > if (!buffer) > return WTF::nullopt; > >- if (!validateBufferBindingType(buffer, layoutBinding.externalBinding, functionName)) >+ if (!validateBufferBindingType(buffer, layoutBinding, functionName)) > return WTF::nullopt; > > return static_cast<GPUBindingResource>(GPUBufferBinding { makeRef(*buffer), bufferBinding.offset, bufferBinding.size }); >@@ -119,7 +119,7 @@ Optional<GPUBindGroupDescriptor> WebGPUBindGroupDescriptor::tryCreateGPUBindGrou > > auto bindingResource = WTF::visit(bindingResourceVisitor, binding.resource); > if (!bindingResource) { >- LOG(WebGPU, "%s: Invalid resource for binding %u!", functionName, layoutBinding.externalBinding.binding); >+ LOG(WebGPU, "%s: Invalid resource for binding %u!", functionName, layoutBinding.binding); > return WTF::nullopt; > } > >diff --git a/Source/WebCore/platform/graphics/gpu/GPUBindGroupLayout.h b/Source/WebCore/platform/graphics/gpu/GPUBindGroupLayout.h >index f7762c3c3b1..a55b1c91368 100644 >--- a/Source/WebCore/platform/graphics/gpu/GPUBindGroupLayout.h >+++ b/Source/WebCore/platform/graphics/gpu/GPUBindGroupLayout.h >@@ -33,7 +33,6 @@ > #include <wtf/RefCounted.h> > #include <wtf/RefPtr.h> > #include <wtf/RetainPtr.h> >-#include <wtf/Variant.h> > > #if USE(METAL) > OBJC_PROTOCOL(MTLArgumentEncoder); >@@ -48,37 +47,7 @@ class GPUBindGroupLayout : public RefCounted<GPUBindGroupLayout> { > public: > static RefPtr<GPUBindGroupLayout> tryCreate(const GPUDevice&, const GPUBindGroupLayoutDescriptor&); > >- struct UniformBuffer { >- unsigned internalLengthName; >- }; >- >- struct DynamicUniformBuffer { >- unsigned internalLengthName; >- }; >- >- struct Sampler { >- }; >- >- struct SampledTexture { >- }; >- >- struct StorageBuffer { >- unsigned internalLengthName; >- }; >- >- struct DynamicStorageBuffer { >- unsigned internalLengthName; >- }; >- >- using InternalBindingDetails = Variant<UniformBuffer, DynamicUniformBuffer, Sampler, SampledTexture, StorageBuffer, DynamicStorageBuffer>; >- >- struct Binding { >- GPUBindGroupLayoutBinding externalBinding; >- unsigned internalName; >- InternalBindingDetails internalBindingDetails; >- }; >- >- using BindingsMapType = HashMap<uint64_t, Binding, WTF::IntHash<uint64_t>, WTF::UnsignedWithZeroKeyHashTraits<uint64_t>>; >+ using BindingsMapType = HashMap<uint64_t, GPUBindGroupLayoutBinding, WTF::IntHash<uint64_t>, WTF::UnsignedWithZeroKeyHashTraits<uint64_t>>; > const BindingsMapType& bindingsMap() const { return m_bindingsMap; } > #if USE(METAL) > MTLArgumentEncoder *vertexEncoder() const { return m_vertexEncoder.get(); } >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupLayoutMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupLayoutMetal.mm >index 927f9ff9bf3..e2ed11a6288 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupLayoutMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupLayoutMetal.mm >@@ -77,18 +77,6 @@ static RetainPtr<MTLArgumentEncoder> tryCreateMtlArgumentEncoder(const GPUDevice > return encoder; > }; > >-static RetainPtr<MTLArgumentDescriptor> argumentDescriptor(MTLDataType dataType, NSUInteger index) >-{ >- RetainPtr<MTLArgumentDescriptor> mtlArgument; >- BEGIN_BLOCK_OBJC_EXCEPTIONS; >- mtlArgument = adoptNS([MTLArgumentDescriptor new]); >- END_BLOCK_OBJC_EXCEPTIONS; >- >- [mtlArgument.get() setDataType:dataType]; >- [mtlArgument.get() setIndex:index]; >- return mtlArgument; >-} >- > RefPtr<GPUBindGroupLayout> GPUBindGroupLayout::tryCreate(const GPUDevice& device, const GPUBindGroupLayoutDescriptor& descriptor) > { > if (!device.platformDevice()) { >@@ -99,72 +87,47 @@ RefPtr<GPUBindGroupLayout> GPUBindGroupLayout::tryCreate(const GPUDevice& device > ArgumentArray vertexArgsArray, fragmentArgsArray, computeArgsArray; > BindingsMapType bindingsMap; > >- unsigned internalName = 0; >- unsigned internalLengthBase = descriptor.bindings.size(); > for (const auto& binding : descriptor.bindings) { >- Optional<unsigned> extraIndex; >- auto internalDetails = ([&]() -> GPUBindGroupLayout::InternalBindingDetails { >- switch (binding.type) { >- case GPUBindingType::UniformBuffer: >- extraIndex = internalLengthBase++; >- return GPUBindGroupLayout::UniformBuffer { *extraIndex }; >- case GPUBindingType::DynamicUniformBuffer: >- extraIndex = internalLengthBase++; >- return GPUBindGroupLayout::DynamicUniformBuffer { *extraIndex }; >- case GPUBindingType::Sampler: >- return GPUBindGroupLayout::Sampler { }; >- case GPUBindingType::SampledTexture: >- return GPUBindGroupLayout::SampledTexture { }; >- case GPUBindingType::StorageBuffer: >- extraIndex = internalLengthBase++; >- return GPUBindGroupLayout::StorageBuffer { *extraIndex }; >- default: >- ASSERT(binding.type == GPUBindingType::DynamicStorageBuffer); >- extraIndex = internalLengthBase++; >- return GPUBindGroupLayout::DynamicStorageBuffer { *extraIndex }; >- } >- })(); >- Binding bindingDetails = { binding, internalName++, WTFMove(internalDetails) }; >- if (!bindingsMap.add(binding.binding, bindingDetails)) { >+ if (!bindingsMap.add(binding.binding, binding)) { > LOG(WebGPU, "GPUBindGroupLayout::tryCreate(): Duplicate binding %u found in GPUBindGroupLayoutDescriptor!", binding.binding); > return nullptr; > } > >- RetainPtr<MTLArgumentDescriptor> mtlArgument = argumentDescriptor(MTLDataTypeForBindingType(binding.type), bindingDetails.internalName); >+ RetainPtr<MTLArgumentDescriptor> mtlArgument; > >+ BEGIN_BLOCK_OBJC_EXCEPTIONS; >+ mtlArgument = adoptNS([MTLArgumentDescriptor new]); >+ END_BLOCK_OBJC_EXCEPTIONS; > if (!mtlArgument) { > LOG(WebGPU, "GPUBindGroupLayout::tryCreate(): Unable to create MTLArgumentDescriptor for binding %u!", binding.binding); > return nullptr; > } > >- auto addIndices = [&](ArgumentArray& array) -> bool { >- appendArgumentToArray(array, mtlArgument); >- if (extraIndex) { >- RetainPtr<MTLArgumentDescriptor> mtlArgument = argumentDescriptor(MTLDataTypeUInt2, *extraIndex); >- if (!mtlArgument) { >- LOG(WebGPU, "GPUBindGroupLayout::tryCreate(): Unable to create MTLArgumentDescriptor for binding %u!", binding.binding); >- return false; >- } >- appendArgumentToArray(array, mtlArgument); >- } >- return true; >- }; >- if ((binding.visibility & GPUShaderStageBit::Flags::Vertex) && !addIndices(vertexArgsArray)) >- return nullptr; >- if ((binding.visibility & GPUShaderStageBit::Flags::Fragment) && !addIndices(fragmentArgsArray)) >- return nullptr; >- if ((binding.visibility & GPUShaderStageBit::Flags::Compute) && !addIndices(computeArgsArray)) >- return nullptr; >+ [mtlArgument setDataType:MTLDataTypeForBindingType(binding.type)]; >+ [mtlArgument setIndex:binding.binding]; >+ >+ if (binding.visibility & GPUShaderStageBit::Flags::Vertex) >+ appendArgumentToArray(vertexArgsArray, mtlArgument); >+ if (binding.visibility & GPUShaderStageBit::Flags::Fragment) >+ appendArgumentToArray(fragmentArgsArray, mtlArgument); >+ if (binding.visibility & GPUShaderStageBit::Flags::Compute) >+ appendArgumentToArray(computeArgsArray, mtlArgument); > } > > RetainPtr<MTLArgumentEncoder> vertex, fragment, compute; > >- if (vertexArgsArray && !(vertex = tryCreateMtlArgumentEncoder(device, vertexArgsArray))) >- return nullptr; >- if (fragmentArgsArray && !(fragment = tryCreateMtlArgumentEncoder(device, fragmentArgsArray))) >- return nullptr; >- if (computeArgsArray && !(compute = tryCreateMtlArgumentEncoder(device, computeArgsArray))) >- return nullptr; >+ if (vertexArgsArray) { >+ if (!(vertex = tryCreateMtlArgumentEncoder(device, vertexArgsArray))) >+ return nullptr; >+ } >+ if (fragmentArgsArray) { >+ if (!(fragment = tryCreateMtlArgumentEncoder(device, fragmentArgsArray))) >+ return nullptr; >+ } >+ if (computeArgsArray) { >+ if (!(compute = tryCreateMtlArgumentEncoder(device, computeArgsArray))) >+ return nullptr; >+ } > > return adoptRef(new GPUBindGroupLayout(WTFMove(bindingsMap), WTFMove(vertex), WTFMove(fragment), WTFMove(compute))); > } >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupMetal.mm >index 6262e5f6d41..da2c20d03ef 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupMetal.mm >@@ -72,15 +72,13 @@ static Optional<GPUBufferBinding> tryGetResourceAsBufferBinding(const GPUBinding > return GPUBufferBinding { bufferBinding.buffer.copyRef(), bufferBinding.offset, bufferBinding.size }; > } > >-static void setBufferOnEncoder(MTLArgumentEncoder *argumentEncoder, const GPUBufferBinding& bufferBinding, unsigned name, unsigned lengthName) >+static void setBufferOnEncoder(MTLArgumentEncoder *argumentEncoder, const GPUBufferBinding& bufferBinding, unsigned index) > { > ASSERT(argumentEncoder && bufferBinding.buffer->platformBuffer()); > > BEGIN_BLOCK_OBJC_EXCEPTIONS; > // Bounds check when converting GPUBufferBinding ensures that NSUInteger cast of uint64_t offset is safe. >- [argumentEncoder setBuffer:bufferBinding.buffer->platformBuffer() offset:static_cast<NSUInteger>(bufferBinding.offset) atIndex:name]; >- void* lengthPointer = [argumentEncoder constantDataAtIndex:lengthName]; >- memcpy(lengthPointer, &bufferBinding.size, sizeof(uint64_t)); >+ [argumentEncoder setBuffer:bufferBinding.buffer->platformBuffer() offset:static_cast<NSUInteger>(bufferBinding.offset) atIndex:index]; > END_BLOCK_OBJC_EXCEPTIONS; > } > >@@ -173,12 +171,12 @@ RefPtr<GPUBindGroup> GPUBindGroup::tryCreate(const GPUBindGroupDescriptor& descr > return nullptr; > } > auto layoutBinding = layoutIterator->value; >- if (layoutBinding.externalBinding.visibility == GPUShaderStageBit::Flags::None) >+ if (layoutBinding.visibility == GPUShaderStageBit::Flags::None) > continue; > >- bool isForVertex = layoutBinding.externalBinding.visibility & GPUShaderStageBit::Flags::Vertex; >- bool isForFragment = layoutBinding.externalBinding.visibility & GPUShaderStageBit::Flags::Fragment; >- bool isForCompute = layoutBinding.externalBinding.visibility & GPUShaderStageBit::Flags::Compute; >+ bool isForVertex = layoutBinding.visibility & GPUShaderStageBit::Flags::Vertex; >+ bool isForFragment = layoutBinding.visibility & GPUShaderStageBit::Flags::Fragment; >+ bool isForCompute = layoutBinding.visibility & GPUShaderStageBit::Flags::Compute; > > if (isForVertex && !vertexEncoder) { > LOG(WebGPU, "%s: No vertex argument encoder found for binding %u!", functionName, index); >@@ -193,39 +191,39 @@ RefPtr<GPUBindGroup> GPUBindGroup::tryCreate(const GPUBindGroupDescriptor& descr > return nullptr; > } > >- auto handleBuffer = [&](unsigned internalLengthName) -> bool { >+ switch (layoutBinding.type) { >+ // FIXME: Support more resource types. >+ // FIXME: We could avoid this ugly switch-on-type using virtual functions if GPUBindingResource is refactored as a base class rather than a Variant. >+ case GPUBindingType::UniformBuffer: >+ case GPUBindingType::StorageBuffer: { > auto bufferResource = tryGetResourceAsBufferBinding(resourceBinding.resource, functionName); > if (!bufferResource) >- return false; >+ return nullptr; > if (isForVertex) >- setBufferOnEncoder(vertexEncoder, *bufferResource, layoutBinding.internalName, internalLengthName); >+ setBufferOnEncoder(vertexEncoder, *bufferResource, index); > if (isForFragment) >- setBufferOnEncoder(fragmentEncoder, *bufferResource, layoutBinding.internalName, internalLengthName); >+ setBufferOnEncoder(fragmentEncoder, *bufferResource, index); > if (isForCompute) >- setBufferOnEncoder(computeEncoder, *bufferResource, layoutBinding.internalName, internalLengthName); >+ setBufferOnEncoder(computeEncoder, *bufferResource, index); > boundBuffers.append(bufferResource->buffer.copyRef()); >- return true; >- }; >- >- auto success = WTF::visit(WTF::makeVisitor([&](GPUBindGroupLayout::UniformBuffer& uniformBuffer) -> bool { >- return handleBuffer(uniformBuffer.internalLengthName); >- }, [&](GPUBindGroupLayout::DynamicUniformBuffer& dynamicUniformBuffer) -> bool { >- return handleBuffer(dynamicUniformBuffer.internalLengthName); >- }, [&](GPUBindGroupLayout::Sampler&) -> bool { >+ break; >+ } >+ case GPUBindingType::Sampler: { > auto samplerState = tryGetResourceAsMtlSampler(resourceBinding.resource, functionName); > if (!samplerState) >- return false; >+ return nullptr; > if (isForVertex) > setSamplerOnEncoder(vertexEncoder, samplerState, index); > if (isForFragment) > setSamplerOnEncoder(fragmentEncoder, samplerState, index); > if (isForCompute) > setSamplerOnEncoder(computeEncoder, samplerState, index); >- return true; >- }, [&](GPUBindGroupLayout::SampledTexture&) -> bool { >+ break; >+ } >+ case GPUBindingType::SampledTexture: { > auto textureResource = tryGetResourceAsTexture(resourceBinding.resource, functionName); > if (!textureResource) >- return false; >+ return nullptr; > if (isForVertex) > setTextureOnEncoder(vertexEncoder, textureResource->platformTexture(), index); > if (isForFragment) >@@ -233,14 +231,12 @@ RefPtr<GPUBindGroup> GPUBindGroup::tryCreate(const GPUBindGroupDescriptor& descr > if (isForCompute) > setTextureOnEncoder(computeEncoder, textureResource->platformTexture(), index); > boundTextures.append(textureResource.releaseNonNull()); >- return true; >- }, [&](GPUBindGroupLayout::StorageBuffer& storageBuffer) -> bool { >- return handleBuffer(storageBuffer.internalLengthName); >- }, [&](GPUBindGroupLayout::DynamicStorageBuffer& dynamicStorageBuffer) -> bool { >- return handleBuffer(dynamicStorageBuffer.internalLengthName); >- }), layoutBinding.internalBindingDetails); >- if (!success) >+ break; >+ } >+ default: >+ LOG(WebGPU, "%s: Resource type not yet implemented.", functionName); > return nullptr; >+ } > } > > return adoptRef(new GPUBindGroup(WTFMove(vertexArgsBuffer), WTFMove(fragmentArgsBuffer), WTFMove(computeArgsBuffer), WTFMove(boundBuffers), WTFMove(boundTextures))); >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm >index 4a9eebbe130..2bb62040941 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm >@@ -110,21 +110,20 @@ static OptionSet<WHLSL::ShaderStage> convertShaderStageFlags(GPUShaderStageFlags > return result; > } > >-static Optional<WHLSL::Binding::BindingDetails> convertBindingType(GPUBindGroupLayout::InternalBindingDetails internalBindingDetails) >+static Optional<WHLSL::BindingType> convertBindingType(GPUBindingType type) > { >- return WTF::visit(WTF::makeVisitor([&](GPUBindGroupLayout::UniformBuffer uniformBuffer) -> Optional<WHLSL::Binding::BindingDetails> { >- return { WHLSL::UniformBufferBinding { uniformBuffer.internalLengthName } }; >- }, [&](GPUBindGroupLayout::DynamicUniformBuffer) -> Optional<WHLSL::Binding::BindingDetails> { >- return WTF::nullopt; >- }, [&](GPUBindGroupLayout::Sampler) -> Optional<WHLSL::Binding::BindingDetails> { >- return { WHLSL::SamplerBinding { } }; >- }, [&](GPUBindGroupLayout::SampledTexture) -> Optional<WHLSL::Binding::BindingDetails> { >- return { WHLSL::TextureBinding { } }; >- }, [&](GPUBindGroupLayout::StorageBuffer storageBuffer) -> Optional<WHLSL::Binding::BindingDetails> { >- return { WHLSL::StorageBufferBinding { storageBuffer.internalLengthName } }; >- }, [&](GPUBindGroupLayout::DynamicStorageBuffer) -> Optional<WHLSL::Binding::BindingDetails> { >+ switch (type) { >+ case GPUBindingType::UniformBuffer: >+ return WHLSL::BindingType::UniformBuffer; >+ case GPUBindingType::Sampler: >+ return WHLSL::BindingType::Sampler; >+ case GPUBindingType::SampledTexture: >+ return WHLSL::BindingType::Texture; >+ case GPUBindingType::StorageBuffer: >+ return WHLSL::BindingType::StorageBuffer; >+ default: > return WTF::nullopt; >- }), internalBindingDetails); >+ } > } > > static Optional<WHLSL::TextureFormat> convertTextureFormat(GPUTextureFormat format) >@@ -378,17 +377,16 @@ static Optional<WHLSL::Layout> convertLayout(const GPUPipelineLayout& layout) > WHLSL::BindGroup bindGroup; > bindGroup.name = static_cast<unsigned>(i); > for (const auto& keyValuePair : bindGroupLayout->bindingsMap()) { >- const auto& bindingDetails = keyValuePair.value; >+ const auto& gpuBindGroupLayoutBinding = keyValuePair.value; > WHLSL::Binding binding; >- binding.visibility = convertShaderStageFlags(bindingDetails.externalBinding.visibility); >- if (auto bindingType = convertBindingType(bindingDetails.internalBindingDetails)) >- binding.binding = *bindingType; >+ binding.visibility = convertShaderStageFlags(gpuBindGroupLayoutBinding.visibility); >+ if (auto bindingType = convertBindingType(gpuBindGroupLayoutBinding.type)) >+ binding.bindingType = *bindingType; > else > return WTF::nullopt; >- if (bindingDetails.externalBinding.binding > std::numeric_limits<unsigned>::max()) >+ if (gpuBindGroupLayoutBinding.binding > std::numeric_limits<unsigned>::max()) > return WTF::nullopt; >- binding.externalName = bindingDetails.externalBinding.binding; >- binding.internalName = bindingDetails.internalName; >+ binding.name = static_cast<unsigned>(gpuBindGroupLayoutBinding.binding); > bindGroup.bindings.append(WTFMove(binding)); > } > result.append(WTFMove(bindGroup));
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 198163
:
370830
|
370874
|
370912
|
371158
|
371243
|
371373
|
371374
|
371375
|
371471
|
371475
|
371555
|
371900