| <!-- webkit-test-runner [ enableMetalShaderValidation=true ] --> |
| <script src="../../../resources/js-test.js"></script> |
| <script> |
| window.jsTestIsAsync = true; |
| |
| async function run() { |
| const adapter = await navigator.gpu.requestAdapter(); |
| const device = await adapter.requestDevice(); |
| const queue = device.queue; |
| |
| const indexBuffer = device.createBuffer({ size: 24, usage: GPUBufferUsage.INDEX | GPUBufferUsage.COPY_DST }); |
| const vbufSmall = device.createBuffer({ size: 3 * 16, usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST }); |
| const vbufBig = device.createBuffer({ size: 200 * 16, usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST }); |
| const tex = device.createTexture({ size: [4, 4], format: 'bgra8unorm', usage: GPUTextureUsage.RENDER_ATTACHMENT }); |
| |
| const module = device.createShaderModule({ |
| code: ` |
| @vertex fn vs(@location(0) p : vec4f) -> @builtin(position) vec4f { return p; } |
| @fragment fn fs() -> @location(0) vec4f { return vec4f(1.0); } |
| ` |
| }); |
| const pipe = device.createRenderPipeline({ |
| layout: 'auto', |
| vertex: { module, entryPoint: 'vs', buffers: [{ arrayStride: 16, stepMode: 'vertex', attributes: [{ shaderLocation: 0, offset: 0, format: 'float32x4' }] }] }, |
| fragment: { module, entryPoint: 'fs', targets: [{ format: 'bgra8unorm' }] }, |
| primitive: { topology: 'triangle-list' } |
| }); |
| |
| const rpDesc = () => ({ colorAttachments: [{ view: tex.createView(), loadOp: 'clear', storeOp: 'store', clearValue: [0, 0, 0, 0] }] }); |
| |
| queue.writeBuffer(indexBuffer, 0, new Uint32Array([0, 1, 2, 100, 101, 102])); |
| const encZ = device.createCommandEncoder(); |
| const pZ = encZ.beginRenderPass(rpDesc()); |
| pZ.setPipeline(pipe); |
| pZ.setIndexBuffer(indexBuffer, 'uint32'); |
| pZ.setVertexBuffer(0, vbufSmall); |
| pZ.drawIndexed(3, 1, 0, 0, 0); |
| pZ.setVertexBuffer(0, vbufBig); |
| pZ.drawIndexed(3, 1, 3, 0, 0); |
| pZ.end(); |
| queue.submit([encZ.finish()]); |
| await queue.onSubmittedWorkDone(); |
| |
| const encA = device.createCommandEncoder(); |
| const pA = encA.beginRenderPass(rpDesc()); |
| pA.setPipeline(pipe); |
| pA.setIndexBuffer(indexBuffer, 'uint32'); |
| pA.setVertexBuffer(0, vbufSmall); |
| pA.drawIndexed(3, 1, 0, 0, 0); |
| pA.end(); |
| const cbA = encA.finish(); |
| |
| const encB = device.createCommandEncoder(); |
| const pB = encB.beginRenderPass(rpDesc()); |
| pB.setPipeline(pipe); |
| pB.setIndexBuffer(indexBuffer, 'uint32'); |
| pB.setVertexBuffer(0, vbufBig); |
| pB.drawIndexed(3, 1, 3, 0, 0); |
| pB.end(); |
| const cbB = encB.finish(); |
| |
| const BIG = 0x00100000; |
| queue.writeBuffer(indexBuffer, 0, new Uint32Array([0, 1, 2, BIG, BIG + 1, BIG + 2])); |
| |
| queue.submit([cbA, cbB]); |
| await queue.onSubmittedWorkDone(); |
| debug('Pass'); |
| } |
| |
| run().catch(e => debug('Error: ' + e)).finally(finishJSTest); |
| </script> |