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

Is wgpuSurfaceGetPreferredFormat redundant with WGPUSurfaceCapabilities.formats[0]? #290

Closed
kainino0x opened this issue May 15, 2024 · 6 comments
Labels
has resolution Issue is resolved, just needs to be done presentation Presenting images to surfaces like windows and canvases

Comments

@kainino0x
Copy link
Collaborator

Since @beaufortfrancois is trying to port some samples, I realized we probably should list the preferred format as formats[0]. Otherwise it's not obvious that formats[0] might give you the wrong format and you need to call GetPreferredFormat instead.

GetPreferredFormat is already planned to become extensible (#216) so it can take extra options into account unlike formats[0], but in the near term it won't actually have any extra options, so maybe there's no reason to have it at all yet. We can add the function once it actually has extra options.

@kainino0x kainino0x added !discuss Needs discussion (at meeting or online) presentation Presenting images to surfaces like windows and canvases labels May 15, 2024
@Kangz
Copy link
Collaborator

Kangz commented May 16, 2024

I'd definitely be in favor of removing it for now!

@kainino0x
Copy link
Collaborator Author

kainino0x commented May 23, 2024

After reviewing some code using this, I do think it's a little bit of a magic incantation to use formats[0] to get the preferred format. But probably not a big deal, compared with being redundant/unclear about how you should do things.

@kainino0x kainino0x removed the !discuss Needs discussion (at meeting or online) label Jun 6, 2024
@kainino0x
Copy link
Collaborator Author

May 23 meeting (sorry for delay):

  • AE/KN: Both in favor of doing this
  • CF: me too
  • KN: eventually JS spec may have srgb, hdr, etc.
  • AE: Can you get this information by just filtering and looking for first match?
  • KN: Probably? If you filter to a format that you need, then the first one you get should be the preferred one? Could use this as a basic heuristic?
  • AE: What about WASM? Would we get only the JS-allowed format?
  • KN: Yea, but there’s 3 formats, so ordering would tell us what's the preferred one.
  • Remove wgpuSurfaceGetPreferredFormat, formats[0] is preferred.

@kainino0x kainino0x added the has resolution Issue is resolved, just needs to be done label Jun 6, 2024
@kainino0x kainino0x added the needs docs Non-trivial API contract needs to be documented. Orthogonal to open vs closed; remove when doc'd. label Jun 7, 2024
@yig
Copy link

yig commented Aug 20, 2024

If wgpuSurfaceGetPreferredFormat() is coming back with an extra options struct, perhaps it can be left in place with a placeholder nullable WGPUSurfaceGetPreferredFormatOptions struct parameter? It is much more pleasant to write

    .format = wgpuSurfaceGetPreferredFormat( surface, adapter, nullptr ), // Sokol-style designated initializer

versus

WGPUSurfaceCapabilities capabilities;
wgpuSurfaceGetCapabilities( surface, adapter, &capabilities );
something.format = capabilities.formats[0];
wgpuSurfaceCapabilitiesFreeMembers( capabilities );

@kainino0x
Copy link
Collaborator Author

I don't think it is coming back very soon, as it will be some time before the JS API has any arguments to getPreferredCanvasFormat(), and we're planning to stabilize webgpu.h before that.

@Kangz
Copy link
Collaborator

Kangz commented Aug 28, 2024

Done in #319.

@Kangz Kangz closed this as completed Aug 28, 2024
@kainino0x kainino0x removed the needs docs Non-trivial API contract needs to be documented. Orthogonal to open vs closed; remove when doc'd. label Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has resolution Issue is resolved, just needs to be done presentation Presenting images to surfaces like windows and canvases
Projects
None yet
Development

No branches or pull requests

3 participants