[windows]: adjusts uniform buffers to hit hlsl optimization#188538
Conversation
…ove HLSL compilation performance.
|
This looks good, we need to do this for |
There was a problem hiding this comment.
Code Review
This pull request refactors several shaders and their corresponding host-side rendering code to move large arrays (such as colors, stop pairs, and kernel samples) into dedicated uniform blocks, preventing size and alignment issues on certain graphics platforms. Feedback recommends passing the temporary returned by GenerateBlurInfo directly to LerpHackKernelSamples to enable copy elision and avoid copying a large struct.
walley892
left a comment
There was a problem hiding this comment.
LG as long as the goldens don't change
b-luk
left a comment
There was a problem hiding this comment.
LGTM. Just a couple of nits, which I'll leave up to you to decide if you think it's anything worth changing.
| float coefficient; | ||
| }; | ||
|
|
||
| /// A larger mirror of GaussianBlurPipeline::FragmentShader::KernelSamples. |
There was a problem hiding this comment.
This is no longer true. GaussianBlurPipeline::FragmentShader::KernelSamples no longer contains sample_count, so this struct is no longer a mirror of it.
There was a problem hiding this comment.
I think the comment is still helpful despite that technicality since it convey's the relationship between them. I think it's better to keep it as-is.
| KernelSample samples[kMaxKernelSize]; | ||
| }; | ||
|
|
||
| struct LerpHackResult { |
There was a problem hiding this comment.
I think this is badly named, and it makes the code a bit harder to follow. I don't know the best way to improve it, but I'd be in favor of even just removing it entirely and using a pair<int32_t, GaussianBlurPipeline::FragmentShader::KernelSamples>.
There was a problem hiding this comment.
The name of the function that generates this is LerpHackKernelSamples. I wouldn't want to switch to unstructured data since we'd be losing named fields. It's common to have a struct declared for returning multiple values. We could name it LerpHackKernelSamplesResult to be more clear if you like. Dropping some of the name didn't seem to affect the readability I my eyes, let me know.
There was a problem hiding this comment.
Maybe it's not exactly a naming issue. I think what makes it harder to follow is that we no longer have a single struct that directly represents the shader input. The behavior used to be:
GenerateBlurInfo()generatesKernalSamples, which is an expanded version of theFragmentShader::KernelSamplesshader input.LerpHackKernelSamples()converts the expandedKernalSamplesinto the inputFragmentShader::KernelSamples, which is bound to the shader.
So there's a single KernalSamples struct which directly maps to a single shader input.
Now it's:
GenerateBlurInfo()generatesKernalSamples, which is an expanded version of (FragmentShader::FragInfo::sample_count+FragmentShader::KernelSamples).LerpHackKernelSamples()convertsKernalSamplesintoLerpHackResult, which is the non-expanded version of (FragmentShader::FragInfo::sample_count+FragmentShader::KernelSamples).- The two parts of
LerpHackResultget split up to be bound to two different inputs in the shader.
We end up with two intermediate KernalSamples and LerpHackResult structs, and neither of them map directly to a shader input field.
I don't know a good way to clean this up, so I'm not blocking submission. The new version isn't super complex. Once you look at it enough you can see what's going on. But I think it does force the reader to juggle a bunch more types/fields/subfields in their head to understand the flow of data compared to the old version. And for many of the new fields it's not immediately clear/intuitive what they represent within the data flow.
There was a problem hiding this comment.
yea, it's less clear, our hand was forced based on hlsl's requirements. It looks like c++26 will have std::inplace_vector which may clean this up a bit. We won't need the struct anymore after that.
|
autosubmit label was removed for flutter/flutter/188538, because - The status or check suite Linux linux_unopt has failed. Please fix the issues identified (or deflake) before re-applying this label. |
| KernelSample samples[kMaxKernelSize]; | ||
| }; | ||
|
|
||
| struct LerpHackResult { |
There was a problem hiding this comment.
Maybe it's not exactly a naming issue. I think what makes it harder to follow is that we no longer have a single struct that directly represents the shader input. The behavior used to be:
GenerateBlurInfo()generatesKernalSamples, which is an expanded version of theFragmentShader::KernelSamplesshader input.LerpHackKernelSamples()converts the expandedKernalSamplesinto the inputFragmentShader::KernelSamples, which is bound to the shader.
So there's a single KernalSamples struct which directly maps to a single shader input.
Now it's:
GenerateBlurInfo()generatesKernalSamples, which is an expanded version of (FragmentShader::FragInfo::sample_count+FragmentShader::KernelSamples).LerpHackKernelSamples()convertsKernalSamplesintoLerpHackResult, which is the non-expanded version of (FragmentShader::FragInfo::sample_count+FragmentShader::KernelSamples).- The two parts of
LerpHackResultget split up to be bound to two different inputs in the shader.
We end up with two intermediate KernalSamples and LerpHackResult structs, and neither of them map directly to a shader input field.
I don't know a good way to clean this up, so I'm not blocking submission. The new version isn't super complex. Once you look at it enough you can see what's going on. But I think it does force the reader to juggle a bunch more types/fields/subfields in their head to understand the flow of data compared to the old version. And for many of the new fields it's not immediately clear/intuitive what they represent within the data flow.
|
CI had a failure that stopped further tests from running. We need to investigate to determine the root cause. SHA at time of execution: 87c4efc. Possible causes:
A blank commit, or merging to head, will be required to resume running CI for this PR. Error Details: Stack trace: |
|
autosubmit label was removed for flutter/flutter/188538, because - The status or check suite Linux linux_fuchsia_tests has failed. Please fix the issues identified (or deflake) before re-applying this label. |
|
this may benefit #188338 |
issue #188348
This removes the following class of HLSL warnings:
By putting large uniform arrays into their own uniform buffer the HLSL compiler in ANGLE is able to optimize the compilation using a StructuredBuffer. This removes the warning about long compilation time.
testing: refactor, no logical change
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.