Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of Metal MTLCommandBuffer directly. #3970

Closed
benjamin-kramer opened this issue Jul 24, 2023 · 5 comments
Closed

Use of Metal MTLCommandBuffer directly. #3970

benjamin-kramer opened this issue Jul 24, 2023 · 5 comments
Labels
type: question Further information is requested

Comments

@benjamin-kramer
Copy link

benjamin-kramer commented Jul 24, 2023

In some Metal based applications it makes sense to perform multiple calculations on the same MTLCommandBuffer.
To make some of these calculations platform independent, I'd like to be able to perform them via WGPU. However, it doesn't seem to be possible with the current API.

I would like to be able to define (a single) MTLCommandBuffer in my Swift code, provide this command buffer to WGPU, and to encode commands to it (e.g. apply wgsl shaders to some texture), without commiting/submiting anything. The perform commit in my Swift code.

I tried to work around this by wrapping the MTLCommandQueue and providing the MTLCommandBuffers to the WGPU code myself, but it turns out that even before submitting anything, the WGPU code creates 3 different command buffers, and defining them in advance doesn't work.
In any case, even if I managed to make it work, there's no guarantee that this solution will be stable...

@teoxoy teoxoy added the type: question Further information is requested label Aug 1, 2023
@teoxoy
Copy link
Member

teoxoy commented Aug 1, 2023

What is the reason for wanting to use the underlying MTLCommandBuffer as opposed to using wgpu's API?

I don't think we can guarantee a 1:1 mapping of wgpu objects to objects of one of our underlying platform APIs as there are extra invariants that wgpu needs to maintain which might require a one to many relationship.

See also #3517 & #3966 - but even with these, it doesn't seem that the API is as permissive as you'd like it to be.

@benjamin-kramer
Copy link
Author

The current application iOS code encodes multiple operations to the same MTLCommandBuffer. We will not be able to translate all the relevant code (tens of thousands of lines) to use WGPU at once, so we are trying to do a gradual move.

That is, we want to be able to replace the underling components one by one. These components are performed on a MTLCommandBuffer together with other components that may be Metal based.

Dividing these pipelines to multiple command buffers will result in substantial added complexity, and possibly running time (this is especially important when taking tiled-rendering into account).

@AdrianEddy
Copy link
Contributor

Check out #3338 and a real world example in Gyroflow

@benjamin-kramer
Copy link
Author

@AdrianEddy I did make use of this PR to define the device and command queue, but this issue is about encoding directly to a command buffer.

@cwfitzgerald
Copy link
Member

Take a look at #4067

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants