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

Cleanup common Renderer methods #6186

Merged
merged 8 commits into from Feb 26, 2024
Merged

Conversation

smoogipoo
Copy link
Contributor

  • Adds Renderer.DrawVertices(), which is the method that binds the global UBO.
  • Makes globalUniformBuffer private.
  • Adds Renderer.BindUniformBuffer(), which does the state tracking/de-duping of flushes around UBO bindings.
  • A few other misc cleanups.

Comment on lines +971 to +972
if (Shader == null)
throw new InvalidOperationException("No shader bound.");
Copy link
Collaborator

Choose a reason for hiding this comment

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

This guard is slightly out of left field... I'm hoping it's just there for general usage safety?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's for general usage safety. It's probably not strictly required.

Comment on lines +1045 to +1054
public void BindUniformBuffer(string blockName, IUniformBuffer buffer)
{
if (boundUniformBuffers.TryGetValue(blockName, out IUniformBuffer? current) && current == buffer)
return;

FlushCurrentBatch(FlushBatchSource.BindBuffer);
SetUniformBufferImplementation(blockName, buffer);

boundUniformBuffers[blockName] = buffer;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This change weirds me out. The buffer tracking is added to the base Renderer, but both renderer implementations still maintain their own boundUniformBuffers dictionaries? Is this intentional just for the type safety or something? It sure is going to cause memory overheads (although they're likely not relevant).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was just the simplest way for me to move the most common logic (dedupe/flush) to the base class.

Something to consider is that they can only be "bound" in DrawVertices. With the way things currently work, it's unsafe to do it earlier than that because there could be misordered events, for example:

shader.BindUniformBuffer()
shader.Bind()
// Or
shader.Bind()
shader.BindUniformBuffer()

At least, we don't explicitly state that the bind order must be shader -> uniform buffer...

The situation can probably be improved in the future, perhaps by storing the bound UBOs to the shader instead.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the misordering issue a blocker for e.g. exposing Renderer's dictionary as protected and then using that in renderer implementations, rather than have the base renderer track as well as the implementations?

Copy link
Contributor Author

@smoogipoo smoogipoo Feb 22, 2024

Choose a reason for hiding this comment

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

That sounds backwards to me because I'm tending towards making more of this class private like I did with the global UBO. The remaining protected ones are even too much for me.

For implementers I think it makes more sense to be given abstract methods to store whatever state they need from, rather than to piece together the parts of Renderer that they need at some point...

Comment on lines 130 to 133
while (renderer.IsFrameBufferBound(this))
Unbind();

deleteResources(true);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is just inlining the old method right? Commit message mentions "avoiding redirection" so I just want to make sure I'm understanding correctly and this isn't some lower-level concern.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, just inlining it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just looking through things again, GLRenderer does the same thing. It might be worth moving this to the base Renderer class instead...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you going to be trying for that? Not sure whether this PR is safe to re-review otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, I've moved it back & added a common method in Renderer. Actually, the implementation in master is a bit scary because it disposed the FBOs immediately rather than the 3-frame-delayed ScheduleDisposal...

@peppy peppy self-requested a review February 26, 2024 05:06
@peppy peppy merged commit 944bcb4 into ppy:master Feb 26, 2024
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants