Skip to content

createShaderModule should return a Promise - #125

Closed
grorg wants to merge 1 commit into
gpuweb:masterfrom
grorg:shadermodule-promise
Closed

grorg wants to merge 1 commit into
gpuweb:masterfrom
grorg:shadermodule-promise

Conversation

@grorg

@grorg grorg commented Nov 20, 2018

Copy link
Copy Markdown
Contributor

No description provided.

@grorg
grorg requested review from Kangz and litherum November 20, 2018 22:19
@kainino0x

Copy link
Copy Markdown
Contributor

Tons of operations in WebGPU are asynchronous, but we usually encode the asynchronicity internally (like in OpenGL). What's the rationale for making createShaderModule special? (forgive me if this was previously decided, but if it was could you include a link?)

@grorg

grorg commented Nov 21, 2018

Copy link
Copy Markdown
Contributor Author

I don't think we ever decided this - I can't remember if we even discussed it.

I realise this could be done internally in the implementation, but at some point we're going to have to process the shaders, and I think whenever that is should be exposed as a Promise. It's one of the requests I've seen a lot for WebGPU (and WebGL).

Some other alternative locations could be:

  • When the WebGPUPipelineStageDescriptor is used, because we probably want to validate that the given entryPoint is actually in the WebGPUShaderModule. So that would be on createRenderPipeline or createComputePipeline.

  • When we commit/draw.

However, I think it makes most sense to do this as early as possible. For one thing, I expect we'll want to expose some reflection APIs to examine the shader module. It seems like you'd want compilation errors to be exposed as soon as possible.

Or maybe I'm misunderstanding what you're suggesting?

@kainino0x

Copy link
Copy Markdown
Contributor

I'm suggesting not having a Promise at all - it's not necessary (just like in WebGL) because shader compilation is async.

However there definitely does need to be a way to know whether a pipeline is ready (so you can avoid stalling on it if you have a fallback pipeline). I don't think we have another way to do that yet - Promise might be okay, but key to note is that it prevents any queuing of work, command buffer construction, etc. until the Promise returns. That seems not ideal.

@grorg

grorg commented Nov 21, 2018

Copy link
Copy Markdown
Contributor Author

Right. Pipeline creation is a set of steps. Each of the steps can cause an error. I feel like it is better to expose the errors as close to the step that caused them as possible, as long as it doesn't produce a significant pain.

I think shader validation/compilation is probably one of the places where developers want to know sooner that something went wrong, rather than later when they try to use the pipeline.

@grorg

grorg commented Nov 21, 2018

Copy link
Copy Markdown
Contributor Author

I guess I also don't quite understand the downside with this being a Promise. Yes, it means you can't queue any work until the Promise resolves, but that seems like a pretty small price to pay for getting the guarantee that a significant part of your pipeline is ready. And you're not going to pay the price often - usually just at startup.

The work is going to happen at some point. This going to be one of the more expensive parts of the pipeline validation, so I think it's fine to have developers be aware of that.

@Kangz

Kangz commented Nov 21, 2018

Copy link
Copy Markdown
Contributor

For reference here's the strawman for error handling we agreed on. We could make WebGPUShaderModule a StatusableObject, this way the application is free to wait on the validation of the shader module to complete, or proceed to use it in the same frame.

Also I expect that while the most expensive validation will be at WebGPUShaderModule creation, the most expensive operation will be pipeline creation because it's at that time that the backing drivers will perform ISA lowering and register allocation (which is very heavy to get the best performance out of the GPU).

@litherum

Copy link
Copy Markdown
Contributor

What is the mechanism for getting back the error log if shader compilation uses the maybe monad?

@grovesNL

Copy link
Copy Markdown
Contributor

There's an error callback described in the Telemetry & Fallback: Error Logging section.

@Kangz

Kangz commented Nov 21, 2018

Copy link
Copy Markdown
Contributor

Also I'd be in favor of updating the strawman by making all WebGPU objects statusable, and making WebGPUObjectStatus a dictionnary with a status, and an error message.

@grorg

grorg commented Nov 21, 2018

Copy link
Copy Markdown
Contributor Author

OK. Sounds good.

Consider this pull request killed. I'll open a new one with WebGPUObjectStatus.

@grorg grorg closed this Nov 21, 2018
@grorg
grorg deleted the shadermodule-promise branch November 21, 2018 17:30
@kainino0x

kainino0x commented Nov 21, 2018 •

Copy link
Copy Markdown
Contributor

re @grovesNL: The error log isn't designed for this case; in particular, it doesn't even send you a notification when the creation succeeds. Oh, I misread. Yes, the error log is indeed where you'll see the shader compilation error.

The Recoverable errors section is the one that would allow you to wait for creation of an object - I ought to update it to express that it is useful for more than just recoverable errors. (filed #128)

@kainino0x

Copy link
Copy Markdown
Contributor

Sorry, misread. Edited comment above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants