From 0f31d2e4480a169684eb45051194bc7c31931096 Mon Sep 17 00:00:00 2001 From: Kai Ninomiya Date: Tue, 22 Oct 2024 14:19:08 -0400 Subject: [PATCH] WIP --- .../emulatedAlphaToCoverage.ts | 4 +-- sample/alphaToCoverage/main.ts | 25 ++++++++++++------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/sample/alphaToCoverage/emulatedAlphaToCoverage.ts b/sample/alphaToCoverage/emulatedAlphaToCoverage.ts index ed7afb44..58d7d6f3 100644 --- a/sample/alphaToCoverage/emulatedAlphaToCoverage.ts +++ b/sample/alphaToCoverage/emulatedAlphaToCoverage.ts @@ -23,8 +23,8 @@ type Mask = number; export const kEmulatedAlphaToCoverage = { 'Apple M1 Pro': `\ fn emulatedAlphaToCoverage(alpha: f32, x: u32, y: u32) -> u32 { - let u = x % 2; - let v = y % 2; + let u = x % 2u; + let v = y % 2u; if (alpha < 0.5 / 16) { return ${0b0000}; } // FIXME returning values out of an array is not working, always returns 0 if (alpha < 1.5 / 16) { return array(array(${0b0001}u, ${0b0000}), array(${0b0000}, ${0b0000}))[v][u]; } diff --git a/sample/alphaToCoverage/main.ts b/sample/alphaToCoverage/main.ts index 0043e7b3..adb06c90 100644 --- a/sample/alphaToCoverage/main.ts +++ b/sample/alphaToCoverage/main.ts @@ -17,14 +17,14 @@ quitIfWebGPUNotAvailable(adapter, device); const kInitConfig = { scene: 'solid_colors', - emulatedDevice: 'none', + emulatedDevice: 'Apple M1 Pro', sizeLog2: 3, showResolvedColor: true, color1: 0x0000ff, - alpha1: 127, + alpha1: 0, color2: 0xff0000, alpha2: 16, - pause: false, + pause: true, }; const config = { ...kInitConfig }; @@ -40,7 +40,7 @@ gui.width = 300; gui.add(config, 'scene', ['solid_colors']); gui.add(config, 'emulatedDevice', [ - 'none', + 'native', ...Object.keys(kEmulatedAlphaToCoverage), ]); @@ -94,8 +94,8 @@ let actualMSTexture: GPUTexture, actualMSTextureView: GPUTextureView; let emulatedMSTexture: GPUTexture, emulatedMSTextureView: GPUTextureView; let resolveTexture: GPUTexture, resolveTextureView: GPUTextureView; let lastSize = 0; -let renderWithEmulatedAlphaToCoveragePipeline: GPURenderPipeline | null; -let lastEmulatedDevice = 'none'; +let renderWithEmulatedAlphaToCoveragePipeline: GPURenderPipeline | null = null; +let lastEmulatedDevice = 'native'; function resetConfiguredObjects() { const size = 2 ** config.sizeLog2; if (lastSize !== size) { @@ -132,9 +132,10 @@ function resetConfiguredObjects() { } if ( - config.emulatedDevice !== 'none' && + config.emulatedDevice !== 'native' && lastEmulatedDevice !== config.emulatedDevice ) { + console.log( kEmulatedAlphaToCoverage[config.emulatedDevice]); // Pipeline to render to a multisampled texture using *emulated* alpha-to-coverage const renderWithEmulatedAlphaToCoverageModule = device.createShaderModule({ code: @@ -248,11 +249,17 @@ function render() { const showMultisampleTextureBG = device.createBindGroup({ layout: showMultisampleTextureBGL, entries: [ - { binding: 0, resource: actualMSTextureView }, + { + binding: 0, + resource: //actualMSTextureView, + config.emulatedDevice === 'native' + ? actualMSTextureView + : emulatedMSTextureView, + }, { binding: 1, resource: - config.emulatedDevice === 'none' + config.emulatedDevice === 'native' ? actualMSTextureView : emulatedMSTextureView, },