-
Notifications
You must be signed in to change notification settings - Fork 158
[Vello Hybrid]: Clipping (Spatiotemporal Allocation) #957
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d6b2c02
Start of spatio-temportal allocation for clipping
raphlinus c220a65
Clipping functionality
taj-p 4b60027
Merge remote-tracking branch 'upstream/main' into tajp/hybrid/clip
taj-p 24bd54e
Fix bad merge
taj-p dc61c48
.
taj-p 2ab36ec
Revert snapshot changes
taj-p 9523ded
Set initial texture height to 1
taj-p 41f78ba
Comments 1
taj-p b7dbcec
Don't multiply and use bit shifts for * 16
taj-p e137620
Comments 2
taj-p ccb0ea6
Skip render pass
taj-p 7585b31
clippy
taj-p 4711939
Fix bad merge
taj-p cbf6ba3
Pass all args
taj-p 007ae05
Comments 3
8000
taj-p 46c7a10
Formatting
taj-p c1e9097
Add notes on clip depths, textures, and rendering
taj-p File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2025 the Vello Authors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
// This shader clears specific slots in slot textures to transparent pixels. | ||
|
||
// Assumes this texture consists of a single column of slots of `config.slot_height`, | ||
// numbering from 0 to `texture_height / slot_height - 1` from top to bottom. | ||
|
||
struct Config { | ||
// Width of a slot (matching `WideTile::WIDTH` and the width of a slot texture). | ||
slot_width: u32, | ||
// Height of a slot (matching `Tile::HEIGHT`) | ||
slot_height: u32, | ||
// Total height of the texture (slot_height * number_of_slots) | ||
texture_height: u32, | ||
// Padding for 16-byte alignment | ||
_padding: u32, | ||
} | ||
|
||
@group(0) @binding(0) | ||
var<uniform> config: Config; | ||
|
||
@vertex | ||
fn vs_main( | ||
@builtin(vertex_index) vertex_index: u32, | ||
@location(0) index: u32, | ||
) -> @builtin(position) vec4<f32> { | ||
// Map vertex_index (0-3) to quad corners: | ||
// 0 → (0,0), 1 → (1,0), 2 → (0,1), 3 → (1,1) | ||
let x = f32(vertex_index & 1u); | ||
let y = f32(vertex_index >> 1u); | ||
|
||
// Calculate the y-position based on the slot index | ||
let slot_y_offset = f32(index * config.slot_height); | ||
|
||
// Scale to match slot dimensions | ||
let pix_x = x * f32(config.slot_width); | ||
let pix_y = slot_y_offset + y * f32(config.slot_height); | ||
|
||
// Convert to NDC | ||
let ndc_x = pix_x * 2.0 / f32(config.slot_width) - 1.0; | ||
let ndc_y = 1.0 - pix_y * 2.0 / f32(config.texture_height); | ||
|
||
return vec4<f32>(ndc_x, ndc_y, 0.0, 1.0); | ||
} | ||
|
||
@fragment | ||
fn fs_main(@builtin(position) position: vec4<f32>) -> @location(0) vec4<f32> { | ||
// Clear with transparent pixels | ||
return vec4<f32>(0.0, 0.0, 0.0, 0.0); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not clear to me how
in.position.y
has been modified in this PR. From the scheduler, it looks like it also contains theslot_ix * Tile::HEIGHT
, or slot y position. So why the& 3
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the answer to this question should also potentially result in a code comment in the wgsl shader.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in.position
represents the positionbuiltin
. In a vertex shader, it ranges from -1 to 1 for X and Y. In the context of a fragment shader, it represents the pixel coordinate of where we are drawing (see this article). The& 3
is used to constrain the pixel coordinate to 4 since that's the height of our tile. I added aCAUTION:
note to theconfig.strip_height
about the danger in changing its value without updating this logic.In time, we will want to make this configurable, but I'm not sure how that will present. We could make the
& 3
configurable, but then we should also make the& 0xFFu
configurable to wide tile width. I think at this stage we should untangle those concerns when we get to them.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh whoops, I got my x and y's confused! Thanks for the great answer :D