Skip to content

Implement view_formats in create_texture - #832

Open
hmaarrfk wants to merge 1 commit into
pygfx:mainfrom
hmaarrfk:view_formats
Open

Implement view_formats in create_texture#832
hmaarrfk wants to merge 1 commit into
pygfx:mainfrom
hmaarrfk:view_formats

Conversation

@hmaarrfk

@hmaarrfk hmaarrfk commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Allow users to create non-srgb textures through the usage of view_formats


create_texture() accepts a view_formats argument and then raises NotImplementedError for any non-empty value, while the descriptor it fills already carries viewFormatCount / 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.

`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
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
@Vipitis

Vipitis commented Aug 22, 2026

Copy link
Copy Markdown
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.

@hmaarrfk

Copy link
Copy Markdown
Contributor Author

perceived efficiency win

it is mostly for offscreen rendering, where something was measured by AI :/

i do tend to believe it on these performance optimizations.

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