Skip to content

vello_hybrid: Add Resources::new_with_config#1750

Merged
grebmeg merged 2 commits into
mainfrom
gemberg/vello-hybrid-resources-atlas-config
Jul 16, 2026
Merged

vello_hybrid: Add Resources::new_with_config#1750
grebmeg merged 2 commits into
mainfrom
gemberg/vello-hybrid-resources-atlas-config

Conversation

@grebmeg

@grebmeg grebmeg commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

The image atlas is currently configured in two independent places: the renderer's settings (which size the GPU atlas texture) and the ImageCache owned by Resources (which is what actually allocates images and reports errors). When these two disagree, the AtlasError::TextureTooLarge error is never surfaced — the too-large check runs against the wrong config, so uploading an image that exceeds the intended atlas size silently proceeds instead of failing.

This PR adds a public Resources::new_with_config(AtlasConfig) so callers can configure the atlas that Resources owns, letting both configs be kept in sync. It also adds a browser WebGL test that sets up a small (10×10) atlas and asserts that uploading a larger image fails with TextureTooLarge.

This is a band-aid: it makes the error reachable, but the caller is still responsible for passing matching configs in two places. A proper fix should unify this, likely a single source of truth via a unified resource-management approach, and is left for follow-up.

Created with assistance from Claude Opus 4.8 High.

@grebmeg
grebmeg requested a review from LaurenzV July 16, 2026 04:11

@LaurenzV LaurenzV left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yeah, we definitely need to fix this, for now let's just go with this I guess!

Self::new_with_config(AtlasConfig::default())
}

/// Create a new set of renderer resources with a custom image/glyph atlas configuration.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's please add the TODO here that we need to fix this, so we don't forget about it.

Also, we later on normalize the config in the renderer against the device limits, so it's possible they still don't match, but yes let's leave that for a follow-up.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Sure, done.

@@ -0,0 +1,92 @@
// Copyright 2026 the Vello Authors

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm not sure this test will run in CI if we put it here. Can we not put it into vello_sparse_tests, still as a custom module?

Also, let's add a TODO that upload_image doesn't unwrap in the first place. Since this is what should fail in the first place, can we not reduce the test to just check that upload_image doesn't work? Like, there is no point in having any of the stuff after this for that specific test (i.e. drawing it into the scene), no?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Moved this into vello_sparse_tests as a new webgl-only image_atlas module. Reduced it to just asserting upload_image fails with TextureTooLarge. Also added a TODO at the allocate(...).unwrap(). (FWIW the old native_webgl/tests location did run in CI via the native-webgl wasm-pack job, but agreed it's cleaner in the dedicated test crate.)

@grebmeg grebmeg left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the review and the helpful feedback! Yes, this is a temporary fix — we'll need to come back and implement a better long-term solution.

Self::new_with_config(AtlasConfig::default())
}

/// Create a new set of renderer resources with a custom image/glyph atlas configuration.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Sure, done.

@@ -0,0 +1,92 @@
// Copyright 2026 the Vello Authors

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Moved this into vello_sparse_tests as a new webgl-only image_atlas module. Reduced it to just asserting upload_image fails with TextureTooLarge. Also added a TODO at the allocate(...).unwrap(). (FWIW the old native_webgl/tests location did run in CI via the native-webgl wasm-pack job, but agreed it's cleaner in the dedicated test crate.)

@grebmeg
grebmeg enabled auto-merge July 16, 2026 10:16
@grebmeg
grebmeg added this pull request to the merge queue Jul 16, 2026
Merged via the queue into main with commit 8ecea46 Jul 16, 2026
19 checks passed
@grebmeg
grebmeg deleted the gemberg/vello-hybrid-resources-atlas-config branch July 16, 2026 10:51
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.

2 participants