WebKit Bugzilla
Attachment 372024 Details for
Bug 198704
: [WHLSL] Hook up common texture functions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
WIP
patch.txt (text/plain), 40.51 KB, created by
Myles C. Maxfield
on 2019-06-13 00:02:52 PDT
(
hide
)
Description:
WIP
Filename:
MIME Type:
Creator:
Myles C. Maxfield
Created:
2019-06-13 00:02:52 PDT
Size:
40.51 KB
patch
obsolete
>commit de5e1bd9631e4b412ff9d72d5d177bd4172e27fe >Author: Myles C. Maxfield <mmaxfield@apple.com> >Date: Wed Jun 12 23:59:05 2019 -0700 > > textures > >diff --git a/LayoutTests/webgpu/whlsl-textures.html b/LayoutTests/webgpu/whlsl-textures.html >new file mode 100644 >index 00000000000..2dffb00d41d >--- /dev/null >+++ b/LayoutTests/webgpu/whlsl-textures.html >@@ -0,0 +1,134 @@ >+<!DOCTYPE html> >+<html> >+<head> >+</head> >+<body> >+<canvas id="canvas" width="400" height="400"></canvas> >+<script> >+const shaderSource = ` >+vertex float4 vertexShader(float4 position : attribute(0)) : SV_Position { >+ return position; >+} >+ >+fragment float4 fragmentShader(Texture2D<float4> theTexture : register(t0), sampler theSampler : register(s1)) : SV_Target 0 { >+ return Sample(theTexture, theSampler, float2(0.5, 0.5)); >+} >+`; >+async function start() { >+ const adapter = await navigator.gpu.requestAdapter(); >+ const device = await adapter.requestDevice(); >+ >+ const shaderModule = device.createShaderModule({code: shaderSource, isWHLSL: true}); >+ const vertexStage = {module: shaderModule, entryPoint: "vertexShader"}; >+ const fragmentStage = {module: shaderModule, entryPoint: "fragmentShader"}; >+ const primitiveTopology = "triangle-strip"; >+ const rasterizationState = {frontFace: "cw", cullMode: "none"}; >+ const alphaBlend = {}; >+ const colorBlend = {}; >+ const colorStates = [{format: "rgba8unorm", alphaBlend, colorBlend, writeMask: 15}]; // GPUColorWriteBits.ALL >+ const depthStencilState = null; >+ >+ const attribute0 = {shaderLocation: 0, format: "float4"}; >+ const input0 = {stride: 16, attributeSet: [attribute0]}; >+ const inputs = [input0]; >+ const vertexInput = {vertexBuffers: inputs}; >+ >+ const bindGroupLayoutDescriptor = {bindings: [{binding: 0, visibility: 7, type: "sampled-texture"}, {binding: 1, visibility: 7, type: "sampler"}]}; >+ const bindGroupLayout = device.createBindGroupLayout(bindGroupLayoutDescriptor); >+ const pipelineLayoutDescriptor = {bindGroupLayouts: [bindGroupLayout]}; >+ const pipelineLayout = device.createPipelineLayout(pipelineLayoutDescriptor); >+ >+ const renderPipelineDescriptor = {vertexStage, fragmentStage, primitiveTopology, rasterizationState, colorStates, depthStencilState, vertexInput, sampleCount: 1, layout: pipelineLayout}; >+ const renderPipeline = device.createRenderPipeline(renderPipelineDescriptor); >+ >+ const vertexBuffer0Descriptor = {size: Float32Array.BYTES_PER_ELEMENT * 4 * 4, usage: GPUBufferUsage.VERTEX | GPUBufferUsage.MAP_WRITE}; >+ const vertexBuffer0 = device.createBuffer(vertexBuffer0Descriptor); >+ const vertexBuffer0ArrayBuffer = await vertexBuffer0.mapWriteAsync(); >+ const vertexBuffer0Float32Array = new Float32Array(vertexBuffer0ArrayBuffer); >+ vertexBuffer0Float32Array[0] = -0.5; >+ vertexBuffer0Float32Array[1] = -0.5; >+ vertexBuffer0Float32Array[2] = 1.0; >+ vertexBuffer0Float32Array[3] = 1; >+ vertexBuffer0Float32Array[4] = -0.5; >+ vertexBuffer0Float32Array[5] = 0.5; >+ vertexBuffer0Float32Array[6] = 1.0; >+ vertexBuffer0Float32Array[7] = 1; >+ vertexBuffer0Float32Array[8] = 0.5; >+ vertexBuffer0Float32Array[9] = -0.5; >+ vertexBuffer0Float32Array[10] = 1.0; >+ vertexBuffer0Float32Array[11] = 1; >+ vertexBuffer0Float32Array[12] = 0.5; >+ vertexBuffer0Float32Array[13] = 0.5; >+ vertexBuffer0Float32Array[14] = 1.0; >+ vertexBuffer0Float32Array[15] = 1; >+ vertexBuffer0.unmap(); >+ >+ const textureDataBufferDescriptor = {size: Uint8Array.BYTES_PER_ELEMENT * 4 * 2 * 2, usage: GPUBufferUsage.TRANSFER_SRC | GPUBufferUsage.MAP_WRITE}; >+ const textureDataBuffer = device.createBuffer(textureDataBufferDescriptor); >+ const textureDataBufferArrayBuffer = await textureDataBuffer.mapWriteAsync(); >+ const textureDataBufferUint8Array = new Uint8Array(textureDataBufferArrayBuffer); >+ textureDataBufferUint8Array[0] = 255; >+ textureDataBufferUint8Array[1] = 255; >+ textureDataBufferUint8Array[2] = 255; >+ textureDataBufferUint8Array[3] = 255; >+ textureDataBufferUint8Array[4] = 255; >+ textureDataBufferUint8Array[5] = 255; >+ textureDataBufferUint8Array[6] = 255; >+ textureDataBufferUint8Array[7] = 255; >+ textureDataBufferUint8Array[8] = 255; >+ textureDataBufferUint8Array[9] = 255; >+ textureDataBufferUint8Array[10] = 255; >+ textureDataBufferUint8Array[11] = 255; >+ textureDataBufferUint8Array[12] = 255; >+ textureDataBufferUint8Array[13] = 255; >+ textureDataBufferUint8Array[14] = 255; >+ textureDataBufferUint8Array[15] = 255; >+ textureDataBuffer.unmap(); >+ >+ const textureDescriptor = {size: {width: 2, height: 2, depth: 1}, format: "rgba8unorm", usage: GPUTextureUsage.SAMPLED | GPUTextureUsage.TRANSFER_DST}; >+ const texture = device.createTexture(textureDescriptor); >+ const textureView = texture.createDefaultView(); >+ >+ const samplerDescriptor = {magFilter: "linear", minFilter: "linear"}; >+ const sampler = device.createSampler(samplerDescriptor); >+ >+ const bindGroupBindings = [{binding: 0, resource: textureView}, {binding: 1, resource: sampler}]; >+ const bindGroupDescriptor = {layout: bindGroupLayout, bindings: bindGroupBindings}; >+ const bindGroup = device.createBindGroup(bindGroupDescriptor); >+ >+ const canvas = document.getElementById("canvas"); >+ const context = canvas.getContext("gpu"); >+ const swapChainDescriptor = {device, format: "bgra8unorm"}; >+ const swapChain = context.configureSwapChain(swapChainDescriptor); >+ const outputTexture = swapChain.getCurrentTexture(); >+ const outputTextureView = outputTexture.createDefaultView(); >+ >+ const commandEncoder = device.createCommandEncoder(); // {} >+ >+ const bufferCopyView = {buffer: textureDataBuffer, rowPitch: Uint8Array.BYTES_PER_ELEMENT * 4 * 2, imageHeight: Uint8Array.BYTES_PER_ELEMENT * 4 * 2 * 2}; >+ const textureCopyView = {texture: texture}; >+ const copySize = {width: 2, height: 2, depth: 1}; >+ commandEncoder.copyBufferToTexture(bufferCopyView, textureCopyView, copySize); >+ >+ const clearColor = {r: 0, g: 0, b: 1, a: 1}; >+ const colorAttachments = [{attachment: outputTextureView, resolveTarget: null, loadOp: "clear", storeOp: "store", clearColor}]; >+ const depthStencilAttachment = null; >+ const renderPassDescriptor = {colorAttachments, depthStencilAttachment}; >+ const renderPassEncoder = commandEncoder.beginRenderPass(renderPassDescriptor); >+ renderPassEncoder.setPipeline(renderPipeline); >+ renderPassEncoder.setBindGroup(0, bindGroup); >+ renderPassEncoder.setVertexBuffers(0, [vertexBuffer0], [0]); >+ renderPassEncoder.draw(4, 1, 0, 0); >+ renderPassEncoder.endPass(); >+ const commandBuffer = commandEncoder.finish(); >+ device.getQueue().submit([commandBuffer]); >+ >+ if (window.testRunner) >+ testRunner.notifyDone(); >+} >+if (window.testRunner) >+ testRunner.waitUntilDone(); >+window.addEventListener("load", start); >+</script> >+</body> >+</html> >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLNativeTypeDeclaration.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLNativeTypeDeclaration.h >index 3ae6ed6475b..217562f08a3 100644 >--- a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLNativeTypeDeclaration.h >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLNativeTypeDeclaration.h >@@ -63,6 +63,8 @@ public: > bool isVector() const { return m_isVector; } > bool isMatrix() const { return m_isMatrix; } > bool isTexture() const { return m_isTexture; } >+ bool isTextureArray() const { return m_isTextureArray; } >+ bool isDepthTexture() const { return m_isDepthTexture; } > bool isSigned() const { return m_isSigned; } > const std::function<bool(int)>& canRepresentInteger() const { return m_canRepresentInteger; } > const std::function<bool(unsigned)>& canRepresentUnsignedInteger() const { return m_canRepresentUnsignedInteger; } >@@ -79,6 +81,8 @@ public: > void setIsVector() { m_isVector = true; } > void setIsMatrix() { m_isMatrix = true; } > void setIsTexture() { m_isTexture = true; } >+ void setIsTextureArray() { m_isTextureArray = true; } >+ void setIsDepthTexture() { m_isDepthTexture = true; } > void setIsSigned() { m_isSigned = true; } > void setCanRepresentInteger(std::function<bool(int)>&& canRepresent) { m_canRepresentInteger = WTFMove(canRepresent); } > void setCanRepresentUnsignedInteger(std::function<bool(unsigned)>&& canRepresent) { m_canRepresentUnsignedInteger = WTFMove(canRepresent); } >@@ -104,6 +108,8 @@ private: > bool m_isVector { false }; > bool m_isMatrix { false }; > bool m_isTexture { false }; >+ bool m_isTextureArray { false }; >+ bool m_isDepthTexture { false }; > bool m_isSigned { false }; > }; > >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLEntryPointScaffolding.cpp b/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLEntryPointScaffolding.cpp >index 01fb71e240b..d4de95c57df 100644 >--- a/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLEntryPointScaffolding.cpp >+++ b/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLEntryPointScaffolding.cpp >@@ -147,15 +147,23 @@ 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; >- auto& referenceType = downcast<AST::ReferenceType>(unnamedType); >- auto mangledTypeName = m_typeNamer.mangledNameForType(referenceType.elementType()); >- auto addressSpace = toString(referenceType.addressSpace()); >- 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")); >+ auto& type = m_entryPointItems.inputs[iterator->value].unnamedType->unifyNode(); >+ if (is<AST::UnnamedType>(type) && is<AST::ReferenceType>(downcast<AST::UnnamedType>(type))) { >+ auto& referenceType = downcast<AST::ReferenceType>(downcast<AST::UnnamedType>(type)); >+ auto mangledTypeName = m_typeNamer.mangledNameForType(referenceType.elementType()); >+ auto addressSpace = toString(referenceType.addressSpace()); >+ 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")); >+ } else if (is<AST::NamedType>(type) && is<AST::NativeTypeDeclaration>(downcast<AST::NamedType>(type))) { >+ auto& namedType = downcast<AST::NativeTypeDeclaration>(downcast<AST::NamedType>(type)); >+ auto mangledTypeName = m_typeNamer.mangledNameForType(namedType); >+ auto elementName = m_namedBindGroups[i].namedBindings[j].elementName; >+ auto index = m_namedBindGroups[i].namedBindings[j].index; >+ stringBuilder.append(makeString(" ", mangledTypeName, ' ', elementName, " [[id(", index, ")]];\n")); >+ } > } > stringBuilder.append("};\n\n"); > } >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLNativeFunctionWriter.cpp b/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLNativeFunctionWriter.cpp >index db3947b16c8..0c16d1c617b 100644 >--- a/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLNativeFunctionWriter.cpp >+++ b/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLNativeFunctionWriter.cpp >@@ -81,6 +81,17 @@ static String atomicName(String input) > return "fetch_xor"_str; > } > >+static int vectorLength(AST::NativeTypeDeclaration& nativeTypeDeclaration) >+{ >+ int vectorLength = 1; >+ if (!nativeTypeDeclaration.typeArguments().isEmpty()) { >+ ASSERT(nativeTypeDeclaration.typeArguments().size() == 2); >+ ASSERT(WTF::holds_alternative<AST::ConstantExpression>(nativeTypeDeclaration.typeArguments()[1])); >+ vectorLength = WTF::get<AST::ConstantExpression>(nativeTypeDeclaration.typeArguments()[1]).integerLiteral().value(); >+ } >+ return vectorLength; >+} >+ > String writeNativeFunction(AST::NativeFunctionDeclaration& nativeFunctionDeclaration, String& outputFunctionName, Intrinsics& intrinsics, TypeNamer& typeNamer) > { > StringBuilder stringBuilder; >@@ -381,8 +392,39 @@ String writeNativeFunction(AST::NativeFunctionDeclaration& nativeFunctionDeclara > } > > if (nativeFunctionDeclaration.name() == "Sample") { >- // FIXME: https://bugs.webkit.org/show_bug.cgi?id=195813 Implement this >- notImplemented(); >+ ASSERT(nativeFunctionDeclaration.parameters().size() == 3 || nativeFunctionDeclaration.parameters().size() == 4); >+ >+ auto& textureType = downcast<AST::NativeTypeDeclaration>(downcast<AST::NamedType>(nativeFunctionDeclaration.parameters()[0]->type()->unifyNode())); >+ auto& locationType = downcast<AST::NativeTypeDeclaration>(downcast<AST::NamedType>(nativeFunctionDeclaration.parameters()[2]->type()->unifyNode())); >+ auto locationVectorLength = vectorLength(locationType); >+ auto& returnType = downcast<AST::NativeTypeDeclaration>(downcast<AST::NamedType>(nativeFunctionDeclaration.type().unifyNode())); >+ auto returnVectorLength = vectorLength(returnType); >+ >+ auto metalParameter1Name = typeNamer.mangledNameForType(*nativeFunctionDeclaration.parameters()[0]->type()); >+ auto metalParameter2Name = typeNamer.mangledNameForType(*nativeFunctionDeclaration.parameters()[1]->type()); >+ auto metalParameter3Name = typeNamer.mangledNameForType(locationType); >+ String metalParameter4Name; >+ if (nativeFunctionDeclaration.parameters().size() == 4) >+ metalParameter4Name = typeNamer.mangledNameForType(*nativeFunctionDeclaration.parameters()[3]->type()); >+ auto metalReturnName = typeNamer.mangledNameForType(returnType); >+ stringBuilder.append(makeString(metalReturnName, ' ', outputFunctionName, '(', metalParameter1Name, " theTexture, ", metalParameter2Name, " theSampler, ", metalParameter3Name, " location")); >+ if (!metalParameter4Name.isNull()) >+ stringBuilder.append(makeString(", ", metalParameter4Name, " offset")); >+ stringBuilder.append(") {\n"); >+ stringBuilder.append(" return theTexture.sample(theSampler, "); >+ if (textureType.isTextureArray()) { >+ ASSERT(locationVectorLength > 1); >+ stringBuilder.append(makeString("location.", "xyzw"_str.substring(0, locationVectorLength - 1), ", location.", "xyzw"_str.substring(locationVectorLength - 1, 1))); >+ } else >+ stringBuilder.append("location"); >+ if (!metalParameter4Name.isNull()) >+ stringBuilder.append(", offset"); >+ stringBuilder.append(")"); >+ if (!textureType.isDepthTexture()) >+ stringBuilder.append(makeString(".", "xyzw"_str.substring(0, returnVectorLength))); >+ stringBuilder.append(";\n"); >+ stringBuilder.append("}\n"); >+ return stringBuilder.toString(); > } > > if (nativeFunctionDeclaration.name() == "Load") { >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLIntrinsics.cpp b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLIntrinsics.cpp >index 0313dbcedca..a2aabbe45d8 100644 >--- a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLIntrinsics.cpp >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLIntrinsics.cpp >@@ -369,6 +369,8 @@ bool Intrinsics::addFullTexture(AST::NativeTypeDeclaration& nativeTypeDeclaratio > } > ASSERT(innerTypeIndex != WTF_ARRAY_LENGTH(m_textureInnerTypeNames)); > nativeTypeDeclaration.setIsTexture(); >+ if (textureTypeIndex >= indexOfFirstArrayType) >+ nativeTypeDeclaration.setIsTextureArray(); > m_fullTextures[textureTypeIndex][innerTypeIndex][vectorLength - 1] = &nativeTypeDeclaration; > return true; > } >@@ -391,6 +393,9 @@ bool Intrinsics::addDepthTexture(AST::NativeTypeDeclaration& nativeTypeDeclarati > auto innerTypeIndex = std::find(m_depthTextureInnerTypes, m_depthTextureInnerTypes + WTF_ARRAY_LENGTH(m_depthTextureInnerTypes), innerType.name()) - m_depthTextureInnerTypes; > ASSERT(innerTypeIndex != WTF_ARRAY_LENGTH(m_depthTextureInnerTypes)); > nativeTypeDeclaration.setIsTexture(); >+ if (texture == m_textureDepth2DArray || texture == m_rwTextureDepth2DArray) >+ nativeTypeDeclaration.setIsTextureArray(); >+ nativeTypeDeclaration.setIsDepthTexture(); > texture[innerTypeIndex] = &nativeTypeDeclaration; > return true; > } >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLIntrinsics.h b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLIntrinsics.h >index d23bf9787d8..30eda3f700a 100644 >--- a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLIntrinsics.h >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLIntrinsics.h >@@ -263,7 +263,10 @@ private: > AST::NativeTypeDeclaration* m_matrixHalf[3][3] {{ 0 }}; > AST::NativeTypeDeclaration* m_matrixFloat[3][3] {{ 0 }}; > >- static constexpr const char* m_textureTypeNames[] = { "Texture1D", "RWTexture1D", "Texture1DArray", "RWTexture1DArray", "Texture2D", "RWTexture2D", "Texture2DArray", "RWTexture2DArray", "Texture3D", "RWTexture3D", "TextureCube" }; >+ // Keep the array types partitioned from the non-array types. >+ // This is how we retain what's an array and what isn't. >+ static constexpr const char* m_textureTypeNames[] = { "Texture1D", "RWTexture1D", "Texture2D", "RWTexture2D", "Texture3D", "RWTexture3D", "TextureCube", "Texture1DArray", "RWTexture1DArray", "Texture2DArray", "RWTexture2DArray" }; >+ static constexpr unsigned indexOfFirstArrayType = 7; > > static constexpr const char* m_textureInnerTypeNames[] = { "uchar", "ushort", "uint", "char", "short", "int", "half", "float" }; > >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp >index 21ca18dcfa3..44a319559ac 100644 >--- a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp >@@ -56,6 +56,15 @@ NameResolver::NameResolver(NameContext& nameContext) > { > } > >+void NameResolver::visit(AST::NativeFunctionDeclaration& nativeFunctionDeclaration) >+{ >+ NameContext newNameContext(&m_nameContext); >+ NameResolver newNameResolver(newNameContext); >+ newNameResolver.Visitor::visit(nativeFunctionDeclaration); >+ if (newNameResolver.error()) >+ setError(); >+} >+ > void NameResolver::visit(AST::TypeReference& typeReference) > { > ScopedSetAdder<AST::TypeReference*> adder(m_typeReferences, &typeReference); >@@ -92,6 +101,8 @@ void NameResolver::visit(AST::FunctionDefinition& functionDefinition) > for (auto& parameter : functionDefinition.parameters()) > newNameResolver.checkErrorAndVisit(parameter); > newNameResolver.checkErrorAndVisit(functionDefinition.block()); >+ if (newNameResolver.error()) >+ setError(); > } > > void NameResolver::visit(AST::Block& block) >@@ -100,6 +111,8 @@ void NameResolver::visit(AST::Block& block) > NameResolver newNameResolver(nameContext); > newNameResolver.setCurrentFunctionDefinition(m_currentFunction); > newNameResolver.Visitor::visit(block); >+ if (newNameResolver.error()) >+ setError(); > } > > void NameResolver::visit(AST::IfStatement& ifStatement) >@@ -109,11 +122,15 @@ void NameResolver::visit(AST::IfStatement& ifStatement) > NameResolver newNameResolver(nameContext); > newNameResolver.setCurrentFunctionDefinition(m_currentFunction); > newNameResolver.checkErrorAndVisit(ifStatement.body()); >- if (ifStatement.elseBody()) { >+ if (newNameResolver.error()) >+ setError(); >+ else if (ifStatement.elseBody()) { > NameContext nameContext(&m_nameContext); > NameResolver newNameResolver(nameContext); > newNameResolver.setCurrentFunctionDefinition(m_currentFunction); > newNameResolver.checkErrorAndVisit(*ifStatement.elseBody()); >+ if (newNameResolver.error()) >+ setError(); > } > } > >@@ -124,6 +141,8 @@ void NameResolver::visit(AST::WhileLoop& whileLoop) > NameResolver newNameResolver(nameContext); > newNameResolver.setCurrentFunctionDefinition(m_currentFunction); > newNameResolver.checkErrorAndVisit(whileLoop.body()); >+ if (newNameResolver.error()) >+ setError(); > } > > void NameResolver::visit(AST::DoWhileLoop& whileLoop) >@@ -133,6 +152,8 @@ void NameResolver::visit(AST::DoWhileLoop& whileLoop) > newNameResolver.setCurrentFunctionDefinition(m_currentFunction); > newNameResolver.checkErrorAndVisit(whileLoop.body()); > checkErrorAndVisit(whileLoop.conditional()); >+ if (newNameResolver.error()) >+ setError(); > } > > void NameResolver::visit(AST::ForLoop& forLoop) >@@ -141,6 +162,8 @@ void NameResolver::visit(AST::ForLoop& forLoop) > NameResolver newNameResolver(nameContext); > newNameResolver.setCurrentFunctionDefinition(m_currentFunction); > newNameResolver.Visitor::visit(forLoop); >+ if (newNameResolver.error()) >+ setError(); > } > > void NameResolver::visit(AST::VariableDeclaration& variableDeclaration) >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.h b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.h >index 8fb4a34fbd4..b9ae0d7dca7 100644 >--- a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.h >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.h >@@ -64,6 +64,7 @@ private: > void visit(AST::DotExpression&) override; > void visit(AST::CallExpression&) override; > void visit(AST::EnumerationMemberLiteral&) override; >+ void visit(AST::NativeFunctionDeclaration&) override; > > NameContext& m_nameContext; > HashSet<AST::TypeReference*> m_typeReferences; >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt >index 5170e1aecd5..94e4ec2fdea 100644 >--- a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt >@@ -619,4 +619,234 @@ operator float4(float x, float y, float z, float w) { > return result; > } > >+operator float2(float x, float y) { >+ float2 result; >+ result.x = x; >+ result.y = y; >+ return result; >+} >+ >+native ushort Sample(Texture1D<ushort>, sampler, float location); >+native ushort Sample(Texture1DArray<ushort>, sampler, float2 location); >+native ushort Sample(Texture2D<ushort>, sampler, float2 location); >+native ushort Sample(Texture2D<ushort>, sampler, float2 location, int2 offset); >+native ushort Sample(Texture2DArray<ushort>, sampler, float3 location); >+native ushort Sample(Texture2DArray<ushort>, sampler, float3 location, int2 offset); >+native ushort Sample(Texture3D<ushort>, sampler, float3 location); >+native ushort Sample(Texture3D<ushort>, sampler, float3 location, int3 offset); >+native ushort Sample(TextureCube<ushort>, sampler, float3 location); >+native ushort2 Sample(Texture1D<ushort2>, sampler, float location); >+native ushort2 Sample(Texture1DArray<ushort2>, sampler, float2 location); >+native ushort2 Sample(Texture2D<ushort2>, sampler, float2 location); >+native ushort2 Sample(Texture2D<ushort2>, sampler, float2 location, int2 offset); >+native ushort2 Sample(Texture2DArray<ushort2>, sampler, float3 location); >+native ushort2 Sample(Texture2DArray<ushort2>, sampler, float3 location, int2 offset); >+native ushort2 Sample(Texture3D<ushort2>, sampler, float3 location); >+native ushort2 Sample(Texture3D<ushort2>, sampler, float3 location, int3 offset); >+native ushort2 Sample(TextureCube<ushort2>, sampler, float3 location); >+native ushort3 Sample(Texture1D<ushort3>, sampler, float location); >+native ushort3 Sample(Texture1DArray<ushort3>, sampler, float2 location); >+native ushort3 Sample(Texture2D<ushort3>, sampler, float2 location); >+native ushort3 Sample(Texture2D<ushort3>, sampler, float2 location, int2 offset); >+native ushort3 Sample(Texture2DArray<ushort3>, sampler, float3 location); >+native ushort3 Sample(Texture2DArray<ushort3>, sampler, float3 location, int2 offset); >+native ushort3 Sample(Texture3D<ushort3>, sampler, float3 location); >+native ushort3 Sample(Texture3D<ushort3>, sampler, float3 location, int3 offset); >+native ushort3 Sample(TextureCube<ushort3>, sampler, float3 location); >+native ushort4 Sample(Texture1D<ushort4>, sampler, float location); >+native ushort4 Sample(Texture1DArray<ushort4>, sampler, float2 location); >+native ushort4 Sample(Texture2D<ushort4>, sampler, float2 location); >+native ushort4 Sample(Texture2D<ushort4>, sampler, float2 location, int2 offset); >+native ushort4 Sample(Texture2DArray<ushort4>, sampler, float3 location); >+native ushort4 Sample(Texture2DArray<ushort4>, sampler, float3 location, int2 offset); >+native ushort4 Sample(Texture3D<ushort4>, sampler, float3 location); >+native ushort4 Sample(Texture3D<ushort4>, sampler, float3 location, int3 offset); >+native ushort4 Sample(TextureCube<ushort4>, sampler, float3 location); >+native uint Sample(Texture1D<uint>, sampler, float location); >+native uint Sample(Texture1DArray<uint>, sampler, float2 location); >+native uint Sample(Texture2D<uint>, sampler, float2 location); >+native uint Sample(Texture2D<uint>, sampler, float2 location, int2 offset); >+native uint Sample(Texture2DArray<uint>, sampler, float3 location); >+native uint Sample(Texture2DArray<uint>, sampler, float3 location, int2 offset); >+native uint Sample(Texture3D<uint>, sampler, float3 location); >+native uint Sample(Texture3D<uint>, sampler, float3 location, int3 offset); >+native uint Sample(TextureCube<uint>, sampler, float3 location); >+native uint2 Sample(Texture1D<uint2>, sampler, float location); >+native uint2 Sample(Texture1DArray<uint2>, sampler, float2 location); >+native uint2 Sample(Texture2D<uint2>, sampler, float2 location); >+native uint2 Sample(Texture2D<uint2>, sampler, float2 location, int2 offset); >+native uint2 Sample(Texture2DArray<uint2>, sampler, float3 location); >+native uint2 Sample(Texture2DArray<uint2>, sampler, float3 location, int2 offset); >+native uint2 Sample(Texture3D<uint2>, sampler, float3 location); >+native uint2 Sample(Texture3D<uint2>, sampler, float3 location, int3 offset); >+native uint2 Sample(TextureCube<uint2>, sampler, float3 location); >+native uint3 Sample(Texture1D<uint3>, sampler, float location); >+native uint3 Sample(Texture1DArray<uint3>, sampler, float2 location); >+native uint3 Sample(Texture2D<uint3>, sampler, float2 location); >+native uint3 Sample(Texture2D<uint3>, sampler, float2 location, int2 offset); >+native uint3 Sample(Texture2DArray<uint3>, sampler, float3 location); >+native uint3 Sample(Texture2DArray<uint3>, sampler, float3 location, int2 offset); >+native uint3 Sample(Texture3D<uint3>, sampler, float3 location); >+native uint3 Sample(Texture3D<uint3>, sampler, float3 location, int3 offset); >+native uint3 Sample(TextureCube<uint3>, sampler, float3 location); >+native uint4 Sample(Texture1D<uint4>, sampler, float location); >+native uint4 Sample(Texture1DArray<uint4>, sampler, float2 location); >+native uint4 Sample(Texture2D<uint4>, sampler, float2 location); >+native uint4 Sample(Texture2D<uint4>, sampler, float2 location, int2 offset); >+native uint4 Sample(Texture2DArray<uint4>, sampler, float3 location); >+native uint4 Sample(Texture2DArray<uint4>, sampler, float3 location, int2 offset); >+native uint4 Sample(Texture3D<uint4>, sampler, float3 location); >+native uint4 Sample(Texture3D<uint4>, sampler, float3 location, int3 offset); >+native uint4 Sample(TextureCube<uint4>, sampler, float3 location); >+native short Sample(Texture1D<short>, sampler, float location); >+native short Sample(Texture1DArray<short>, sampler, float2 location); >+native short Sample(Texture2D<short>, sampler, float2 location); >+native short Sample(Texture2D<short>, sampler, float2 location, int2 offset); >+native short Sample(Texture2DArray<short>, sampler, float3 location); >+native short Sample(Texture2DArray<short>, sampler, float3 location, int2 offset); >+native short Sample(Texture3D<short>, sampler, float3 location); >+native short Sample(Texture3D<short>, sampler, float3 location, int3 offset); >+native short Sample(TextureCube<short>, sampler, float3 location); >+native short2 Sample(Texture1D<short2>, sampler, float location); >+native short2 Sample(Texture1DArray<short2>, sampler, float2 location); >+native short2 Sample(Texture2D<short2>, sampler, float2 location); >+native short2 Sample(Texture2D<short2>, sampler, float2 location, int2 offset); >+native short2 Sample(Texture2DArray<short2>, sampler, float3 location); >+native short2 Sample(Texture2DArray<short2>, sampler, float3 location, int2 offset); >+native short2 Sample(Texture3D<short2>, sampler, float3 location); >+native short2 Sample(Texture3D<short2>, sampler, float3 location, int3 offset); >+native short2 Sample(TextureCube<short2>, sampler, float3 location); >+native short3 Sample(Texture1D<short3>, sampler, float location); >+native short3 Sample(Texture1DArray<short3>, sampler, float2 location); >+native short3 Sample(Texture2D<short3>, sampler, float2 location); >+native short3 Sample(Texture2D<short3>, sampler, float2 location, int2 offset); >+native short3 Sample(Texture2DArray<short3>, sampler, float3 location); >+native short3 Sample(Texture2DArray<short3>, sampler, float3 location, int2 offset); >+native short3 Sample(Texture3D<short3>, sampler, float3 location); >+native short3 Sample(Texture3D<short3>, sampler, float3 location, int3 offset); >+native short3 Sample(TextureCube<short3>, sampler, float3 location); >+native short4 Sample(Texture1D<short4>, sampler, float location); >+native short4 Sample(Texture1DArray<short4>, sampler, float2 location); >+native short4 Sample(Texture2D<short4>, sampler, float2 location); >+native short4 Sample(Texture2D<short4>, sampler, float2 location, int2 offset); >+native short4 Sample(Texture2DArray<short4>, sampler, float3 location); >+native short4 Sample(Texture2DArray<short4>, sampler, float3 location, int2 offset); >+native short4 Sample(Texture3D<short4>, sampler, float3 location); >+native short4 Sample(Texture3D<short4>, sampler, float3 location, int3 offset); >+native short4 Sample(TextureCube<short4>, sampler, float3 location); >+native int Sample(Texture1D<int>, sampler, float location); >+native int Sample(Texture1DArray<int>, sampler, float2 location); >+native int Sample(Texture2D<int>, sampler, float2 location); >+native int Sample(Texture2D<int>, sampler, float2 location, int2 offset); >+native int Sample(Texture2DArray<int>, sampler, float3 location); >+native int Sample(Texture2DArray<int>, sampler, float3 location, int2 offset); >+native int Sample(Texture3D<int>, sampler, float3 location); >+native int Sample(Texture3D<int>, sampler, float3 location, int3 offset); >+native int Sample(TextureCube<int>, sampler, float3 location); >+native int2 Sample(Texture1D<int2>, sampler, float location); >+native int2 Sample(Texture1DArray<int2>, sampler, float2 location); >+native int2 Sample(Texture2D<int2>, sampler, float2 location); >+native int2 Sample(Texture2D<int2>, sampler, float2 location, int2 offset); >+native int2 Sample(Texture2DArray<int2>, sampler, float3 location); >+native int2 Sample(Texture2DArray<int2>, sampler, float3 location, int2 offset); >+native int2 Sample(Texture3D<int2>, sampler, float3 location); >+native int2 Sample(Texture3D<int2>, sampler, float3 location, int3 offset); >+native int2 Sample(TextureCube<int2>, sampler, float3 location); >+native int3 Sample(Texture1D<int3>, sampler, float location); >+native int3 Sample(Texture1DArray<int3>, sampler, float2 location); >+native int3 Sample(Texture2D<int3>, sampler, float2 location); >+native int3 Sample(Texture2D<int3>, sampler, float2 location, int2 offset); >+native int3 Sample(Texture2DArray<int3>, sampler, float3 location); >+native int3 Sample(Texture2DArray<int3>, sampler, float3 location, int2 offset); >+native int3 Sample(Texture3D<int3>, sampler, float3 location); >+native int3 Sample(Texture3D<int3>, sampler, float3 location, int3 offset); >+native int3 Sample(TextureCube<int3>, sampler, float3 location); >+native int4 Sample(Texture1D<int4>, sampler, float location); >+native int4 Sample(Texture1DArray<int4>, sampler, float2 location); >+native int4 Sample(Texture2D<int4>, sampler, float2 location); >+native int4 Sample(Texture2D<int4>, sampler, float2 location, int2 offset); >+native int4 Sample(Texture2DArray<int4>, sampler, float3 location); >+native int4 Sample(Texture2DArray<int4>, sampler, float3 location, int2 offset); >+native int4 Sample(Texture3D<int4>, sampler, float3 location); >+native int4 Sample(Texture3D<int4>, sampler, float3 location, int3 offset); >+native int4 Sample(TextureCube<int4>, sampler, float3 location); >+native half Sample(Texture1D<half>, sampler, float location); >+native half Sample(Texture1DArray<half>, sampler, float2 location); >+native half Sample(Texture2D<half>, sampler, float2 location); >+native half Sample(Texture2D<half>, sampler, float2 location, int2 offset); >+native half Sample(Texture2DArray<half>, sampler, float3 location); >+native half Sample(Texture2DArray<half>, sampler, float3 location, int2 offset); >+native half Sample(Texture3D<half>, sampler, float3 location); >+native half Sample(Texture3D<half>, sampler, float3 location, int3 offset); >+native half Sample(TextureCube<half>, sampler, float3 location); >+native half2 Sample(Texture1D<half2>, sampler, float location); >+native half2 Sample(Texture1DArray<half2>, sampler, float2 location); >+native half2 Sample(Texture2D<half2>, sampler, float2 location); >+native half2 Sample(Texture2D<half2>, sampler, float2 location, int2 offset); >+native half2 Sample(Texture2DArray<half2>, sampler, float3 location); >+native half2 Sample(Texture2DArray<half2>, sampler, float3 location, int2 offset); >+native half2 Sample(Texture3D<half2>, sampler, float3 location); >+native half2 Sample(Texture3D<half2>, sampler, float3 location, int3 offset); >+native half2 Sample(TextureCube<half2>, sampler, float3 location); >+native half3 Sample(Texture1D<half3>, sampler, float location); >+native half3 Sample(Texture1DArray<half3>, sampler, float2 location); >+native half3 Sample(Texture2D<half3>, sampler, float2 location); >+native half3 Sample(Texture2D<half3>, sampler, float2 location, int2 offset); >+native half3 Sample(Texture2DArray<half3>, sampler, float3 location); >+native half3 Sample(Texture2DArray<half3>, sampler, float3 location, int2 offset); >+native half3 Sample(Texture3D<half3>, sampler, float3 location); >+native half3 Sample(Texture3D<half3>, sampler, float3 location, int3 offset); >+native half3 Sample(TextureCube<half3>, sampler, float3 location); >+native half4 Sample(Texture1D<half4>, sampler, float location); >+native half4 Sample(Texture1DArray<half4>, sampler, float2 location); >+native half4 Sample(Texture2D<half4>, sampler, float2 location); >+native half4 Sample(Texture2D<half4>, sampler, float2 location, int2 offset); >+native half4 Sample(Texture2DArray<half4>, sampler, float3 location); >+native half4 Sample(Texture2DArray<half4>, sampler, float3 location, int2 offset); >+native half4 Sample(Texture3D<half4>, sampler, float3 location); >+native half4 Sample(Texture3D<half4>, sampler, float3 location, int3 offset); >+native half4 Sample(TextureCube<half4>, sampler, float3 location); >+native float Sample(Texture1D<float>, sampler, float location); >+native float Sample(Texture1DArray<float>, sampler, float2 location); >+native float Sample(Texture2D<float>, sampler, float2 location); >+native float Sample(Texture2D<float>, sampler, float2 location, int2 offset); >+native float Sample(Texture2DArray<float>, sampler, float3 location); >+native float Sample(Texture2DArray<float>, sampler, float3 location, int2 offset); >+native float Sample(Texture3D<float>, sampler, float3 location); >+native float Sample(Texture3D<float>, sampler, float3 location, int3 offset); >+native float Sample(TextureCube<float>, sampler, float3 location); >+native float2 Sample(Texture1D<float2>, sampler, float location); >+native float2 Sample(Texture1DArray<float2>, sampler, float2 location); >+native float2 Sample(Texture2D<float2>, sampler, float2 location); >+native float2 Sample(Texture2D<float2>, sampler, float2 location, int2 offset); >+native float2 Sample(Texture2DArray<float2>, sampler, float3 location); >+native float2 Sample(Texture2DArray<float2>, sampler, float3 location, int2 offset); >+native float2 Sample(Texture3D<float2>, sampler, float3 location); >+native float2 Sample(Texture3D<float2>, sampler, float3 location, int3 offset); >+native float2 Sample(TextureCube<float2>, sampler, float3 location); >+native float3 Sample(Texture1D<float3>, sampler, float location); >+native float3 Sample(Texture1DArray<float3>, sampler, float2 location); >+native float3 Sample(Texture2D<float3>, sampler, float2 location); >+native float3 Sample(Texture2D<float3>, sampler, float2 location, int2 offset); >+native float3 Sample(Texture2DArray<float3>, sampler, float3 location); >+native float3 Sample(Texture2DArray<float3>, sampler, float3 location, int2 offset); >+native float3 Sample(Texture3D<float3>, sampler, float3 location); >+native float3 Sample(Texture3D<float3>, sampler, float3 location, int3 offset); >+native float3 Sample(TextureCube<float3>, sampler, float3 location); >+native float4 Sample(Texture1D<float4>, sampler, float location); >+native float4 Sample(Texture1DArray<float4>, sampler, float2 location); >+native float4 Sample(Texture2D<float4>, sampler, float2 location); >+native float4 Sample(Texture2D<float4>, sampler, float2 location, int2 offset); >+native float4 Sample(Texture2DArray<float4>, sampler, float3 location); >+native float4 Sample(Texture2DArray<float4>, sampler, float3 location, int2 offset); >+native float4 Sample(Texture3D<float4>, sampler, float3 location); >+native float4 Sample(Texture3D<float4>, sampler, float3 location, int3 offset); >+native float4 Sample(TextureCube<float4>, sampler, float3 location); >+native float Sample(TextureDepth2D<float>, sampler, float2 location); >+native float Sample(TextureDepth2D<float>, sampler, float2 location, int2 offset); >+native float Sample(TextureDepth2DArray<float>, sampler, float3 location); >+native float Sample(TextureDepth2DArray<float>, sampler, float3 location, int2 offset); >+native float Sample(TextureDepthCube<float>, sampler, float3 location); >+ >+ > // FIXME: https://bugs.webkit.org/show_bug.cgi?id=192890 Insert the rest of the standard library once the parser is fast enough >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupMetal.mm >index 6262e5f6d41..3e0c7d38ae1 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupMetal.mm >@@ -216,22 +216,22 @@ RefPtr<GPUBindGroup> GPUBindGroup::tryCreate(const GPUBindGroupDescriptor& descr > if (!samplerState) > return false; > if (isForVertex) >- setSamplerOnEncoder(vertexEncoder, samplerState, index); >+ setSamplerOnEncoder(vertexEncoder, samplerState, layoutBinding.internalName); > if (isForFragment) >- setSamplerOnEncoder(fragmentEncoder, samplerState, index); >+ setSamplerOnEncoder(fragmentEncoder, samplerState, layoutBinding.internalName); > if (isForCompute) >- setSamplerOnEncoder(computeEncoder, samplerState, index); >+ setSamplerOnEncoder(computeEncoder, samplerState, layoutBinding.internalName); > return true; > }, [&](GPUBindGroupLayout::SampledTexture&) -> bool { > auto textureResource = tryGetResourceAsTexture(resourceBinding.resource, functionName); > if (!textureResource) > return false; > if (isForVertex) >- setTextureOnEncoder(vertexEncoder, textureResource->platformTexture(), index); >+ setTextureOnEncoder(vertexEncoder, textureResource->platformTexture(), layoutBinding.internalName); > if (isForFragment) >- setTextureOnEncoder(fragmentEncoder, textureResource->platformTexture(), index); >+ setTextureOnEncoder(fragmentEncoder, textureResource->platformTexture(), layoutBinding.internalName); > if (isForCompute) >- setTextureOnEncoder(computeEncoder, textureResource->platformTexture(), index); >+ setTextureOnEncoder(computeEncoder, textureResource->platformTexture(), layoutBinding.internalName); > boundTextures.append(textureResource.releaseNonNull()); > return true; > }, [&](GPUBindGroupLayout::StorageBuffer& storageBuffer) -> bool {
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 198704
:
371723
|
371725
|
372024
|
372027
|
372105
|
372109
|
372115
|
372195
|
372234
|
372235
|
372238
|
372239
|
372316
|
372378
|
372421
|
372423
|
372470