Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/dom/webgpu/tests/reftest/   (Firefox Browser Version 153.0.1©)  Datei vom 27.6.2026 mit Größe 5 kB image not shown  

Quelle  draw-storage.html

  Sprache: HTML
 

 products/Sources/formale Sprachen/C/Firefox/dom/webgpu/tests/reftest/draw-storage.html


<!doctype html>

<!-- Render a triangle to a storage texture. The triangle should be displayed.
     Regression test for https://bugzilla.mozilla.org/show_bug.cgi?id=1972921. -->


<html class="reftest-wait">
  <head>
    <meta charset="utf-8" />
  </head>
  <body>
    <canvas id="canvas" width=512 height=512></canvas>
  </body>
  <script>
    (async function() {
      try {
        var triangleVertWGSL = `@vertex
        fn main(
          @builtin(vertex_index) VertexIndex : u32
        ) -> @builtin(position) vec4f {
          var pos = array<vec2f, 3>(
            vec2(0.03.0),
            vec2(-2.0, -1.0),
            vec2(2.0, -1.0)
          );

          return vec4f(pos[VertexIndex], 0.01.0);
        }
        `;

        var redFragWGSL = `
        @group(0) @binding(0var output: texture_storage_2d<{PRESENTATION_FORMAT}, write>;

        @fragment
        fn main(@builtin(position) pos: vec4f) -> @location(0) vec4f {
          let x = i32(pos.x);
          let y = i32(pos.y);
          if (y >= 128 && y < 384 && 2 * x >= 640 - y && 2 * x < 384 + y) {
            textureStore(output, vec2(x, y), vec4f(1001));
          } else {
            textureStore(output, vec2(x, y), vec4f(0001));
          }
          return vec4(0.00.00.00.0);
        }`;

        const canvas = document.querySelector('canvas');
        const adapter = await navigator.gpu?.requestAdapter({ });

        let presentationFormat = navigator.gpu.getPreferredCanvasFormat();
        if (presentationFormat != 'rgba8unorm' && presentationFormat != 'bgra8unorm') {
          throw new Error('Unsupported presentation format: ' + presentationFormat);
        }
        const deviceDescriptor = {};
        if (presentationFormat == 'bgra8unorm') {
          if (!adapter.features.has('bgra8unorm-storage')) {
            console.warn('Using rgba8unorm because bgra8unorm-storage feature is not available');
            presentationFormat = 'rgba8unorm';
          } else {
            deviceDescriptor.requiredFeatures = ['bgra8unorm-storage'];
          }
        }

        const device = await adapter?.requestDevice(deviceDescriptor);
        const context = canvas.getContext('webgpu');
        const devicePixelRatio = window.devicePixelRatio;
        canvas.width = canvas.clientWidth * devicePixelRatio;
        canvas.height = canvas.clientHeight * devicePixelRatio;
        context.configure({
          device,
          format: presentationFormat,
          usage: GPUTextureUsage.STORAGE_BINDING,
        });
        const canvasView = context.getCurrentTexture().createView();

        const dummyTexture = device.createTexture({
          size: { width: 512, height: 512, depth: 1 },
          format: presentationFormat,
          usage: GPUTextureUsage.RENDER_ATTACHMENT,
        });
        const dummyView = dummyTexture.createView();

        const bindGroupLayout = device.createBindGroupLayout({
          entries: [
            {
              binding: 0,
              visibility: GPUShaderStage.FRAGMENT,
              storageTexture: {
                access: 'write-only',
                format: presentationFormat,
                viewDimension: '2d',
              },
            },
          ],
        });
        const bindGroup = device.createBindGroup({
          layout: bindGroupLayout,
          entries: [
            {
              binding: 0,
              resource: canvasView,
            },
          ],
        });

        const pipelineLayout = device.createPipelineLayout({
          bindGroupLayouts: [bindGroupLayout],
        });
        const pipeline = device.createRenderPipeline({
          layout: pipelineLayout,
          vertex: {
            module: device.createShaderModule({
              code: triangleVertWGSL,
            }),
          },
          fragment: {
            module: device.createShaderModule({
              code: redFragWGSL.replace('{PRESENTATION_FORMAT}', presentationFormat),
            }),
            targets: [
              {
                format: presentationFormat,
              },
            ],
          },
          primitive: {
            topology: 'triangle-list',
          },
        });

        const renderPassDescriptor = {
          colorAttachments: [
            {
              view: dummyView,
              clearValue: [0001],
              loadOp: 'clear',
              storeOp: 'store',
            },
          ],
        };
        const commandEncoder = device.createCommandEncoder();
        const passEncoder = commandEncoder.beginRenderPass(renderPassDescriptor);
        passEncoder.setBindGroup(0, bindGroup);
        passEncoder.setPipeline(pipeline);
        passEncoder.draw(3);
        passEncoder.end();
        device.queue.submit([commandEncoder.finish()]);
        await device.queue.onSubmittedWorkDone();
        requestAnimationFrame(() => {
          requestAnimationFrame(() => document.documentElement.className = '');
        });
      } catch (error) {
        console.error(error);
        document.getElementById('canvas').style.display = 'none';
        document.body.append(error.toString());
        document.documentElement.className = '';
      }
    })();
  </script>
</html>

Messung V0.5 in Prozent
C=80 H=98 G=89

¤ Dauer der Verarbeitung: 0.21 Sekunden  (vorverarbeitet am  2026-08-25) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.