Skip to content

Conversation

@petermcneeleychromium
Copy link
Contributor

This is to make us aligned with existing spec and vulkan behavior.
Webgpu issue
gpuweb/gpuweb#5457

Copy link
Contributor

@mwyrzykowski mwyrzykowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is incorrect. The current definition of sample_mask:

Sample coverage mask for the current fragment. It contains a bitmask indicating which samples in this fragment are covered by the primitive being rendered.

There is nothing in the definition indicating sample_mask is per-sample, one would it expect it to be constant per-fragment.

@kainino0x
Copy link
Collaborator

Isn't one fragment = the output of one invocation of the fragment shader? So may be a single sample or not, depending on which mode the fragment shader is running in.

@mwyrzykowski
Copy link
Contributor

mwyrzykowski commented Dec 10, 2025

Isn't one fragment = the output of one invocation of the fragment shader? So may be a single sample or not, depending on which mode the fragment shader is running in.

We discussed briefly in the WGSL meeting, there is certainly confusion regarding this.

In Metal, one fragment corresponds to a single texel in the render target. I.e., there may be up to [sample-count] fragment function invocations per fragment. This also aligns with the definition here, not say that's a definitive source either.

In computer graphics, a fragment is the data necessary to generate a single pixel's worth of a drawing primitive in the frame buffer.

edit: the Wikipedia definition concurs with Computer Graphics: Principles and Practice (3rd edition), page 433:

A fragment is the portion of a triangle that overlaps the bounds of a pixel.

given the book's relevance over the past 40 years that seems like an accurate definition. In the case of multisampling, the fragment includes all the samples which lie inside the triangle and contained within the bounds of a pixel

@petermcneeleychromium
Copy link
Contributor Author

petermcneeleychromium commented Dec 10, 2025

My reading of opengl is that there are multiple fragments per pixel.

but rasterization can produce multiple fragments from the same triangle per-pixel, depending on various multisampling parameters and OpenGL state. There will be at least one fragment produced for every pixel area covered by the primitive being rasterized.

However clearly, in the case we were discussing (sample shading) it is as you say multiple invocations per fragment

If sample shading is enabled and multiple invocations per fragment are required, additional invocations must be executed as specified.

from vkdoc

However we are still stuck in vulkan with

If sample shading is enabled, fragment shaders will only see values of 1 for samples being shaded - other bits will be 0.

Which is why I think we get the vulkan behavior we see. (this is possibly motivated due to writing to sample mask as well)

@kainino0x
Copy link
Collaborator

I stand corrected. From looking at Vulkan and GL, I'm getting the sense that "fragment" = one pixel-sized chunk of one primitive, prior to whatever fragment shader(s) run on it. I'm looking at Vulkan section "Sample Shading" and GL4.6/GLES3.2 sections "Shader Memory Access Ordering".

@kainino0x
Copy link
Collaborator

My reading of opengl is that there are multiple fragments per pixel.

but rasterization can produce multiple fragments from the same triangle per-pixel, depending on various multisampling parameters and OpenGL state. There will be at least one fragment produced for every pixel area covered by the primitive being rasterized.

Oops forgot to say - I agree this text from the OpenGL wiki does read the way you interpreted it, but I think that's inconsistent with the (latest) OpenGL specs.

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

Successfully merging this pull request may close these issues.

4 participants