-
Notifications
You must be signed in to change notification settings - Fork 43
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
Conversation
There was a problem hiding this 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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 ^^)
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, apologies!
There was a problem hiding this comment.
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.
55625d5
to
b9c96db
Compare
@@ -575,6 +574,15 @@ typedef enum WGPUVertexStepMode { | |||
WGPUVertexStepMode_Force32 = 0x7FFFFFFF | |||
} WGPUVertexStepMode; | |||
|
|||
typedef enum WGPUSurfaceStatus { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
@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? |
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. |
@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. |
@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. |
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? |
It certainly can - I was simply saying that our team is probably not going to do native swapchain changes just yet. |
superseded by #203 |
remove WGPUSwapChain as its already been removed from webgpu spec.
wgpuDeviceCreateSwapChain
withwgpuSurfaceConfigure
wgpuSwapChainPresent
withwgpuSurfacePresent
wgpuSwapChainGetCurrentTextureView
withwgpuSurfaceGetCurrentTexture
wgpuSurfaceUnconfigure
wgpu
already supports most of these, except forwgpuSurfaceUnconfigure
andWGPUSurfaceConfiguration.viewFormats
One question:
WGPUSurfaceConfiguration
also havealphaMode
&colorSpace
fromGPUCanvasConfiguration
?Fixes #89
Fixes #88