Skip to content

Unhardcode vertices#21059

Merged
Mailaender merged 5 commits into
OpenRA:bleedfrom
PunkPun:vertex
Sep 23, 2023
Merged

Unhardcode vertices#21059
Mailaender merged 5 commits into
OpenRA:bleedfrom
PunkPun:vertex

Conversation

@PunkPun

@PunkPun PunkPun commented Sep 13, 2023

Copy link
Copy Markdown
Member

This PR is a large step towards custom shader support. The first commit and ShaderBindings class are inspired by #19519 and #20581. In theory ShaderBindings will be absorbed into a Material class in the future.

Unhardcoding verticies has allowed me to remove 4 floats from a voxel vertex. While it should in theory improve perf I didn't notice any significant change on TS shellmap.

@PunkPun PunkPun force-pushed the vertex branch 4 times, most recently from 9baf2a8 to a65b158 Compare September 15, 2023 14:10

@RoosterDragon RoosterDragon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

General idea looks solid to me, some tidy-up comments added.

Comment thread OpenRA.Game/Graphics/ShaderBindings.cs Outdated
Comment thread OpenRA.Platforms.Default/Shader.cs Outdated
Comment thread OpenRA.Platforms.Default/Shader.cs Outdated
Comment thread OpenRA.Platforms.Default/ThreadedGraphicsContext.cs Outdated
Comment thread OpenRA.Platforms.Default/ThreadedGraphicsContext.cs Outdated
Comment thread OpenRA.Platforms.Default/ThreadedGraphicsContext.cs Outdated
Comment thread OpenRA.Platforms.Default/ThreadedGraphicsContext.cs Outdated
@PunkPun PunkPun force-pushed the vertex branch 2 times, most recently from bf1f780 to 1d27ee5 Compare September 16, 2023 13:32

@anvilvapre anvilvapre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems clean. Untested. I have limited knowledge of shaders.

Stack<T[]> pool;
if (!vertexBufferPools.TryGetValue(typeof(T), out var poolObject))
{
pool = new Stack<T[]>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Allocation while holding lock. May take long.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this should be called only once per type

lock (verticesPool)
if (size <= BatchSize && verticesPool.Count > 0)
return verticesPool.Pop();
lock (vertexBufferPools)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How many types do you expect there to be.

(Perhaps) better to have the lock at poolObject level.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I expect to have a bunch of more vertex types. At least 4

Comment thread OpenRA.Platforms.Default/ThreadedGraphicsContext.cs Outdated
Comment thread OpenRA.Platforms.Default/ThreadedGraphicsContext.cs
Comment thread OpenRA.Platforms.Default/ThreadedGraphicsContext.cs
Comment thread OpenRA.Game/Graphics/SpriteRenderer.cs Outdated
Comment thread OpenRA.Platforms.Default/ThreadedGraphicsContext.cs Outdated
Comment thread OpenRA.Platforms.Default/ThreadedGraphicsContext.cs Outdated
Comment thread OpenRA.Game/Graphics/Vertex.cs Outdated
var filename = Path.Combine(Platform.EngineDir, "glsl", name + "." + ext);
var code = File.ReadAllText(filename);

var version = OpenGL.Profile == GLProfile.Embedded ? "300 es" :

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can this move into ShaderBindings to avoid magic manipulation of shader code that implementations can't control?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I need to change the scope of this class to OpenRA.Platforms.Default or pass the profile

@PunkPun PunkPun Sep 18, 2023

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

it's actually hard to do either. This is currently dependency injected into a scope that has no idea about opengl

Comment thread OpenRA.Game/Renderer.cs

WorldSpriteRenderer = new SpriteRenderer(this, Context.CreateShader("combined"));
var combinedBindings = new CombinedShaderBindings();
WorldSpriteRenderer = new SpriteRenderer(this, Context.CreateShader(combinedBindings));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For a future PR (definitely out of scope here): Would it be possible to have a very minimal (no palettes, no secondary sheet, no tint etc) renderer hardcoded for use by the load screen, and then defer all of these ones until after ModData is available? This would then let shaders modify their behaviour (e.g. changing the shader code that is loaded) based on the manifest data.

@PunkPun PunkPun Sep 18, 2023

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

world renderers can be deferred without errors. The instantiation of whole classes can be deferred.

The problem comes with the UI renderer, there are some issues when trying to delay its shader. Granted I haven't fully tried to fix them

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Those problems will be due to the loadscreens right? this is why I suggested keeping a minimal one around for that.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've delayed the initialisation on ModelRenderer in #21066

@Mailaender Mailaender left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Typo in commit message.

@Mailaender Mailaender changed the title Unhardcode verticies Unhardcode vertices Sep 23, 2023
@PunkPun

PunkPun commented Sep 23, 2023

Copy link
Copy Markdown
Member Author

fixed

@Mailaender Mailaender merged commit c009f58 into OpenRA:bleed Sep 23, 2023
@Mailaender

Copy link
Copy Markdown
Member

Changelog

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.

5 participants