Title: [245662] trunk
Revision
245662
Author
[email protected]
Date
2019-05-22 17:33:45 -0700 (Wed, 22 May 2019)

Log Message

WHLSL: fix enum parsing
https://bugs.webkit.org/show_bug.cgi?id=198087

Reviewed by Myles Maxfield.

Source/WebCore:

This fixes two bugs:

1. We were using a String by reference after moving the underlying owner of
the string. This would lead to the String becoming the empty value, and
crashing when used as a key in a hash map.
2. We were incorrectly producing a syntax error for enum declarations by
saying it's invalid if an enum value was added to a hash map for the first
time. This logic should be negated. We need to error when it's added for
the second time and onwards.

Test: webgpu/whlsl-dont-crash-parsing-enum.html

* Modules/webgpu/WHLSL/AST/WHLSLAST.h: Replaced.
* Modules/webgpu/WHLSL/AST/WHLSLEnumerationDefinition.h:
(WebCore::WHLSL::AST::EnumerationDefinition::add):
* Modules/webgpu/WHLSL/AST/WHLSLEnumerationMember.h:
(WebCore::WHLSL::AST::EnumerationMember::name):
* Modules/webgpu/WHLSL/WHLSLASTDumper.cpp: Replaced.
(WebCore::WHLSL::ASTDumper::visit):
* Modules/webgpu/WHLSL/WHLSLASTDumper.h: Replaced.

LayoutTests:

* webgpu/whlsl-dont-crash-parsing-enum-expected.html: Added.
* webgpu/whlsl-dont-crash-parsing-enum.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (245661 => 245662)


--- trunk/LayoutTests/ChangeLog	2019-05-23 00:30:23 UTC (rev 245661)
+++ trunk/LayoutTests/ChangeLog	2019-05-23 00:33:45 UTC (rev 245662)
@@ -1,3 +1,13 @@
+2019-05-22  Saam barati  <[email protected]>
+
+        WHLSL: fix enum parsing
+        https://bugs.webkit.org/show_bug.cgi?id=198087
+
+        Reviewed by Myles Maxfield.
+
+        * webgpu/whlsl-dont-crash-parsing-enum-expected.html: Added.
+        * webgpu/whlsl-dont-crash-parsing-enum.html: Added.
+
 2019-05-22  Ryosuke Niwa  <[email protected]>
 
         REGRESSION(r245148): Removing inputmode="none" does not bring up software keyboard

Added: trunk/LayoutTests/webgpu/whlsl-dont-crash-parsing-enum-expected.html (0 => 245662)


--- trunk/LayoutTests/webgpu/whlsl-dont-crash-parsing-enum-expected.html	                        (rev 0)
+++ trunk/LayoutTests/webgpu/whlsl-dont-crash-parsing-enum-expected.html	2019-05-23 00:33:45 UTC (rev 245662)
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+<canvas id="canvas" width="400" height="400"></canvas>
+<script>
+async function start() {
+    const canvas = document.getElementById("canvas");
+    const context = canvas.getContext("2d");
+    context.fillStyle = "blue";
+    context.fillRect(0, 0, 400, 400);
+    context.fillStyle = "white";
+    context.fillRect(100, 100, 200, 200);
+}
+window.addEventListener("load", start);
+</script>
+</body>
+</html>

Added: trunk/LayoutTests/webgpu/whlsl-dont-crash-parsing-enum.html (0 => 245662)


--- trunk/LayoutTests/webgpu/whlsl-dont-crash-parsing-enum.html	                        (rev 0)
+++ trunk/LayoutTests/webgpu/whlsl-dont-crash-parsing-enum.html	2019-05-23 00:33:45 UTC (rev 245662)
@@ -0,0 +1,125 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+<canvas id="canvas" width="400" height="400"></canvas>
+<script>
+const shaderSource = `
+
+enum DontCrash {
+    Value
+}
+
+vertex float4 vertexShader(float4 position : attribute(0), float i : attribute(1)) : SV_Position {
+    return position;
+}
+
+fragment float4 fragmentShader(float4 position : SV_Position) : SV_Target 0 {
+    return position;
+}
+`;
+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, inputSlot: 0, format: "float4"};
+    const attribute1 = {shaderLocation: 1, inputSlot: 1, format: "float"};
+    const attributes = [attribute0, attribute1];
+    const input0 = {inputSlot: 0, stride: 16 };
+    const input1 = {inputSlot: 1, stride: 4 };
+    const inputs = [input0, input1];
+    const inputState = {indexFormat: "uint32", attributes, inputs};
+
+    const bindGroupLayoutDescriptor = {bindings: [{binding: 0, visibility: 7, type: "uniform-buffer"}]};
+    const bindGroupLayout = device.createBindGroupLayout(bindGroupLayoutDescriptor);
+    const pipelineLayoutDescriptor = {bindGroupLayouts: [bindGroupLayout]};
+    const pipelineLayout = device.createPipelineLayout(pipelineLayoutDescriptor);
+
+    const renderPipelineDescriptor = {vertexStage, fragmentStage, primitiveTopology, rasterizationState, colorStates, depthStencilState, inputState, 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 vertexBuffer1Descriptor = {size: Float32Array.BYTES_PER_ELEMENT * 4, usage: GPUBufferUsage.VERTEX | GPUBufferUsage.MAP_WRITE};
+    const vertexBuffer1 = device.createBuffer(vertexBuffer1Descriptor);
+    const vertexBuffer1ArrayBuffer = await vertexBuffer1.mapWriteAsync();
+    const vertexBuffer1Float32Array = new Float32Array(vertexBuffer1ArrayBuffer);
+    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};
+    const resourceBuffer = device.createBuffer(resourceBufferDescriptor);
+    const resourceBufferArrayBuffer = await resourceBuffer.mapWriteAsync();
+    const resourceBufferFloat32Array = new Float32Array(resourceBufferArrayBuffer);
+    resourceBufferFloat32Array[0] = 1;
+    resourceBuffer.unmap();
+
+    const bufferBinding = {buffer: resourceBuffer, size: 4};
+    const bindGroupBinding = {binding: 0, resource: bufferBinding};
+    const bindGroupDescriptor = {layout: bindGroupLayout, bindings: [bindGroupBinding]};
+    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 red = {r: 0, g: 0, b: 1, a: 1};
+    const colorAttachments = [{attachment: outputTextureView, resolveTarget: null, loadOp: "clear", storeOp: "store", clearColor: red}];
+    const depthStencilAttachment = null;
+    const renderPassDescriptor = {colorAttachments, depthStencilAttachment};
+    const renderPassEncoder = commandEncoder.beginRenderPass(renderPassDescriptor);
+    renderPassEncoder.setPipeline(renderPipeline);
+    renderPassEncoder.setBindGroup(0, bindGroup);
+    renderPassEncoder.setVertexBuffers(0, [vertexBuffer0, vertexBuffer1], [0, 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>

Modified: trunk/Source/WebCore/ChangeLog (245661 => 245662)


--- trunk/Source/WebCore/ChangeLog	2019-05-23 00:30:23 UTC (rev 245661)
+++ trunk/Source/WebCore/ChangeLog	2019-05-23 00:33:45 UTC (rev 245662)
@@ -1,3 +1,31 @@
+2019-05-22  Saam barati  <[email protected]>
+
+        WHLSL: fix enum parsing
+        https://bugs.webkit.org/show_bug.cgi?id=198087
+
+        Reviewed by Myles Maxfield.
+
+        This fixes two bugs:
+        
+        1. We were using a String by reference after moving the underlying owner of
+        the string. This would lead to the String becoming the empty value, and
+        crashing when used as a key in a hash map.
+        2. We were incorrectly producing a syntax error for enum declarations by
+        saying it's invalid if an enum value was added to a hash map for the first
+        time. This logic should be negated. We need to error when it's added for
+        the second time and onwards.
+
+        Test: webgpu/whlsl-dont-crash-parsing-enum.html
+
+        * Modules/webgpu/WHLSL/AST/WHLSLAST.h: Replaced.
+        * Modules/webgpu/WHLSL/AST/WHLSLEnumerationDefinition.h:
+        (WebCore::WHLSL::AST::EnumerationDefinition::add):
+        * Modules/webgpu/WHLSL/AST/WHLSLEnumerationMember.h:
+        (WebCore::WHLSL::AST::EnumerationMember::name):
+        * Modules/webgpu/WHLSL/WHLSLASTDumper.cpp: Replaced.
+        (WebCore::WHLSL::ASTDumper::visit):
+        * Modules/webgpu/WHLSL/WHLSLASTDumper.h: Replaced.
+
 2019-05-22  Simon Fraser  <[email protected]>
 
         Fix scrolling tree state for more obscure combinations of positioning and paint order

Modified: trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLEnumerationDefinition.h (245661 => 245662)


--- trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLEnumerationDefinition.h	2019-05-23 00:30:23 UTC (rev 245661)
+++ trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLEnumerationDefinition.h	2019-05-23 00:33:45 UTC (rev 245662)
@@ -64,7 +64,7 @@
     bool add(EnumerationMember&& member)
     {
         auto result = m_members.add(member.name(), std::make_unique<EnumerationMember>(WTFMove(member)));
-        return !result.isNewEntry;
+        return result.isNewEntry;
     }
 
     EnumerationMember* memberByName(const String& name)

Modified: trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLEnumerationMember.h (245661 => 245662)


--- trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLEnumerationMember.h	2019-05-23 00:30:23 UTC (rev 245661)
+++ trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLEnumerationMember.h	2019-05-23 00:33:45 UTC (rev 245662)
@@ -55,7 +55,7 @@
     EnumerationMember(EnumerationMember&&) = default;
 
     const Lexer::Token& origin() const { return m_origin; }
-    String& name() { return m_name; }
+    String name() { return m_name; }
     Optional<ConstantExpression>& value() { return m_value; }
 
     void setValue(ConstantExpression&& value)

Modified: trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLASTDumper.cpp (245661 => 245662)


--- trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLASTDumper.cpp	2019-05-23 00:30:23 UTC (rev 245661)
+++ trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLASTDumper.cpp	2019-05-23 00:33:45 UTC (rev 245662)
@@ -111,10 +111,7 @@
 
 void ASTDumper::visit(AST::EnumerationDefinition& enumerationDefinition)
 {
-    // FIXME: Test this once we parse enums:
-    // https://bugs.webkit.org/show_bug.cgi?id=198087
-
-    m_out.println(m_indent, "enum ");
+    m_out.print(m_indent, "enum ");
     visit(enumerationDefinition.type());
     m_out.print(" {");
 
@@ -339,10 +336,9 @@
 {
 }
 
-void ASTDumper::visit(AST::EnumerationMemberLiteral&)
+void ASTDumper::visit(AST::EnumerationMemberLiteral& enumerationMemberLiteral)
 {
-    // FIXME: Handle this when we can parse enums:
-    // https://bugs.webkit.org/show_bug.cgi?id=198087
+    m_out.print(enumerationMemberLiteral.left(), ".", enumerationMemberLiteral.right());
 }
 
 void ASTDumper::visit(AST::FunctionAttribute& functionAttribute)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to