Skip to content

Specify the primitive clipping and rasterization stages - #1564

Merged
kvark merged 8 commits into
gpuweb:mainfrom
kvark:pipeline
Apr 1, 2021
Merged

kvark merged 8 commits into
gpuweb:mainfrom
kvark:pipeline

Conversation

@kvark

@kvark kvark commented Mar 25, 2021 •

Copy link
Copy Markdown
Contributor

I used Vulkan specification as a reference, although some parts were unclear.

In terms of organization, I wanted to have this specified inside the rendering algorithm, but bikeshed doesn't like seeing any definitions there:

FATAL ERROR: Algorithm container has no name, and there are too many s to choose which to infer a name from.

If we can't make it work, we may consider moving other sections out of the algorithm as well. For now, it's not too important.

For reviewers, please double check the "linear" interpolation equation.


Preview | Diff

@github-actions

Copy link
Copy Markdown
Contributor

Previews, as seen at the time of posting this comment:
WebGPU | IDL
WGSL
e272bc4

@github-actions

Copy link
Copy Markdown
Contributor

Previews, as seen at the time of posting this comment:
WebGPU | IDL
WGSL
24b26cc

@github-actions

Copy link
Copy Markdown
Contributor

Previews, as seen at the time of posting this comment:
WebGPU | IDL
WGSL
13937d8

@github-actions

Copy link
Copy Markdown
Contributor

Previews, as seen at the time of posting this comment:
WebGPU | IDL
WGSL
3e7212b

@Kangz Kangz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good overall, with some missing things and maybe simplification possible if we don't talk about the GPU generating more polygons with clipping.

Comment thread spec/index.bs Resolved
Comment thread spec/index.bs Outdated
**Returns:** {{GPUExtent3DDict}}

1. Let |extent| be a new {{GPUExtent3DDict}} object.
1. Set |extent|.{{GPUExtent3DDict/width}} to max(1, |baseSize|.[=Extent3D/width=] ÷ |mipLevel|).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's not divided by the mipLevel but shifted. Can we define the "virtual size" of a mip level instead? It's that virtual size that's used for everything asides from copies.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We should define this somewhere. I was looking at copy logic, and didn't see a nice way to share it. But we'll need to share it with the sampling descriptions somewhere.

Comment thread spec/index.bs Resolved
Comment thread spec/index.bs Resolved
Comment thread spec/index.bs Resolved
Comment thread spec/index.bs
{{GPUPrimitiveTopology/"triangle-list"}} or {{GPUPrimitiveTopology/"triangle-strip"}}), this reconnection
may result in introduction of new vertices into the polygon, internally.

If a primitive intersects an edge of the [=clip volume=]’s boundary,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure I understand this.

Comment thread spec/index.bs
If a primitive intersects an edge of the [=clip volume=]’s boundary,
the clipped polygon must include a point on this boundary edge.

If the vertex shader outputs other floating-point values (scalars and vectors), qualified with

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is somewhat misleading: this is just saying that if the GPU performs clipping by producing new vertices, then the outputs are correctly interpolated. This problem completely disappears if we only talk about fragments.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a complicated thing. I tried to investigate, and so far it appears that this section isn't necessary (for our case), strictly speaking. But it's providing good detail on how the HW is expected to do things.

Comment thread spec/index.bs

A primitive passes through this stage unchanged if every one of its edges
lie entirely inside the [=clip volume=].
If the edges of a primitives intersect the boundary of the [=clip volume=],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What if the edges of the primitive doesn't intersect the clip volume at all. Is it discarded?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

no, it's fine. It could still cover the whole screen without any particular edge intersecting the clip volume.

Comment thread spec/index.bs Resolved
Comment thread spec/index.bs

Note: this section uses the term "polygon" instead of a "triangle",
since {#primitive-clipping} stage may have introduced additional vertices.
This is non-observable by the application.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SInce it is non-observable maybe we could remove it and do the clipping as part of the rasterization? Also what happens when the fragment writes gl_FragDepth?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Only the fact that we are dealing with a "polygon" is non-observable. The clipping stage itself is still necessary before we can talk about rasterization.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Also what happens when the fragment writes gl_FragDepth?

So far, we haven't reached the FS, so for this stage it doesn't matter if the user writes anything to the frag depth.

@github-actions

Copy link
Copy Markdown
Contributor

Previews, as seen at the time of posting this comment:
WebGPU | IDL
WGSL
37395f1

@kvark kvark changed the title Specify the primitive clipping stage Specify the primitive clipping and rasterization stages Mar 29, 2021
@kainino0x

Copy link
Copy Markdown
Contributor

Comment Brandon found about tracking viewport/scissor/other state in encoders: #850 (comment)

Comment thread spec/index.bs Resolved
Comment thread spec/index.bs Resolved
Comment thread spec/index.bs Resolved
Comment thread spec/index.bs Resolved
Comment thread spec/index.bs
the intersecting edges are reconnected by new edges that lie along the boundary of the [=clip volume=].
For triangular primitives (|descriptor|.{{GPURenderPipelineDescriptor/primitive}}.{{GPUPrimitiveState/topology}} is
{{GPUPrimitiveTopology/"triangle-list"}} or {{GPUPrimitiveTopology/"triangle-strip"}}), this reconnection
may result in introduction of new vertices into the polygon, internally.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thinking about it, I'm fairly convinced that's not how hardware works anymore. Instead FrontFace / cullmode is done for the whole triangle, potentially before clipping. Then clipping + clip planes happen with some kind of coarse scan line algorithm. Then for each smaller tile, finer rasterization is done by testing each fragment against the various planes defining the triangle.

Finally the fragments inputs are computed by interpolating from the triangle's vertices. It does conceptually the exact same thing as what's described here but doesn't need the complexity of generating new triangles to form a polygon.

Comment thread spec/index.bs Resolved
Comment thread spec/index.bs Resolved

@kainino0x kainino0x left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Mostly editorial review as I am not well versed enough in the underlying rendering algorithm.

Comment thread spec/index.bs Resolved
Comment thread spec/index.bs Resolved
Comment thread spec/index.bs Resolved
Comment thread spec/index.bs Resolved
Comment thread spec/index.bs Resolved
@kvark

kvark commented Apr 1, 2021

Copy link
Copy Markdown
Contributor Author

There is one thing that @Kangz noted as unclear, and I wasn't able to reword yet.
Let's land this and iterate. There is #1583 waiting.

@kvark
kvark merged commit 52c4039 into gpuweb:main Apr 1, 2021
@kvark
kvark deleted the pipeline branch April 1, 2021 20:05
@kvark kvark mentioned this pull request Apr 5, 2021
ben-clayton pushed a commit to ben-clayton/gpuweb that referenced this pull request Sep 6, 2022
…est (gpuweb#1564)

This PR adds a description for the number_of_bind_group_layouts_exceeds_the_maximum_value
test.
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.

3 participants