WebKit Bugzilla
Attachment 372664 Details for
Bug 198414
: [WHLSL] Implement arrays and MakeArrayReference
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
WIP
c-backup.diff (text/plain), 15.02 KB, created by
Saam Barati
on 2019-06-21 18:56:52 PDT
(
hide
)
Description:
WIP
Filename:
MIME Type:
Creator:
Saam Barati
Created:
2019-06-21 18:56:52 PDT
Size:
15.02 KB
patch
obsolete
>Index: Source/WebCore/Modules/webgpu/WHLSL/WHLSLPrepare.cpp >=================================================================== >--- Source/WebCore/Modules/webgpu/WHLSL/WHLSLPrepare.cpp (revision 246704) >+++ Source/WebCore/Modules/webgpu/WHLSL/WHLSLPrepare.cpp (working copy) >@@ -60,7 +60,7 @@ namespace WHLSL { > > static constexpr bool dumpASTBeforeEachPass = false; > static constexpr bool dumpASTAfterParsing = false; >-static constexpr bool dumpASTAtEnd = false; >+static constexpr bool dumpASTAtEnd = true; > static constexpr bool alwaysDumpPassFailures = false; > static constexpr bool dumpPassFailure = dumpASTBeforeEachPass || dumpASTAfterParsing || dumpASTAtEnd || alwaysDumpPassFailures; > >Index: Source/WebCore/Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp >=================================================================== >--- Source/WebCore/Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp (revision 246704) >+++ Source/WebCore/Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp (working copy) >@@ -95,13 +95,12 @@ struct AnderCallArgumentResult { > }; > > template <typename ExpressionConstructor, typename TypeConstructor> >-static Optional<AnderCallArgumentResult> wrapAnderCallArgument(UniqueRef<AST::Expression>& expression, bool anderFunction, bool threadAnderFunction) >+static Optional<AnderCallArgumentResult> wrapAnderCallArgument(UniqueRef<AST::Expression>& expression, UniqueRef<AST::UnnamedType> baseType, 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()); >@@ -109,7 +108,6 @@ static Optional<AnderCallArgumentResult> > } > 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)); >@@ -151,9 +149,9 @@ static Optional<AnderCallArgumentResult> > if (is<AST::ArrayReferenceType>(unnamedType)) > return {{ WTFMove(expression), WTF::nullopt, WhichAnder::Ander }}; > if (is<AST::ArrayType>(unnamedType)) >- return wrapAnderCallArgument<AST::MakeArrayReferenceExpression, AST::ArrayReferenceType>(expression, anderFunction, threadAnderFunction); >+ return wrapAnderCallArgument<AST::MakeArrayReferenceExpression, AST::ArrayReferenceType>(expression, downcast<AST::ArrayType>(unnamedType).type().clone(), anderFunction, threadAnderFunction); > } >- return wrapAnderCallArgument<AST::MakePointerExpression, AST::PointerType>(expression, anderFunction, threadAnderFunction); >+ return wrapAnderCallArgument<AST::MakePointerExpression, AST::PointerType>(expression, expression->resolvedType().clone(), 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) >Index: Source/WebCore/Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt >=================================================================== >--- Source/WebCore/Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt (revision 246704) >+++ Source/WebCore/Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt (working copy) >@@ -792,6 +792,12 @@ int operator++(int value) { > int operator--(int value) { > return value - 1; > } >+uint operator++(uint value) { >+ return value + 1; >+} >+uint operator--(uint value) { >+ return value - 1; >+} > > native ushort Sample(Texture1D<ushort>, sampler, float location); > native ushort Sample(Texture1DArray<ushort>, sampler, float2 location); >Index: Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp >=================================================================== >--- Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp (revision 246704) >+++ Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp (working copy) >@@ -38,6 +38,8 @@ > #include <wtf/SetForScope.h> > #include <wtf/text/StringBuilder.h> > >+#include <wtf/DataLog.h> >+ > namespace WebCore { > > namespace WHLSL { >@@ -628,16 +630,22 @@ void FunctionDefinitionWriter::visit(AST > checkErrorAndVisit(makeArrayReferenceExpression.leftValue()); > // FIXME: This needs to be made to work. It probably should be using the last leftValue too. > // https://bugs.webkit.org/show_bug.cgi?id=198838 >- auto lValue = takeLastValue(); > auto variableName = generateNextVariableName(); >+ >+ dataLogLn("Visiting array reference: ", RawPointer(&makeArrayReferenceExpression)); >+ dataLogLn("Resolving type: ", RawPointer(&makeArrayReferenceExpression.resolvedType())); >+ > auto mangledTypeName = m_typeNamer.mangledNameForType(makeArrayReferenceExpression.resolvedType()); >- if (is<AST::PointerType>(makeArrayReferenceExpression.resolvedType())) >+ if (is<AST::PointerType>(makeArrayReferenceExpression.leftValue().resolvedType())) >+ m_stringBuilder.append(makeString(mangledTypeName, ' ', variableName, " = { ", takeLastValue(), ", 1 };\n")); >+ else if (is<AST::ArrayType>(makeArrayReferenceExpression.leftValue().resolvedType())) { >+ auto lValue = takeLastLeftValue(); >+ auto& arrayType = downcast<AST::ArrayType>(makeArrayReferenceExpression.leftValue().resolvedType()); >+ m_stringBuilder.append(makeString(mangledTypeName, ' ', variableName, " = { ", lValue, "->data(), ", arrayType.numElements(), " };\n")); >+ } else { >+ auto lValue = takeLastLeftValue(); > m_stringBuilder.append(makeString(mangledTypeName, ' ', variableName, " = { ", lValue, ", 1 };\n")); >- else if (is<AST::ArrayType>(makeArrayReferenceExpression.resolvedType())) { >- auto& arrayType = downcast<AST::ArrayType>(makeArrayReferenceExpression.resolvedType()); >- m_stringBuilder.append(makeString(mangledTypeName, ' ', variableName, " = { &(", lValue, "[0]), ", arrayType.numElements(), " };\n")); >- } else >- m_stringBuilder.append(makeString(mangledTypeName, ' ', variableName, " = { &", lValue, ", 1 };\n")); >+ } > appendRightValue(makeArrayReferenceExpression, variableName); > } > >Index: Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLNativeFunctionWriter.cpp >=================================================================== >--- Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLNativeFunctionWriter.cpp (revision 246704) >+++ Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLNativeFunctionWriter.cpp (working copy) >@@ -125,6 +125,10 @@ String writeNativeFunction(AST::NativeFu > if (nativeFunctionDeclaration.isCast()) { > auto metalReturnName = typeNamer.mangledNameForType(nativeFunctionDeclaration.type()); > if (!nativeFunctionDeclaration.parameters().size()) { >+ if (is<AST::ArrayType>(nativeFunctionDeclaration.type())) { >+ dataLogLn("default Ctor for array type!"); >+ } >+ > stringBuilder.append(makeString(metalReturnName, ' ', outputFunctionName, "() {\n")); > stringBuilder.append(makeString(" ", metalReturnName, " x;\n")); > stringBuilder.append(makeString(" ", memsetZeroFunctionName, "(x);\n")); >@@ -174,8 +178,8 @@ String writeNativeFunction(AST::NativeFu > auto& unnamedParameterType = downcast<AST::UnnamedType>(parameterType); > if (is<AST::ArrayType>(unnamedParameterType)) { > auto& arrayParameterType = downcast<AST::ArrayType>(unnamedParameterType); >- stringBuilder.append(makeString("uint ", outputFunctionName, '(', metalParameterName, " v) {\n")); >- stringBuilder.append(makeString(" return ", arrayParameterType.numElements(), "u;\n")); >+ stringBuilder.append(makeString("uint ", outputFunctionName, '(', metalParameterName, ") {\n")); >+ stringBuilder.append(makeString(" return ", arrayParameterType.numElements(), ";\n")); > stringBuilder.append("}\n"); > return stringBuilder.toString(); > } >@@ -253,13 +257,22 @@ String writeNativeFunction(AST::NativeFu > > if (nativeFunctionDeclaration.name() == "operator&[]") { > ASSERT(nativeFunctionDeclaration.parameters().size() == 2); >+ > auto metalParameter1Name = typeNamer.mangledNameForType(*nativeFunctionDeclaration.parameters()[0]->type()); > auto metalParameter2Name = typeNamer.mangledNameForType(*nativeFunctionDeclaration.parameters()[1]->type()); > auto metalReturnName = typeNamer.mangledNameForType(nativeFunctionDeclaration.type()); > stringBuilder.append(makeString(metalReturnName, ' ', outputFunctionName, '(', metalParameter1Name, " v, ", metalParameter2Name, " n) {\n")); >- stringBuilder.append(" if (n < v.length) return &(v.pointer[n]);\n"); >+ >+ if (is<AST::ArrayType>(*nativeFunctionDeclaration.parameters()[0]->type())) { >+ AST::ArrayType& arrayType = downcast<AST::ArrayType>(*nativeFunctionDeclaration.parameters()[0]->type()); >+ stringBuilder.append(makeString(" if (n < ", arrayType.numElements(), ") return &v[n];\n")); >+ } else { >+ ASSERT(is<AST::ArrayReferenceType>(*nativeFunctionDeclaration.parameters()[0]->type())); >+ stringBuilder.append(" if (n < v.length) return &(v.pointer[n]);\n"); >+ } > stringBuilder.append(" return nullptr;\n"); > stringBuilder.append("}\n"); >+ > return stringBuilder.toString(); > } > >Index: Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLTypeNamer.cpp >=================================================================== >--- Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLTypeNamer.cpp (revision 246704) >+++ Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLTypeNamer.cpp (working copy) >@@ -398,7 +398,7 @@ void TypeNamer::emitUnnamedTypeDefinitio > } else { > auto& arrayType = downcast<ArrayTypeNameNode>(baseTypeNameNode); > ASSERT(baseTypeNameNode.parent()); >- stringBuilder.append(makeString("typedef Array<", arrayType.parent()->mangledName(), ", ", arrayType.numElements(), "> ", arrayType.mangledName(), ";\n")); >+ stringBuilder.append(makeString("typedef array<", arrayType.parent()->mangledName(), ", ", arrayType.numElements(), "> ", arrayType.mangledName(), ";\n")); > } > emittedUnnamedTypes.add(&baseTypeNameNode); > } >Index: LayoutTests/webgpu/whlsl-simple-arrays.html >=================================================================== >--- LayoutTests/webgpu/whlsl-simple-arrays.html (nonexistent) >+++ LayoutTests/webgpu/whlsl-simple-arrays.html (working copy) >@@ -0,0 +1,121 @@ >+ >+<!DOCTYPE html> >+<html> >+<head> >+<script src="../resources/js-test-pre.js"></script> >+</head> >+<body> >+<script> >+const shaderSource = ` >+void fill(thread int[] array, int value) { >+ for (uint i = 0; i < array.length; i++) { >+ array[i] = value; >+ } >+} >+ >+[numthreads(1, 1, 1)] >+compute void computeShader(device int[] buffer : register(u0), float3 threadID : SV_DispatchThreadID) { >+ int[42] array; >+ if (array.length != 42) >+ return; >+ for (uint i = 0; i < array.length; ++i) { >+ if (array[i] != 0) >+ return; >+ } >+ >+ array[0] = 517; >+ if (array[0] != 517) >+ return; >+ >+ thread int[] arrayPtr = @array; >+ if (arrayPtr.length != 42) >+ return; >+ >+ int[42] array2; // OOPS: causes checker to fail! >+ >+ //array2 = array; >+ //if (array2.length != 42) >+ // return; >+ //if (array2[0] != 517) >+ // return; >+ >+ fill(arrayPtr, 1337); >+ for (uint i = 0; i < arrayPtr.length; ++i) { >+ if (arrayPtr[i] != 1337) >+ return; >+ if (array[i] != 1337) >+ return; >+ } >+ >+ //if (array2[0] != 517) >+ // return; >+ //if (array2.length != 42) >+ // return; >+ //for (uint i = 1; i < array2.length; ++i) { >+ // if (array2[i] != 0) >+ // return; >+ //} >+ >+ buffer[0] = 1; >+} >+`; >+let resultsFloat32Array; >+async function start() { >+ const adapter = await navigator.gpu.requestAdapter(); >+ const device = await adapter.requestDevice(); >+ >+ const shaderModule = device.createShaderModule({code: shaderSource, isWHLSL: true}); >+ const computeStage = {module: shaderModule, entryPoint: "computeShader"}; >+ >+ const bindGroupLayoutDescriptor = {bindings: [{binding: 0, visibility: 7, type: "storage-buffer"}]}; >+ const bindGroupLayout = device.createBindGroupLayout(bindGroupLayoutDescriptor); >+ const pipelineLayoutDescriptor = {bindGroupLayouts: [bindGroupLayout]}; >+ const pipelineLayout = device.createPipelineLayout(pipelineLayoutDescriptor); >+ >+ const computePipelineDescriptor = {computeStage, layout: pipelineLayout}; >+ const computePipeline = device.createComputePipeline(computePipelineDescriptor); >+ >+ const size = Int32Array.BYTES_PER_ELEMENT * 1; >+ >+ const bufferDescriptor = {size, usage: GPUBufferUsage.MAP_WRITE | GPUBufferUsage.TRANSFER_SRC}; >+ const buffer = device.createBuffer(bufferDescriptor); >+ const bufferArrayBuffer = await buffer.mapWriteAsync(); >+ const bufferFloat32Array = new Int32Array(bufferArrayBuffer); >+ bufferFloat32Array[0] = 0; >+ buffer.unmap(); >+ >+ const resultsBufferDescriptor = {size, usage: GPUBufferUsage.STORAGE | GPUBufferUsage.TRANSFER_DST | GPUBufferUsage.MAP_READ}; >+ const resultsBuffer = device.createBuffer(resultsBufferDescriptor); >+ >+ const bufferBinding = {buffer: resultsBuffer, size}; >+ const bindGroupBinding = {binding: 0, resource: bufferBinding}; >+ const bindGroupDescriptor = {layout: bindGroupLayout, bindings: [bindGroupBinding]}; >+ const bindGroup = device.createBindGroup(bindGroupDescriptor); >+ >+ const commandEncoder = device.createCommandEncoder(); // {} >+ commandEncoder.copyBufferToBuffer(buffer, 0, resultsBuffer, 0, size); >+ const computePassEncoder = commandEncoder.beginComputePass(); >+ computePassEncoder.setPipeline(computePipeline); >+ computePassEncoder.setBindGroup(0, bindGroup); >+ computePassEncoder.dispatch(1, 1, 1); >+ computePassEncoder.endPass(); >+ const commandBuffer = commandEncoder.finish(); >+ device.getQueue().submit([commandBuffer]); >+ >+ const resultsArrayBuffer = await resultsBuffer.mapReadAsync(); >+ resultsFloat32Array = new Int32Array(resultsArrayBuffer); >+ shouldBe("resultsFloat32Array[0]", "1"); >+ resultsBuffer.unmap(); >+} >+window.jsTestIsAsync = true; >+window.addEventListener("load", function() { >+ start().then(function() { >+ finishJSTest(); >+ }, function() { >+ finishJSTest(); >+ }); >+}); >+</script> >+<script src="../resources/js-test-post.js"></script> >+</body> >+</html>
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 198414
:
372664
|
372859
|
373006