REGRESSION: ( r246394 ) webgpu/whlsl-buffer-fragment.html and webgpu/whlsl-buffer...
[WebKit-https.git] / LayoutTests / webgpu / texture-triangle-strip.html
index 2f04694..cae04b5 100644 (file)
@@ -55,35 +55,29 @@ fragment float4 fragment_main(VertexOut v [[stage_in]], const device TextureSamp
 }
 `
 
-function createInputStateDescriptor() {
-    return {
-        indexFormat: "uint32",
-        attributes: [{
-            shaderLocation: positionAttributeNum,
-            inputSlot: positionBufferIndex,
-            offset: 0,
-            format: "float4"
-        }, {
-            shaderLocation: texCoordsAttributeNum,
-            inputSlot: texCoordsBufferIndex,
-            offset: 0,
-            format: "float2"
-        }],
-        inputs: [{
-            inputSlot: positionBufferIndex,
-            stride: 4 * 4,
-            stepMode: "vertex"
-        }, {
-            inputSlot: texCoordsBufferIndex,
-            stride: 4 * 2,
-            stepMode: "vertex"
+function createVertexInputDescriptor() {
+    var bufferDescriptors = [];
+    bufferDescriptors[positionBufferIndex] = {
+        stride: 4 * 4,
+        attributeSet: [{
+            format: "float4",
+            shaderLocation: positionAttributeNum
         }]
-    }
+    };
+    bufferDescriptors[texCoordsBufferIndex] = {
+        stride: 4 * 2,
+        attributeSet: [{
+            format: "float2",
+            shaderLocation: texCoordsAttributeNum
+        }]
+    };
+
+    return { vertexBuffers: bufferDescriptors };
 }
 
-async function test() {
-    const device = await getBasicDevice();
-    const canvas = document.querySelector("canvas");
+const canvas = document.querySelector("canvas");
+
+async function test(device) {
     const swapChain = createBasicSwapChain(canvas, device);
     // FIXME: Replace with non-MSL shaders.
     const shaderModule = device.createShaderModule({ code: shaderCode });
@@ -95,8 +89,7 @@ async function test() {
         1, 1, 0, 1, 
         1, -1, 0, 1
     ]);
-    const positionBuffer = device.createBuffer({ size: positionArray.byteLength, usage: GPUBufferUsage.VERTEX | GPUBufferUsage.TRANSFER_DST });
-    positionBuffer.setSubData(0, positionArray.buffer);
+    const positionBuffer = createBufferWithData(device, { size: positionArray.byteLength, usage: GPUBufferUsage.VERTEX }, positionArray.buffer);
 
     const texCoordsArray = new Float32Array([
         // float2 texCoords
@@ -105,10 +98,9 @@ async function test() {
         1, 0,
         1, 1
     ]);
-    const textureCoordBuffer = device.createBuffer({ size: texCoordsArray.byteLength, usage: GPUBufferUsage.VERTEX | GPUBufferUsage.TRANSFER_DST });
-    textureCoordBuffer.setSubData(0, texCoordsArray.buffer);
+    const textureCoordBuffer = createBufferWithData(device, { size: texCoordsArray.byteLength, usage: GPUBufferUsage.VERTEX }, texCoordsArray.buffer);
 
-    const inputStateDescriptor = createInputStateDescriptor();
+    const vertexInputDescriptor = createVertexInputDescriptor();
 
     // Load texture image
     const image = new Image();
@@ -128,10 +120,9 @@ async function test() {
 
     const textureBufferDescriptor = {
         size: imageData.data.length,
-        usage: GPUBufferUsage.TRANSFER_SRC | GPUBufferUsage.TRANSFER_DST
+        usage: GPUBufferUsage.TRANSFER_SRC
     };
-    const textureBuffer = device.createBuffer(textureBufferDescriptor);
-    textureBuffer.setSubData(0, imageData.data.buffer);
+    const textureBuffer = createBufferWithData(device, textureBufferDescriptor, imageData.data.buffer);
 
     // Create GPUTexture
     const textureSize = {
@@ -142,10 +133,6 @@ async function test() {
 
     const textureDescriptor = {
         size: { width: image.width, height: image.height, depth: 1 },
-        arrayLayerCount: 1,
-        mipLevelCount: 1,
-        sampleCount: 1,
-        dimension: "2d",
         format: "rgba8unorm",
         usage: GPUTextureUsage.TRANSFER_DST | GPUTextureUsage.SAMPLED
     };
@@ -185,21 +172,15 @@ async function test() {
     const bindGroup = device.createBindGroup(bindGroupDescriptor);
 
     // Pipeline and render
-    const pipeline = createBasicPipeline(shaderModule, device, pipelineLayout, inputStateDescriptor);
+    const pipeline = createBasicPipeline(shaderModule, device, null, pipelineLayout, vertexInputDescriptor);
     const commandEncoder = device.createCommandEncoder();
 
     const bufferCopyView = {
         buffer: textureBuffer,
-        offset: 0,
         rowPitch: image.width * 4,
         imageHeight: 0
     };
-    const textureCopyView = {
-        texture: texture,
-        mipLevel: 0,
-        arrayLayer: 0,
-        origin: { x: 0, y: 0, z: 0 }
-    };
+    const textureCopyView = { texture: texture };
     commandEncoder.copyBufferToTexture(bufferCopyView, textureCopyView, textureSize);
     const passEncoder = beginBasicRenderPass(swapChain, commandEncoder);
     passEncoder.setPipeline(pipeline);
@@ -213,10 +194,19 @@ async function test() {
     positionBuffer.destroy();
     textureCoordBuffer.destroy();
     texture.destroy();
+}
 
+getBasicDevice().then(function(device) {
+    test(device).then(function() {
+        if (window.testRunner)
+            testRunner.notifyDone();
+    }, function() {
+        if (window.testRunner)
+            testRunner.notifyDone();
+    });
+}, function() {
+    drawGreenAndBlueCheckerboardInSoftware(canvas);
     if (window.testRunner)
         testRunner.notifyDone();
-}
-
-test();
-</script>
\ No newline at end of file
+});
+</script>