wgpu-py icon indicating copy to clipboard operation
wgpu-py copied to clipboard

missing rgba16unorm

Open jmgurney opened this issue 5 months ago • 3 comments

Describe the bug

I'm attempting to use rgba16unorm as a storage texture type per the WGSL spec: https://www.w3.org/TR/WGSL/#texel-formats but it is missing from https://wgpu-py.readthedocs.io/en/stable/wgpu_enums.html#wgpu.enums.TextureFormat and I get: KeyError: 'TextureFormat.rgba16unorm'

To Reproduce

Attempt to create an output texture via:

>>> import wgpu
>>> gpu = wgpu.utils.get_default_device()
>>> tex_out = gpu.create_texture(size=(16,16,1),
...             format=wgpu.TextureFormat.rgba16unorm,
...             usage=wgpu.TextureUsage.COPY_SRC | wgpu.TextureUsage.STORAGE_BINDING,
...             sample_count=1)
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
AttributeError: type object 'TextureFormat' has no attribute 'rgba16unorm'. Did you mean: 'rgba8unorm'?
>>> 

Observed behavior

See above.

Screenshots

n/a

Your environment

Details about the environment this issue was observed on, like OS, Python version, wgpu-py version. You can also include (the relevant sections of) the result of wgpu.diagnostics.print_report().

>>> wgpu.diagnostics.print_report()
                                               
██ system:                 
                                               
             platform:  macOS-14.7-arm64-arm-64bit
python_implementation:  CPython          
               python:  3.10.14
                                               
██ versions:
                                                                                              
wgpu:  0.22.2
cffi:  1.17.1                                                                                 
                                                                                              
██ wgpu_native_info:                                                                          
                                                                                              
expected_version:  24.0.3.1                                                                   
     lib_version:  24.0.3.1                                                                   
        lib_path:  ./resources/libwgpu_native-release.dylib
                                                                                              
██ object_counts:                                                                             
                                                                                              
                      count  resource_mem                                                     
                                                                                              
            Adapter:      1                                                                   
          BindGroup:      0                                                                   
    BindGroupLayout:      0                                                                   
             Buffer:      0                                                                   
      CanvasContext:      0                                                                   
      CommandBuffer:      0                                                                   
     CommandEncoder:      0
 ComputePassEncoder:      0 
    ComputePipeline:      0
             Device:      1                                                                   
     PipelineLayout:      0                                                                   
           QuerySet:      0                                                                                                                                                                 
           QuerySet:      0                                                                   
              Queue:      1                                                                   
       RenderBundle:      0    
RenderBundleEncoder:      0       
  RenderPassEncoder:      0          
     RenderPipeline:      0                                                                                                                                                                 
            Sampler:      0        
       ShaderModule:      0                    
            Texture:      0
        TextureView:      0                    
                                                                                              
              total:      3             0
                                               
██ wgpu_native_counts:                         
                                               
                  count  mem  hub   a  k  r  el_size                                          
                                               
        Adapter:      1    8  hub:  1  1  0        8                                          
      BindGroup:      0    0  hub:  0  0  0       16                                          
BindGroupLayout:      0    0  hub:  0  0  0       16                                          
         Buffer:      0    0  hub:  0  0  0       16                                          
  CanvasContext:      0    0        0  0  0        8                                          
  CommandBuffer:      0    0  hub:  0  0  0        8                                          
ComputePipeline:      0    0  hub:  0  0  0       16       
         Device:      1    8  hub:  1  1  0        8                                          
  PipelineCache:      0    0  hub:  0  0  0       16                                          
 PipelineLayout:      0    0  hub:  0  0  0       16                                          
       QuerySet:      0    0  hub:  0  0  0       16                                          
          Queue:      1    8  hub:  1  1  0        8                                          
   RenderBundle:      0    0  hub:  0  0  0       16                                          
 RenderPipeline:      0    0  hub:  0  0  0       16                                          
        Sampler:      0    0  hub:  0  0  0       16                                          
   ShaderModule:      0    0  hub:  0  0  0       16                                          
        Texture:      0    0  hub:  0  0  0       16                                          
    TextureView:      0    0  hub:  0  0  0       16                                          
                                               
          total:      3   24
                                               
    * The a, k, r are allocated, kept, and released, respectively.                            
    * Reported memory does not include buffer/texture data.                                   

jmgurney avatar Jun 27 '25 13:06 jmgurney

looks like the version of webgpu.h we have in wgpu-native doesn't have it. But it's available as a native only texture format... so it's not part of the enum or mapping. You can try to just set the magic value from here: https://github.com/pygfx/wgpu-py/blob/d25edb102644f74c0d12e24996f757eac77b57fa/wgpu/resources/wgpu.h#L247 or format=lib.WGPUNativeTextureFormat_Rgba16Unorm(but I don't think lib is exposed) it might work.

Vipitis avatar Jun 27 '25 14:06 Vipitis

Interestingly, the format is present in the WebGPU spec, so I image it will land in webgpu.h at some point.

Perhaps for things like this, we can add it to our API, even when its not in webgpu.h, when:

  • WebGPU has it.
  • We can support it, e.g. because its in wgpu.h.

almarklein avatar Jun 30 '25 07:06 almarklein

The enums fields are now available (added in #743), but they are not supported by the current wgpu-native yet.

They are present in the current webgpu.h (https://github.com/webgpu-native/webgpu-headers/blob/main/webgpu.h#L1012). But wgpu-native is pinned to an older version that does not have it yet.

So to get proper support for the 16unorm texture formats and friends:

  • wgpu-native should update to the latest webgpu.h.
  • wgpu-native should do a release.
  • we should update to that version of wgpu-native.

almarklein avatar Sep 16 '25 06:09 almarklein