Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement blend_src attribute. #381

Open
iwoplaza opened this issue Sep 23, 2024 · 0 comments
Open

Implement blend_src attribute. #381

iwoplaza opened this issue Sep 23, 2024 · 0 comments

Comments

@iwoplaza
Copy link
Collaborator

Spec: https://www.w3.org/TR/WGSL/#blend-src-attr
https://www.w3.org/TR/webgpu/#dom-gpufeaturename-dual-source-blending

Rules:

  • dual-source-blending extension has to be enabled,
  • Can only appear as an attribute for a member of a fragment shader output struct.
  • The struct containing members with this attribute has to have exactly two entries (one with @blend_str(0), and the other with @blend_str(1)).
  • All the members must have same data type.

Are degrees of freedom are:

  • The shared type both members will have.
  • The names of both members.

Potential API:

import tgpu from 'typegpu';
import * as d from 'typegpu/data';

// Default names

/* TgpuDualSourceBlend<vec4f, 'src0', 'src1'> */
const FragmentOutput = d.dualSourceBlend(vec4f);

// Custom names, useful for WGSL -> JS generation

/* TgpuDualSourceBlend<vec4f, 'a', 'b'> */
const FragmentOutput = d.dualSourceBlend(vec4f, 'a', 'b');

const fragmentFn = tgpu
  .fragmentFn([], FragmentOutput)
  .implement(() => {
    // ...
    return {
      'a': vec4f(),
      'b': vec4f(),
    };
  });
@iwoplaza iwoplaza modified the milestone: 0.2.0 Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant