Skip to content

Commit 0f31d2e

Browse files
committed
WIP
1 parent e65e384 commit 0f31d2e

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

sample/alphaToCoverage/emulatedAlphaToCoverage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ type Mask = number;
2323
export const kEmulatedAlphaToCoverage = {
2424
'Apple M1 Pro': `\
2525
fn emulatedAlphaToCoverage(alpha: f32, x: u32, y: u32) -> u32 {
26-
let u = x % 2;
27-
let v = y % 2;
26+
let u = x % 2u;
27+
let v = y % 2u;
2828
if (alpha < 0.5 / 16) { return ${0b0000}; }
2929
// FIXME returning values out of an array is not working, always returns 0
3030
if (alpha < 1.5 / 16) { return array(array(${0b0001}u, ${0b0000}), array(${0b0000}, ${0b0000}))[v][u]; }

sample/alphaToCoverage/main.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ quitIfWebGPUNotAvailable(adapter, device);
1717

1818
const kInitConfig = {
1919
scene: 'solid_colors',
20-
emulatedDevice: 'none',
20+
emulatedDevice: 'Apple M1 Pro',
2121
sizeLog2: 3,
2222
showResolvedColor: true,
2323
color1: 0x0000ff,
24-
alpha1: 127,
24+
alpha1: 0,
2525
color2: 0xff0000,
2626
alpha2: 16,
27-
pause: false,
27+
pause: true,
2828
};
2929
const config = { ...kInitConfig };
3030

@@ -40,7 +40,7 @@ gui.width = 300;
4040

4141
gui.add(config, 'scene', ['solid_colors']);
4242
gui.add(config, 'emulatedDevice', [
43-
'none',
43+
'native',
4444
...Object.keys(kEmulatedAlphaToCoverage),
4545
]);
4646

@@ -94,8 +94,8 @@ let actualMSTexture: GPUTexture, actualMSTextureView: GPUTextureView;
9494
let emulatedMSTexture: GPUTexture, emulatedMSTextureView: GPUTextureView;
9595
let resolveTexture: GPUTexture, resolveTextureView: GPUTextureView;
9696
let lastSize = 0;
97-
let renderWithEmulatedAlphaToCoveragePipeline: GPURenderPipeline | null;
98-
let lastEmulatedDevice = 'none';
97+
let renderWithEmulatedAlphaToCoveragePipeline: GPURenderPipeline | null = null;
98+
let lastEmulatedDevice = 'native';
9999
function resetConfiguredObjects() {
100100
const size = 2 ** config.sizeLog2;
101101
if (lastSize !== size) {
@@ -132,9 +132,10 @@ function resetConfiguredObjects() {
132132
}
133133

134134
if (
135-
config.emulatedDevice !== 'none' &&
135+
config.emulatedDevice !== 'native' &&
136136
lastEmulatedDevice !== config.emulatedDevice
137137
) {
138+
console.log( kEmulatedAlphaToCoverage[config.emulatedDevice]);
138139
// Pipeline to render to a multisampled texture using *emulated* alpha-to-coverage
139140
const renderWithEmulatedAlphaToCoverageModule = device.createShaderModule({
140141
code:
@@ -248,11 +249,17 @@ function render() {
248249
const showMultisampleTextureBG = device.createBindGroup({
249250
layout: showMultisampleTextureBGL,
250251
entries: [
251-
{ binding: 0, resource: actualMSTextureView },
252+
{
253+
binding: 0,
254+
resource: //actualMSTextureView,
255+
config.emulatedDevice === 'native'
256+
? actualMSTextureView
257+
: emulatedMSTextureView,
258+
},
252259
{
253260
binding: 1,
254261
resource:
255-
config.emulatedDevice === 'none'
262+
config.emulatedDevice === 'native'
256263
? actualMSTextureView
257264
: emulatedMSTextureView,
258265
},

0 commit comments

Comments
 (0)