pygfx/wgpu-py

create_render_pipeline() fails with layout=AutoLayoutMode.auto

fyellin opened this issue · 2 comments

The documentation for create_render_pipeline() claims that you can pass layout=AutoLayoutMode.auto. This gives an eror if you try it.

The similar function create_compute_pipeline() contains code to deal with `layout=AutoLayoutMode.auto':

        if isinstance(layout, GPUPipelineLayout):
            layout_id = layout._internal
        elif layout == enums.AutoLayoutMode.auto:
            layout_id = ffi.NULL
        else:
            raise TypeError(
                "create_compute_pipeline() 'layout' arg must be a GPUPipelineLayout or 'auto'"
            )

and then uses layout_id to build the WGPUComputePipelineDescriptor *.

These lines are missing from create_render_pipeline(). It just directly takes layout._internal when building the WGPURenderPipelineDescriptor, and errors when the argument is auto. There is no check that the layout argument is even a GPUPipelineLayout.

I have confirmed that if I modify create_render_pipeline() to handle layouts just like create_compute_pipeline(), it works correctly for the simple autolayout test casts that I've tried.

I'm still not comfortable enough with the build process to know if I'm supposed to make these changes directly to _api.py, or if this is autogenerated from higher-level code.

Python 3.12 running on MacOS
wgpu 0.15.2

Thanks for reporting! It looks like it's on oversight on my part, and create_render_pipeline() should indeed use similar logic to create_compute_pipeline(). Would you be interested to submit a pr for this?

You can change the _api.py - it's a mix of generated and manual code. You can run python codegen from the repo root to update/check the code. But I expect that that won't be necessary for this particular change. (You can just make this change and submit the pr; CI does a check too).

I will fix this.