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

VideoCommon: Cache native vertex formats #463

Merged
merged 1 commit into from Jul 6, 2014

Conversation

degasus
Copy link
Member

@degasus degasus commented Jun 5, 2014

We are used to have a 1:1 mapping of GX vertex formats and the native (OGL + D3D) ones, but there are by far more GX ones.
This new cache maps them directly so that we don't flush on GX vertex format changes as long as the native one doesn't change.

The idea is stolen from galop1n.

@@ -38,6 +38,7 @@ namespace VertexLoaderManager
{

static VertexLoaderMap g_VertexLoaderMap;
std::map<PortableVertexDeclaration, NativeVertexFormat*> g_native_vertex_cache;

This comment was marked as off-topic.

This comment was marked as off-topic.

@degasus
Copy link
Member Author

degasus commented Jun 5, 2014

galop1n's comments are copied from: degasus@6b42af2

@@ -55,6 +56,11 @@ void Shutdown()
delete p.second;
}
g_VertexLoaderMap.clear();
for (auto& v :g_native_vertex_cache)

This comment was marked as off-topic.

@degasus
Copy link
Member Author

degasus commented Jun 6, 2014

updated to use unique_ptr

@degasus
Copy link
Member Author

degasus commented Jun 6, 2014

updated again to work around vs issue which doesn't know about std::map::emplace_hint

@@ -20,6 +23,8 @@ namespace VertexLoaderManager

// For debugging
void AppendListToString(std::string *dest);

extern std::map<PortableVertexDeclaration, std::unique_ptr<NativeVertexFormat> > g_native_vertex_cache;

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

@degasus
Copy link
Member Author

degasus commented Jul 3, 2014

Updated with a Get* Function instead of a global

@Sonicadvance1
Copy link
Contributor

LGTM.
Now we just need to VertexLoaderManager changed over to a class so we get rid of ugly globals.
Out of the scope of this PR though ;)

@@ -131,6 +135,18 @@ int GetVertexSize(int vtx_attr_group)
return RefreshLoader(vtx_attr_group)->GetVertexSize();
}

NativeVertexFormat *GetNativeVertexFormat(const PortableVertexDeclaration& format, u32 components) {

This comment was marked as off-topic.

@delroth
Copy link
Member

delroth commented Jul 4, 2014

@JMC47 care for some performance testing?

@JMC47
Copy link
Contributor

JMC47 commented Jul 4, 2014

I'm guessing higher polygon games would be more affected, right? I tried out both Galaxy games and was unable to determine a difference in speed. Maybe MaJoR could try out Last Story and see if that beast of a game is affected.

@degasus
Copy link
Member Author

degasus commented Jul 4, 2014

The amount of primitives doesn't affect this change. It is only affected if a game engine uses lots of different vertex formats alternatingly which only differs in vertex attribute type.

@galop1n
Copy link
Contributor

galop1n commented Jul 4, 2014

The game i made the optim first was Donkey Kong ( won 30% of flush ), you
can look at the stat display for the amount of flush to compare the
influence between a build with an without the optim.

On Fri, Jul 4, 2014 at 2:02 PM, Markus Wick notifications@github.com
wrote:

The amount of primitives doesn't affect this change. It is only affected
if a game engine uses lots of different vertex formats alternatingly which
only differs in vertex attribute type.


Reply to this email directly or view it on GitHub
#463 (comment).

@degasus
Copy link
Member Author

degasus commented Jul 4, 2014

I haven't seen any win of flushes (I haven't tried Donkey Kong), but I saw a lot of redundant vertex formats, so imo it's still better for the driver through.

-30% of flushes is a nice improvment :)


namespace VertexLoaderManager
{

static VertexLoaderMap g_VertexLoaderMap;
static NativeVertexLoaderMap g_native_vertex_map;

This comment was marked as off-topic.

@neobrain
Copy link
Member

neobrain commented Jul 4, 2014

Apart from the two coding style issues, LGTM.

We are used to have a 1:1 mapping of GX vertex formats and the native (OGL + D3D) ones, but there are by far more GX ones.
This new cache maps them directly so that we don't flush on GX vertex format changes as long as the native one doesn't change.

The idea is stolen from galop1n.
@degasus
Copy link
Member Author

degasus commented Jul 6, 2014

ready for merge

@JMC47
Copy link
Contributor

JMC47 commented Jul 6, 2014

I didn't notice any breakage while testing, so it looks good to me. If someone could actually get some framerate comparisons from DKCR, that'd be great for the progress report.

Sonicadvance1 added a commit that referenced this pull request Jul 6, 2014
VideoCommon: Cache native vertex formats
@Sonicadvance1 Sonicadvance1 merged commit 4483b64 into dolphin-emu:master Jul 6, 2014
@galop1n
Copy link
Contributor

galop1n commented Jul 6, 2014

it will change nothing, it was not the optim i was talking about (
comparing native vertex format to skip flushes ). That change is not a
performance optim, more a clean to not create duplicated object from the
d3d backend.

On Sun, Jul 6, 2014 at 12:21 PM, JMC47 notifications@github.com wrote:

I didn't notice any breakage while testing, so it looks good to me. If
someone could actually get some framerate comparisons from DKCR, that'd be
great for the progress report.


Reply to this email directly or view it on GitHub
#463 (comment).

@JMC47
Copy link
Contributor

JMC47 commented Jul 6, 2014

Ok, thanks for explanation.

@degasus
Copy link
Member Author

degasus commented Jul 6, 2014

@degasus degasus deleted the vertex_format_cache branch July 12, 2014 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
6 participants