Fix some WebGPU demos
authordino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Nov 2019 20:16:12 +0000 (20:16 +0000)
committerdino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Nov 2019 20:16:12 +0000 (20:16 +0000)
https://bugs.webkit.org/show_bug.cgi?id=204167
Source/WebCore:

<rdar://problem/57160316>

Reviewed by Myles C. Maxfield.

Add a note referencing a bug I detected while fixing this demo.
And a drive-by typo.

* Modules/webgpu/WebGPUBuffer.cpp:
(WebCore::WebGPUBuffer::rejectOrRegisterPromiseCallback):
* platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm:
(WebCore::GPUCommandBuffer::copyBufferToTexture):

Websites/webkit.org:

Reviewed by Myles C. Maxfield.

Use COPY_ rather than TRANSFER_.

* demos/webgpu/babylon/babylonWebGpu.max.js:
* demos/webgpu/babylon/oneSphereWebGPU.html:
* demos/webgpu/hello-cube.html:
* demos/webgpu/scripts/compute-boids-compile.js:
* demos/webgpu/scripts/compute-boids-utils.js:
(async.createTextureFromImage):
* demos/webgpu/textured-cube.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@252423 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/Modules/webgpu/WebGPUBuffer.cpp
Source/WebCore/platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm
Websites/webkit.org/ChangeLog
Websites/webkit.org/demos/webgpu/babylon/babylonWebGpu.max.js
Websites/webkit.org/demos/webgpu/babylon/oneSphereWebGPU.html
Websites/webkit.org/demos/webgpu/hello-cube.html
Websites/webkit.org/demos/webgpu/scripts/compute-boids-compile.js
Websites/webkit.org/demos/webgpu/scripts/compute-boids-utils.js
Websites/webkit.org/demos/webgpu/textured-cube.html

index 0efe289..be0e497 100644 (file)
@@ -1,3 +1,19 @@
+2019-11-13  Dean Jackson  <dino@apple.com>
+
+        Fix some WebGPU demos
+        https://bugs.webkit.org/show_bug.cgi?id=204167
+        <rdar://problem/57160316>
+
+        Reviewed by Myles C. Maxfield.
+
+        Add a note referencing a bug I detected while fixing this demo.
+        And a drive-by typo.
+
+        * Modules/webgpu/WebGPUBuffer.cpp:
+        (WebCore::WebGPUBuffer::rejectOrRegisterPromiseCallback):
+        * platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm:
+        (WebCore::GPUCommandBuffer::copyBufferToTexture):
+
 2019-11-13  Antti Koivisto  <antti@apple.com>
 
         Google Docs spreadsheet tiles render very slowly (because of event region painting)
index 41f4168..1066264 100644 (file)
@@ -91,6 +91,9 @@ void WebGPUBuffer::rejectOrRegisterPromiseCallback(BufferMappingPromise&& promis
         if (arrayBuffer)
             promise.resolve(*arrayBuffer);
         else {
+            // FIXME: It's possible to hit this code path in response to an unmap call, where
+            // the ArrayBuffer will definitely be null, and thus an out of memory error makes no sense.
+            // https://bugs.webkit.org/show_bug.cgi?id=204166
             protectedErrorScopes->generateError("", GPUErrorFilter::OutOfMemory);
             promise.reject();
         }
index 691f9e6..367d63d 100644 (file)
@@ -135,7 +135,7 @@ void GPUCommandBuffer::copyBufferToBuffer(Ref<GPUBuffer>&& src, uint64_t srcOffs
 void GPUCommandBuffer::copyBufferToTexture(GPUBufferCopyView&& srcBuffer, GPUTextureCopyView&& dstTexture, const GPUExtent3D& size)
 {
     if (isEncodingPass() || !srcBuffer.buffer->isCopySource() || !dstTexture.texture->isCopyDestination()) {
-        LOG(WebGPU, "GPUComandBuffer::copyBufferToTexture(): Invalid operation!");
+        LOG(WebGPU, "GPUCommandBuffer::copyBufferToTexture(): Invalid operation!");
         return;
     }
 
index 7e225f5..53ae0f4 100644 (file)
@@ -1,3 +1,20 @@
+2019-11-13  Dean Jackson  <dino@apple.com>
+
+        Fix some WebGPU demos
+        https://bugs.webkit.org/show_bug.cgi?id=204167
+
+        Reviewed by Myles C. Maxfield.
+
+        Use COPY_ rather than TRANSFER_.
+
+        * demos/webgpu/babylon/babylonWebGpu.max.js:
+        * demos/webgpu/babylon/oneSphereWebGPU.html:
+        * demos/webgpu/hello-cube.html:
+        * demos/webgpu/scripts/compute-boids-compile.js:
+        * demos/webgpu/scripts/compute-boids-utils.js:
+        (async.createTextureFromImage):
+        * demos/webgpu/textured-cube.html:
+
 2019-11-08  Ryosuke Niwa  <rniwa@webkit.org>
 
         Add punctuation rules for C++ lambdas
index d7b13a4..55f50c2 100644 (file)
@@ -32945,8 +32945,8 @@ var WebGPUConstants = /** @class */ (function () {
     WebGPUConstants.GPUBufferUsage_NONE = 0;
     WebGPUConstants.GPUBufferUsage_MAP_READ = 1;
     WebGPUConstants.GPUBufferUsage_MAP_WRITE = 2;
-    WebGPUConstants.GPUBufferUsage_TRANSFER_SRC = 4;
-    WebGPUConstants.GPUBufferUsage_TRANSFER_DST = 8;
+    WebGPUConstants.GPUBufferUsage_COPY_SRC = 4;
+    WebGPUConstants.GPUBufferUsage_COPY_DST = 8;
     WebGPUConstants.GPUBufferUsage_INDEX = 16;
     WebGPUConstants.GPUBufferUsage_VERTEX = 32;
     WebGPUConstants.GPUBufferUsage_UNIFORM = 64;
@@ -42295,7 +42295,7 @@ var WebGPUEngine = /** @class */ (function (_super) {
         // TODO WEBGPU. Deprecated soon to be removed... replace by mappedBuffers
         var bufferDescriptor = {
             size: byteLength,
-            usage: _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_MAP_WRITE | _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_TRANSFER_SRC
+            usage: _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_MAP_WRITE | _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_COPY_SRC
         };
         var [tempBuffer, arr] = this._device.createBufferMapped(bufferDescriptor);
         var uint8Src = new Uint8Array(src.buffer, src.byteOffset);
@@ -42323,7 +42323,7 @@ var WebGPUEngine = /** @class */ (function (_super) {
         else {
             view = data;
         }
-        var dataBuffer = this._createBuffer(view, _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_VERTEX | _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_TRANSFER_DST);
+        var dataBuffer = this._createBuffer(view, _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_VERTEX | _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_COPY_DST);
         return dataBuffer;
     };
     WebGPUEngine.prototype.createDynamicVertexBuffer = function (data) {
@@ -42379,7 +42379,7 @@ var WebGPUEngine = /** @class */ (function (_super) {
                 is32Bits = false;
             }
         }
-        var dataBuffer = this._createBuffer(view, _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_INDEX | _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_TRANSFER_DST);
+        var dataBuffer = this._createBuffer(view, _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_INDEX | _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_COPY_DST);
         dataBuffer.is32Bits = is32Bits;
         return dataBuffer;
     };
@@ -42443,7 +42443,7 @@ var WebGPUEngine = /** @class */ (function (_super) {
         else {
             view = elements;
         }
-        var dataBuffer = this._createBuffer(view, _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_UNIFORM | _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_TRANSFER_DST);
+        var dataBuffer = this._createBuffer(view, _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_UNIFORM | _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_COPY_DST);
         return dataBuffer;
     };
     WebGPUEngine.prototype.createDynamicUniformBuffer = function (elements) {
@@ -42664,7 +42664,7 @@ var WebGPUEngine = /** @class */ (function (_super) {
         var rowPitch = Math.ceil(width * 4 / 256) * 256;
         var dataBuffer;
         if (rowPitch == width * 4) {
-            dataBuffer = this._createBuffer(pixels, _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_TRANSFER_SRC | _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_TRANSFER_DST);
+            dataBuffer = this._createBuffer(pixels, _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_COPY_SRC | _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_COPY_DST);
             var bufferView = {
                 buffer: dataBuffer.underlyingResource,
                 rowPitch: rowPitch,
@@ -42686,7 +42686,7 @@ var WebGPUEngine = /** @class */ (function (_super) {
                     pixelsIndex += 4;
                 }
             }
-            dataBuffer = this._createBuffer(alignedPixels, _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_TRANSFER_SRC | _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_TRANSFER_DST);
+            dataBuffer = this._createBuffer(alignedPixels, _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_COPY_SRC | _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_COPY_DST);
             var bufferView = {
                 buffer: dataBuffer.underlyingResource,
                 rowPitch: rowPitch,
@@ -42760,7 +42760,7 @@ var WebGPUEngine = /** @class */ (function (_super) {
         var rowPitch = Math.ceil(width * 4 / 256) * 256;
         var dataBuffer;
         if (rowPitch == width * 4) {
-            dataBuffer = this._createBuffer(pixels, _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_TRANSFER_SRC | _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_TRANSFER_DST);
+            dataBuffer = this._createBuffer(pixels, _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_COPY_SRC | _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_COPY_DST);
             var bufferView = {
                 buffer: dataBuffer.underlyingResource,
                 rowPitch: rowPitch,
@@ -42782,7 +42782,7 @@ var WebGPUEngine = /** @class */ (function (_super) {
                     pixelsIndex += 4;
                 }
             }
-            dataBuffer = this._createBuffer(alignedPixels, _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_TRANSFER_SRC | _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_TRANSFER_DST);
+            dataBuffer = this._createBuffer(alignedPixels, _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_COPY_SRC | _WebGPU_webgpuConstants__WEBPACK_IMPORTED_MODULE_9__["WebGPUConstants"].GPUBufferUsage_COPY_DST);
             var bufferView = {
                 buffer: dataBuffer.underlyingResource,
                 rowPitch: rowPitch,
index 0255a46..60f2e3e 100644 (file)
             scene.render();
             divFps.innerHTML = engine.getFps().toFixed() + " fps";
         });
+        setTimeout(() => {
+            engine.stopRenderLoop();
+        }, 2000);
     })();
     </script>
 </body>
index d28597a..e8a7e9a 100644 (file)
@@ -147,7 +147,7 @@ async function init() {
 
     const verticesBufferDescriptor = { 
         size: verticesArray.byteLength, 
-        usage: GPUBufferUsage.VERTEX | GPUBufferUsage.TRANSFER_DST
+        usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST
     };
     let verticesArrayBuffer;
     [verticesBuffer, verticesArrayBuffer] = device.createBufferMapped(verticesBufferDescriptor);
index 66df36c..0b64ec5 100644 (file)
@@ -205,8 +205,8 @@ function appendMessage(msg) {
 
 async function init() {
     if (!isChrome) {
-        GPUBufferUsage.COPY_DST = GPUBufferUsage.TRANSFER_DST;
-        GPUBufferUsage.COPY_SRC = GPUBufferUsage.TRANSFER_SRC;
+        GPUBufferUsage.COPY_DST = GPUBufferUsage.COPY_DST;
+        GPUBufferUsage.COPY_SRC = GPUBufferUsage.COPY_SRC;
     }
 
     const adapter = await navigator.gpu.requestAdapter();
index ad6ba4a..342568e 100644 (file)
         sampleCount: 1,
         dimension: "2d",
         format: "rgba8unorm",
-        usage: GPUTextureUsage.TRANSFER_DST | usage,
+        usage: GPUTextureUsage.COPY_DST | usage,
       });
 
       const textureDataBuffer = device.createBuffer({
         size: data.byteLength,
-        usage: GPUBufferUsage.TRANSFER_DST | GPUBufferUsage.TRANSFER_SRC,
+        usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.COPY_SRC,
       });
 
       textureDataBuffer.setSubData(0, data);
index fb0c522..274b66e 100644 (file)
@@ -80,6 +80,8 @@ fragment float4 fragment_main(
 }
 `;
 
+//console.log(`Shader is: ${shader}`);
+
 let device, swapChain, verticesBuffer, bindGroupLayout, pipeline, renderPassDescriptor, queue, textureViewBinding, samplerBinding;
 let projectionMatrix = mat4.create();
 
@@ -134,6 +136,10 @@ async function init() {
     const adapter = await navigator.gpu.requestAdapter();
     device = await adapter.requestDevice();
 
+    device.onuncapturederror = function (e) {
+        console.log(`ERROR:`, e);
+    };
+
     const canvas = document.querySelector('canvas');
 
     const aspect = Math.abs(canvas.width / canvas.height);
@@ -204,7 +210,7 @@ async function init() {
         sampleCount: 1,
         dimension: "2d",
         format: "rgba8unorm",
-        usage: GPUTextureUsage.TRANSFER_DST | GPUTextureUsage.SAMPLED
+        usage: GPUTextureUsage.COPY_DST | GPUTextureUsage.SAMPLED
     };
     const texture = device.createTexture(textureDescriptor);