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

replace WGPUSwapChain with methods for WGPUSurface #164

Closed

Conversation

rajveermalviya
Copy link
Collaborator

remove WGPUSwapChain as its already been removed from webgpu spec.

  • replaces wgpuDeviceCreateSwapChain with wgpuSurfaceConfigure
  • replaces wgpuSwapChainPresent with wgpuSurfacePresent
  • replaces wgpuSwapChainGetCurrentTextureView with wgpuSurfaceGetCurrentTexture
  • adds wgpuSurfaceUnconfigure

wgpu already supports most of these, except for wgpuSurfaceUnconfigure and WGPUSurfaceConfiguration.viewFormats

One question:

Fixes #89
Fixes #88

@rajveermalviya rajveermalviya marked this pull request as ready for review July 19, 2022 15:02
Copy link
Collaborator

@Kangz Kangz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall direction to match the Web API sounds good, but I think we need more changes than just this.

webgpu.h Outdated
// Procs of SwapChain
typedef WGPUTextureView (*WGPUProcSwapChainGetCurrentTextureView)(WGPUSwapChain swapChain);
typedef void (*WGPUProcSwapChainPresent)(WGPUSwapChain swapChain);
typedef void (*WGPUProcSurfaceConfigure)(WGPUSurface surface, WGPUDevice device, WGPUSurfaceConfiguration const * configuration);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: To match the Web API exactly, the Device would be in the WGPUSurfaceConfiguration.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

webgpu.h Outdated
typedef void (*WGPUProcSwapChainPresent)(WGPUSwapChain swapChain);
typedef void (*WGPUProcSurfaceConfigure)(WGPUSurface surface, WGPUDevice device, WGPUSurfaceConfiguration const * configuration);
typedef void (*WGPUProcSurfaceUnconfigure)(WGPUSurface surface);
typedef WGPUTexture (*WGPUProcGetCurrentTexture)(WGPUSurface surface, bool * suboptimal);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Maybe it could be a separate call, but also optionally return some optimal parameters like the size of the texture?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't separate calls to wgpuTextureGetWidth & wgpuTextureGetHeight on the returned WGPUTexture suffice?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. The texture you get should have exactly the size defined in WGPUSurfaceConfiguration otherwise the application doesn't really control when the resize happens and needs to be ready to resize other rendertargets any time. (plus if they forget to check then they'll get errors leading to rendering a black screen). At least in Dawn we have manual test that the resizing work, and it is implemented with a blit in the backends if it is needed (of course optimal would return false ^^)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

typedef void (*WGPUProcSurfaceConfigure)(WGPUSurface surface, WGPUDevice device, WGPUSurfaceConfiguration const * configuration);
typedef void (*WGPUProcSurfaceUnconfigure)(WGPUSurface surface);
typedef WGPUTexture (*WGPUProcGetCurrentTexture)(WGPUSurface surface, bool * suboptimal);
typedef void (*WGPUProcSurfacePresent)(WGPUSurface surface);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are other changes @cwfitzgerald made compared to the Web API for getting the supported formats and present mode. Maybe we should replicate some of them, and also re-discuss them in the context of a native API that's shared between projects.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#163 mentions wgpuSurfaceGetSupportedPresentModes.

for supported formats I think we can have

size_t wgpuSurfaceGetSupportedFormats(WGPUSurface surface, WGPUTextureFormats * formats);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need some kind of option structure for example to ask low bit-depth vs. high bit-depth? It could be useful for HDR.

Copy link
Collaborator Author

@rajveermalviya rajveermalviya Aug 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think wgpu currently provides a way to know that

(also we don't have hdr support in webgpu.h, yet, wgpu does though)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AstcChannel seems unrelated to the swapchain API TBH.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, apologies!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's tackle this in another PR - maybe after a mini issue-rfc kind of deal - as there is a ton of complexity there that we aren't yet equipped to deal with here. For reference: gfx-rs/wgpu#2869 is our proposal internal to wgpu which would set the stage for the HDR api.

@@ -575,6 +574,15 @@ typedef enum WGPUVertexStepMode {
WGPUVertexStepMode_Force32 = 0x7FFFFFFF
} WGPUVertexStepMode;

typedef enum WGPUSurfaceStatus {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced bool * suboptimal with an enum.
This matches SurfaceStatus in wgpu.

But still not sure if we should only have Good & Suboptimal and report others as errors.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what Outdated means in practice, but the enum sounds good.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what Outdated means in practice

in wgpu it is mapped to VK_ERROR_OUT_OF_DATE_KHR

after thinking more about it, WGPUSurfaceStatus can be

typedef enum WGPUSurfaceStatus {
    WGPUSurfaceStatus_Good = 0x00000000,  // ~ VK_SUCCESS
    WGPUSurfaceStatus_Suboptimal = 0x00000001, // ~ VK_SUBOPTIMAL_KHR
    WGPUSurfaceStatus_Timeout = 0x00000002, // ~ VK_TIMEOUT
    WGPUSurfaceStatus_Force32 = 0x7FFFFFFF
} WGPUSurfaceStatus;

removed Lost & Outdated, those can be reported as errors.

typedef void (*WGPUProcSwapChainPresent)(WGPUSwapChain swapChain);
typedef void (*WGPUProcSurfaceConfigure)(WGPUSurface surface, WGPUSurfaceConfiguration const * configuration);
typedef void (*WGPUProcSurfaceUnconfigure)(WGPUSurface surface);
typedef WGPUTexture (*WGPUProcSurfaceGetCurrentTexture)(WGPUSurface surface, uint32_t * width, uint32_t * height, WGPUSurfaceStatus * status);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why we need to return all of these by pointer. width and height is whatever the user configured and is also available with wgpuTextureGetWidth/Height. Status could just be wgpuSurfaceGetStatus?

@cwfitzgerald wdyt?

Copy link
Collaborator Author

@rajveermalviya rajveermalviya Aug 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for width & height if I didn't misunderstand, didn't you propose to return them here.

for status I think we should return it via pointer to enforce users to explicitly check swapchain status

Copy link
Collaborator

@cwfitzgerald cwfitzgerald Aug 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We return this immediately, so I think it's good to have it returned in the interface immediately - I would also like to discorage a glGetError kinda interface as much as we can.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume that by "this" you mean the status? That'd work, although maybe we should support passing NULL if you don't care. The pointer is slightly unfortunate but IDK how to make a C API better then this (Maybe the function returns the status and it is the WGPUTexture that's returned by pointer? Not sure).

@lisanlow
Copy link

@Kangz @rajveermalviya I am looking forward to the changes in this PR, may I know if there is currently a road block to its completion and is there any plan to get this change into the first version of webgpu release?

@Kangz
Copy link
Collaborator

Kangz commented Sep 22, 2022

I think we need to iterate a bit more. For example we don't have the notion of orientation which would be important on Android. Returning of optimal parameters is a bit wonky at the moment etc. My suggestion is that we start a branch that's swapchain-rework and start landing PRs against it, then when ready we merge it back. It'll make it easier to discuss various parts of the swapchain separately.

@mwyrzykowski
Copy link

@Kangz it looks like the last commit to swapchain-rework was 6 months ago. Do you know if these changes are still planned for v1?

It would align the web API more directly with WebGPU.h. Currently there is a bit of a disconnect between them with Surface and SwapChain concepts in WebGPU.h but they are bundled together in GPUCanvasContext in the web specification.

@austinEng
Copy link
Collaborator

@mwyrzykowski, our team is currently more focused on getting V1 of the JavaScript API out. We may not get to reworking the native swapchain API until later.

@litherum
Copy link

this is maybe a silly question, but is it really true that updating the webgpu-native/webgpu-headers is blocked on Dawn's implementation?

Can't this repo be updated in parallel?

@austinEng
Copy link
Collaborator

It certainly can - I was simply saying that our team is probably not going to do native swapchain changes just yet.

@kainino0x kainino0x added the presentation Presenting images to surfaces like windows and canvases label Jun 29, 2023
@rajveermalviya
Copy link
Collaborator Author

superseded by #203

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
presentation Presenting images to surfaces like windows and canvases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Return a texture instead of a view by the swapchain usability of swapchain in a native context
8 participants