static VertexLoader* RefreshLoader(int vtx_attr_group, CPState* state)
{
	VertexLoader* loader;
	if (state->attr_dirty[vtx_attr_group])
	{
		VertexLoaderUID uid(state->vtx_desc, state->vtx_attr[vtx_attr_group]);
		std::lock_guard<std::mutex> lk(s_vertex_loader_map_lock);
		VertexLoaderMap::iterator iter = s_vertex_loader_map.find(uid);
		if (iter != s_vertex_loader_map.end())
		{
			loader = iter->second.get();
		}
		else
		{
			loader = new VertexLoader(state->vtx_desc, state->vtx_attr[vtx_attr_group]);
			s_vertex_loader_map[uid] = std::unique_ptr<VertexLoader>(loader);
			INCSTAT(stats.numVertexLoaders);
		}
		state->vertex_loaders[vtx_attr_group] = loader;
		state->attr_dirty[vtx_attr_group] = false;
	} else {
		loader = state->vertex_loaders[vtx_attr_group];
	}
	return loader;
}
Exemple #2
0
static VertexLoaderBase* RefreshLoader(int vtx_attr_group, bool preprocess = false)
{
  CPState* state = preprocess ? &g_preprocess_cp_state : &g_main_cp_state;
  state->last_id = vtx_attr_group;

  VertexLoaderBase* loader;
  if (state->attr_dirty[vtx_attr_group])
  {
    // We are not allowed to create a native vertex format on preprocessing as this is on the wrong
    // thread
    bool check_for_native_format = !preprocess;

    VertexLoaderUID uid(state->vtx_desc, state->vtx_attr[vtx_attr_group]);
    std::lock_guard<std::mutex> lk(s_vertex_loader_map_lock);
    VertexLoaderMap::iterator iter = s_vertex_loader_map.find(uid);
    if (iter != s_vertex_loader_map.end())
    {
      loader = iter->second.get();
      check_for_native_format &= !loader->m_native_vertex_format;
    }
    else
    {
      s_vertex_loader_map[uid] =
          VertexLoaderBase::CreateVertexLoader(state->vtx_desc, state->vtx_attr[vtx_attr_group]);
      loader = s_vertex_loader_map[uid].get();
      INCSTAT(stats.numVertexLoaders);
    }
    if (check_for_native_format)
    {
      // search for a cached native vertex format
      const PortableVertexDeclaration& format = loader->m_native_vtx_decl;
      std::unique_ptr<NativeVertexFormat>& native = s_native_vertex_map[format];
      if (!native)
      {
        native.reset(g_vertex_manager->CreateNativeVertexFormat(format));
      }
      loader->m_native_vertex_format = native.get();
    }
    state->vertex_loaders[vtx_attr_group] = loader;
    state->attr_dirty[vtx_attr_group] = false;
  }
  else
  {
    loader = state->vertex_loaders[vtx_attr_group];
  }

  // Lookup pointers for any vertex arrays.
  if (!preprocess)
    UpdateVertexArrayPointers();

  return loader;
}
inline VertexLoaderBase *GetOrAddLoader(const TVtxDesc &VtxDesc, const VAT &VtxAttr)
{
	VertexLoaderUID uid(VtxDesc, VtxAttr);
	VertexLoaderMap::iterator iter = s_vertex_loader_map.find(uid);
	if (iter == s_vertex_loader_map.end())
	{
		s_vertex_loader_map[uid] = VertexLoaderBase::CreateVertexLoader(VtxDesc, VtxAttr);
		VertexLoaderBase* loader = s_vertex_loader_map[uid].get();
		loader->m_native_vertex_format = GetNativeVertexFormat(loader->m_native_vtx_decl);
		VertexLoaderBase * fallback = loader->GetFallback();
		if (fallback)
		{
			fallback->m_native_vertex_format = GetNativeVertexFormat(fallback->m_native_vtx_decl);
		}
		INCSTAT(stats.numVertexLoaders);
		return loader;
	}
	return iter->second.get();
}
void AppendListToString(std::string *dest)
{
	std::vector<entry> entries;

	size_t total_size = 0;
	for (VertexLoaderMap::const_iterator iter = s_vertex_loader_map.begin(); iter != s_vertex_loader_map.end(); ++iter)
	{
		entry e;
		iter->second->AppendToString(&e.text);
		e.num_verts = iter->second->m_numLoadedVertices;
		entries.push_back(e);
		total_size += e.text.size() + 1;
	}
	sort(entries.begin(), entries.end());
	dest->reserve(dest->size() + total_size);
	for (std::vector<entry>::const_iterator iter = entries.begin(); iter != entries.end(); ++iter)
	{
		dest->append(iter->text);
	}
}
static void DumpLoadersCode()
{
	std::vector<codeentry> entries;
	for (VertexLoaderMap::const_iterator iter = s_vertex_loader_map.begin(); iter != s_vertex_loader_map.end(); ++iter)
	{
		if (!iter->second->IsPrecompiled())
		{
			codeentry e;
			e.conf.append(To_HexString(iter->first.GetElement(0)));
			e.conf.append(", ");
			e.conf.append(To_HexString(iter->first.GetElement(1)));
			e.conf.append(", ");
			e.conf.append(To_HexString(iter->first.GetElement(2)));
			e.conf.append(", ");
			e.conf.append(To_HexString(iter->first.GetElement(3)));				
			e.name = iter->second->GetName();
			e.num_verts = iter->second->m_numLoadedVertices;
			e.hash = std::to_string(iter->first.GetHash());
			entries.push_back(e);
		}
	}
	if (entries.size() == 0)
	{
		return;
	}		
	std::string filename = StringFromFormat("%sG_%s_pvt.h", File::GetUserPath(D_DUMP_IDX).c_str(), last_game_code.c_str());		
	std::string header;
	header.append("// Copyright 2013 Dolphin Emulator Project\n");
	header.append("// Licensed under GPLv2+\n");
	header.append("// Refer to the license.txt file included.\n");
	header.append("// Added for Ishiiruka by Tino\n");
	header.append("#pragma once\n");
	header.append("#include <map>\n");
	header.append("#include \"VideoCommon/NativeVertexFormat.h\"\n");
	header.append("class G_");
	header.append(last_game_code);
	header.append("_pvt\n{\npublic:\n");
	header.append("static void Initialize(std::map<u64, TCompiledLoaderFunction> &pvlmap);\n");
	header.append("};\n");
	std::ofstream headerfile(filename);
	headerfile << header;
	headerfile.close();
	filename = StringFromFormat("%sG_%s_pvt.cpp", File::GetUserPath(D_DUMP_IDX).c_str(), last_game_code.c_str());		
	sort(entries.begin(), entries.end());
	std::string sourcecode;
	sourcecode.append("#include \"VideoCommon/G_");
	sourcecode.append(last_game_code);
	sourcecode.append("_pvt.h\"\n");
	sourcecode.append("#include \"VideoCommon/VertexLoader_Template.h\"\n\n");
	sourcecode.append("\n\nvoid G_");
	sourcecode.append(last_game_code);
	sourcecode.append("_pvt::Initialize(std::map<u64, TCompiledLoaderFunction> &pvlmap)\n{\n");
	for (std::vector<codeentry>::const_iterator iter = entries.begin(); iter != entries.end(); ++iter)
	{
		sourcecode.append("\t// ");
		sourcecode.append(iter->name);
		sourcecode.append("\n// num_verts= ");
		sourcecode.append(std::to_string(iter->num_verts));			
		sourcecode.append("#if _M_SSE >= 0x301\n");
		sourcecode.append("\tif (cpu_info.bSSSE3)\n");
		sourcecode.append("\t{\n");
		sourcecode.append("\t\tpvlmap[");
		sourcecode.append(iter->hash);
		sourcecode.append("] = ");
		sourcecode.append("TemplatedLoader");
		sourcecode.append("<0x301, ");
		sourcecode.append(iter->conf);
		sourcecode.append(">;\n");
		sourcecode.append("\t}\n\telse\n");
		sourcecode.append("#endif\n");
		sourcecode.append("\t{\n");
		sourcecode.append("\t\tpvlmap[");
		sourcecode.append(iter->hash);
		sourcecode.append("] = ");
		sourcecode.append("TemplatedLoader");
		sourcecode.append("<0, ");
		sourcecode.append(iter->conf);
		sourcecode.append(">;\n");
		sourcecode.append("\t}\n");
	}
	sourcecode.append("}\n");
	std::ofstream out(filename);
	out << sourcecode;
	out.close();
}