Implement view_formats in create_texture - #832
Open
hmaarrfk wants to merge 1 commit into
Open
Conversation
`create_texture()` accepted a `view_formats` argument and then raised NotImplementedError for any non-empty value, while the descriptor it fills already carried `viewFormatCount` / `viewFormats`, commented out as unused. This wires them up using the same conversion the surface configuration path in this file already performs. WebGPU allows a texture view to reinterpret the texture as any format listed in `viewFormats` at creation, and only those. The common use is the srgb/non-srgb pair: sampling an srgb texture applies the transfer function, so reading back the bytes that were actually written requires a view in the plain format. Without `view_formats` there is no way to ask for that view, and the only workaround is to copy the whole texture into a second one of the plain format -- a full-frame copy, every frame, plus the memory for the duplicate. Adds a test covering a declared view format, the texture's own format, an undeclared format still being rejected, and a texture that declares none keeping the previous behaviour.
hmaarrfk
added a commit
to hmaarrfk/rendercanvas
that referenced
this pull request
Aug 22, 2026
Covers the plumbing in both directions: with a format declared the view is created, and without it the same view is rejected, so the positive assertion is testing this change rather than something the backend would have allowed anyway. Skipped when the wgpu backend does not implement create_texture(view_formats=...), which it did not before pygfx/wgpu-py#832 -- otherwise the test would fail for a reason unrelated to rendercanvas.
hmaarrfk
marked this pull request as ready for review
August 22, 2026 22:00
hmaarrfk
added a commit
to hmaarrfk/rendercanvas
that referenced
this pull request
Aug 22, 2026
<details><summary>Claude's draft</summary> The test feature-detected `create_texture(view_formats=...)` and skipped when the backend did not implement it, which is every released wgpu: the argument raises NotImplementedError until pygfx/wgpu-py#832 ships. So CI skipped it every run, the PR looked green, and nothing about the pass-through was verified. A skipped test is not evidence. Drop the feature detection and let the test run. On a wgpu without the argument, `get_current_texture()` raises NotImplementedError and the test turns that into an explicit failure naming the version in use and the wgpu-py PR it is waiting on, rather than an opaque traceback. On a wgpu with it, the test passes, and no marker has to be removed by hand for that to happen. The failure state is the point: this PR depends on something unreleased, and red is the honest report of that until the release lands. Verified in both worlds. Against wgpu 0.32 the test fails with the message above; against a wgpu that implements the argument it passes. Removing the `view_formats=` pass-through from `WgpuContextToBitmap._get_current_texture()` while keeping the implementing wgpu also fails it (GPUValidationError on the view), so the test cannot go green without the change it covers. Resume this Claude session: ``` cd /home/mark/git/ramona/python-owl claude --resume 66360ec9-8ab8-4ae1-8f3f-e873ce8fc563 ``` </details> Claude-Session: https://claude.ai/code/session_01FvMxuoA4rU1KvqM38ypUwe
Contributor
|
diff looks good to me. Little unsure if native texture formats would even work... Because as it currently is, they are included. But it's not really our job to validate that anyway, Just a warning about the perceived efficiency win. On a lot of platforms (combination of os, GPU, driver, backend) sRGB textures aren't real. As in they don't exist in hardware. Instead there is just a transfer function used in the shadercode for compatibility. |
Contributor
Author
it is mostly for offscreen rendering, where something was measured by AI :/ i do tend to believe it on these performance optimizations. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Allow users to create non-srgb textures through the usage of
view_formatscreate_texture()accepts aview_formatsargument and then raisesNotImplementedErrorfor any non-empty value, while the descriptor it fills already carriesviewFormatCount/viewFormats, commented out as unused. This wires them up with the same conversion the surface configuration path in the same file already performs, which makes it possible to take a non-srgb view of an srgb target instead of copying the whole texture into a second one of the plain format every frame. The test covers a declared format working, the texture's own format, an undeclared format still being rejected, and a texture declaring none keeping the previous behaviour.