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

Add optional feature clip-distances #4588

Merged
merged 23 commits into from
May 29, 2024
Merged

Conversation

Jiawei-Shao
Copy link
Contributor

@Jiawei-Shao Jiawei-Shao commented Apr 18, 2024

This patch adds the optional feature clip-distances to WebGPU API and WGSL SPEC.

  • Add WebGPU API and WGSL optional feature clip-distances
  • Add new vertex stage output builtin variable clip_distances
  • Update the primitive clipping algorithm with user-defined clip distances
  • Add new validation rules to the validation algorithm on inter-stage interfaces when clip-distances is used in the vertex stage
  • Add new device limit maxClipDistancesSize and update the related vertex stage validation algorithm

Fixed: #390

This patch adds the optional feature `clip-distance to WebGPU API
and WGSL SPEC.
- Add WebGPU API and WGSL optional feature `clip-distance`
- Add new vertex stage output builtin variable `clip-distance`
- Update the primitive clipping algorithm with user-defined clip
  distances
- Add new validation rules to the validation algorithm on
  inter-stage interfaces when `clip-distance` is used in the vertex
  stage
- Add new device limit `maxClipDistances` and update the related
  vertex stage validation algorithm
Copy link
Contributor

@beaufortfrancois beaufortfrancois left a comment

Choose a reason for hiding this comment

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

I believe it would help developers if WGSL builtin value was renamed to clip_distances and WebGPU feature to "clip-distances".

spec/index.bs Outdated Show resolved Hide resolved
Copy link
Contributor

github-actions bot commented Apr 19, 2024

Previews, as seen when this build job started (466c36f):
WebGPU webgpu.idl | Explainer | Correspondence Reference
WGSL grammar.js | wgsl.lalr.txt

@Jiawei-Shao
Copy link
Contributor Author

I believe it would help developers if WGSL builtin value was renamed to clip_distances and WebGPU feature to "clip-distances".

Done @beaufortfrancois

@beaufortfrancois
Copy link
Contributor

I believe it would help developers if WGSL builtin value was renamed to clip_distances and WebGPU feature to "clip-distances".

Done @beaufortfrancois

I'm still seeing singular "clip distance", not plural "clip distances".

@Jiawei-Shao
Copy link
Contributor Author

I believe it would help developers if WGSL builtin value was renamed to clip_distances and WebGPU feature to "clip-distances".

Done @beaufortfrancois

I'm still seeing singular "clip distance", not plural "clip distances".

Sorry @beaufortfrancois , now there should be no clip distance.

wgsl/index.bs Outdated Show resolved Hide resolved
@beaufortfrancois
Copy link
Contributor

I believe it would help developers if WGSL builtin value was renamed to clip_distances and WebGPU feature to "clip-distances".

Done @beaufortfrancois

I'm still seeing singular "clip distance", not plural "clip distances".

Sorry @beaufortfrancois , now there should be no clip distance.

You may want to edit #4588 (comment) and PR title as well.

spec/index.bs Outdated Show resolved Hide resolved
@Jiawei-Shao Jiawei-Shao changed the title Add optional feature clip-distance Add optional feature clip-distances Apr 22, 2024
@Jiawei-Shao
Copy link
Contributor Author

I believe it would help developers if WGSL builtin value was renamed to clip_distances and WebGPU feature to "clip-distances".

Done @beaufortfrancois

I'm still seeing singular "clip distance", not plural "clip distances".

Sorry @beaufortfrancois , now there should be no clip distance.

You may want to edit #4588 (comment) and PR title as well.

Done

spec/index.bs Outdated Show resolved Hide resolved
spec/index.bs Outdated Show resolved Hide resolved
spec/index.bs Outdated Show resolved Hide resolved
spec/index.bs Outdated Show resolved Hide resolved
spec/index.bs Outdated Show resolved Hide resolved
spec/index.bs Outdated Show resolved Hide resolved
spec/index.bs Outdated Show resolved Hide resolved
spec/index.bs Outdated Show resolved Hide resolved
@kainino0x kainino0x requested a review from alan-baker May 8, 2024 23:15
wgsl/index.bs Outdated
<tr><td>[=built-in values/clip_distances=]
<td>vertex
<td>output
<td>array&lt;f32, N&gt;
Copy link
Contributor

Choose a reason for hiding this comment

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

From what I can tell, the API requires N to be 8. Is there a reason not to restrict WGSL to the same value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added the restriction to WGSL. PTAL, thanks!

wgsl/index.bs Outdated Show resolved Hide resolved
@Kangz
Copy link
Contributor

Kangz commented May 14, 2024

GPU Web WG 2024-05-08 Pacific-time
  • JS: One question is whether we should make the limit for number to 8, since that’s what Metal and D3D has as hardcoded.
  • KN: I think we could add a limit later if we wanted to. I think the downside is that if we ship this with the hardcoded limit, that might cause minor issues, but it’s very unlikely, because of the reasons you mentioned.
  • KG: Sounds reasonable to me
  • MW: Believe it’s indeed limited to 8 on Metal.
  • JS: I really want someone to review the WGSL side
  • KN: Everyone happy to land this feature, once details are ironed out?
  • KG: sounds like yes, and OK with hardcoding to 8.
  • Consensus: Hardcode max to 8, and we’ll review the WGSL side before landing.

spec/index.bs Outdated Show resolved Hide resolved
@Jiawei-Shao
Copy link
Contributor Author

Hi @kainino0x @alan-baker could you take a look at this PR?

Copy link
Contributor

@kainino0x kainino0x left a comment

Choose a reason for hiding this comment

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

Specs LGTM. I haven't dug into the backend investigations but it seems like the mapping is fairly straightforward. Still, what is the status of prototyping and testing? It would be helpful to know that it's behaving consistently across backends.

spec/index.bs Outdated Show resolved Hide resolved
@Jiawei-Shao
Copy link
Contributor Author

Hi @kainino0x ,

I haven't started prototyping and testing yet but according to previous investigations the behaviors of clip distances are quite clear and should be same among D3D12, Metal and Vulkan. Do you think now we should have more experiments and prototyping on this feature?

@kainino0x
Copy link
Contributor

IMO for nontrivial changes, at least one prototype and some basic tests should work before we land changes to the spec (and then land the tests).

Generally I'd like the spec to be "evergreen", by which I mean, it should always be a valid target for implementations, and we need implementation experience to be sure of that. We could reevaluate that once we've published a Candidate Recommendation, but right now I think it's necessary.

@kainino0x
Copy link
Contributor

We can discuss at the WG meeting though, maybe people think the investigation already meets the bar needed to land the spec.

@kainino0x kainino0x added wgsl WebGPU Shading Language Issues api WebGPU API labels May 21, 2024
@Jiawei-Shao
Copy link
Contributor Author

Note that in SPIRV-Cross the SPIRV ClipDistance is directly translated into [[clip_distance]] in MSL when it is an vertex output and SV_ClipDistance0 and SV_Clip_Distance1 in HLSL.

@kdashg kdashg merged commit adb07b1 into gpuweb:main May 29, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api WebGPU API for webgpu editors meeting wgsl WebGPU Shading Language Issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HW Clip Planes support
7 participants