Repository navigation
Specify the primitive clipping and rasterization stages - #1564
Conversation
Kangz
left a comment
There was a problem hiding this comment.
Looks good overall, with some missing things and maybe simplification possible if we don't talk about the GPU generating more polygons with clipping.
| **Returns:** {{GPUExtent3DDict}} | ||
|
|
||
| 1. Let |extent| be a new {{GPUExtent3DDict}} object. | ||
| 1. Set |extent|.{{GPUExtent3DDict/width}} to max(1, |baseSize|.[=Extent3D/width=] ÷ |mipLevel|). |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| {{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, |
There was a problem hiding this comment.
I'm not sure I understand this.
| 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
|
||
| 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=], |
There was a problem hiding this comment.
What if the edges of the primitive doesn't intersect the clip volume at all. Is it discarded?
There was a problem hiding this comment.
no, it's fine. It could still cover the whole screen without any particular edge intersecting the clip volume.
|
|
||
| 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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
Comment Brandon found about tracking viewport/scissor/other state in encoders: #850 (comment) |
| 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. |
There was a problem hiding this comment.
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.
…est (gpuweb#1564) This PR adds a description for the number_of_bind_group_layouts_exceeds_the_maximum_value test.
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
bikesheddoesn't like seeing any definitions there: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