Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kainino0x committed Oct 22, 2024
1 parent e65e384 commit 0f31d2e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
4 changes: 2 additions & 2 deletions sample/alphaToCoverage/emulatedAlphaToCoverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]; }
Expand Down
25 changes: 16 additions & 9 deletions sample/alphaToCoverage/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

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

gui.add(config, 'scene', ['solid_colors']);
gui.add(config, 'emulatedDevice', [
'none',
'native',
...Object.keys(kEmulatedAlphaToCoverage),
]);

Expand Down Expand Up @@ -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';

Check failure on line 98 in sample/alphaToCoverage/main.ts

View workflow job for this annotation

GitHub Actions / build-and-deploy

'lastEmulatedDevice' is never reassigned. Use 'const' instead
function resetConfiguredObjects() {
const size = 2 ** config.sizeLog2;
if (lastSize !== size) {
Expand Down Expand Up @@ -132,9 +132,10 @@ function resetConfiguredObjects() {
}

if (
config.emulatedDevice !== 'none' &&
config.emulatedDevice !== 'native' &&
lastEmulatedDevice !== config.emulatedDevice
) {
console.log( kEmulatedAlphaToCoverage[config.emulatedDevice]);

Check failure on line 138 in sample/alphaToCoverage/main.ts

View workflow job for this annotation

GitHub Actions / build-and-deploy

Delete `·`
// Pipeline to render to a multisampled texture using *emulated* alpha-to-coverage
const renderWithEmulatedAlphaToCoverageModule = device.createShaderModule({
code:
Expand Down Expand Up @@ -248,11 +249,17 @@ function render() {
const showMultisampleTextureBG = device.createBindGroup({
layout: showMultisampleTextureBGL,
entries: [
{ binding: 0, resource: actualMSTextureView },
{
binding: 0,
resource: //actualMSTextureView,

Check failure on line 254 in sample/alphaToCoverage/main.ts

View workflow job for this annotation

GitHub Actions / build-and-deploy

Replace `resource:·//actualMSTextureView,` with `//actualMSTextureView,⏎········resource:`
config.emulatedDevice === 'native'
? actualMSTextureView
: emulatedMSTextureView,
},
{
binding: 1,
resource:
config.emulatedDevice === 'none'
config.emulatedDevice === 'native'
? actualMSTextureView
: emulatedMSTextureView,
},
Expand Down

0 comments on commit 0f31d2e

Please sign in to comment.