-
Notifications
You must be signed in to change notification settings - Fork 194
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
Constant propagation #97
Comments
I have been thinking about this during the weekend, and I don't think your outline is the best approach. As far as I can tell, you get problems no matter which subset of Expression you choose for ConstExpression:
In both cases we get friction from having duplication between Expression and ConstExpression, and we also need to do extra work if we want constant folding optimizations for normal expressions. Instead I propose that we change ArraySize::Static to contain a normal Expression. Then we can implement constant folding for all expressions in the IR, and have a step in the validator that checks that all expressions in ArraySize::Static are Constant after the constant folding. Does that make sense, or have I missed something? |
I thought this is something we'll need, but now there is a bit of doubt, see gpuweb/gpuweb#905
I'm not sure what you mean here by "the frontend needs to do inlining", please elaborate! The way I see it: when the front-end encounters a constant, its expression parsing gets the "constant" mode. So seeing A + B constants, it will use the constant expression
Variables are not constants by definition :) constant expression enum doesn't need to include those variants.
I don't know how much duplication there's really going to be. Roughly, we'll need the following variants:
This doesn't look too scary to me, although I agree that some friction will be present.
Wouldn't this make it easier? Constant folding would require precisely the same separation of constant mode vs regular expression mode that I described, so it seems like it would be a piece of cake to get if we need it. Concluding a bit, I know what can be done here, but I don't know (or have a strong feeling) on what should be done. We can proceed with your GLSL changes and see what WebGPU group decides. It could be that we'll just leave |
So, the group's resolution for now is to not have the constant propagation in WGSL. |
Another option would be to remove the serializer entirely from the local variables... which is fine, semantically speaking, since everything is expected to be zero-initialized, at least in |
We should allow constant expressions for array sizes. This needs IR changes:
enum ConstExpression
that takes a subset ofExpression
that's valid for constant propagationExpression::Const(Handle<ConstExpression>)
to transition from regular expressions (instead of the currentExpression::Constant
)pub const_expressions: Arena<ConstExpression>
in a functionThe text was updated successfully, but these errors were encountered: