mirror of
https://github.com/yuzu-emu/yuzu-mainline.git
synced 2024-12-25 21:15:36 +00:00
gl_shader_cache: Use an u32 for the binding point cache.
The std::string generation with its malloc and free requirement was a noticeable overhead. Also switch to an ordered_map to avoid the std::hash call. As those maps usually have a size of two elements, the lookup time shall not matter.
This commit is contained in:
parent
dda4b5e89e
commit
99a71580c4
|
@ -709,7 +709,7 @@ std::tuple<u8*, GLintptr, u32> RasterizerOpenGL::SetupConstBuffers(u8* buffer_pt
|
||||||
|
|
||||||
// Now configure the bindpoint of the buffer inside the shader
|
// Now configure the bindpoint of the buffer inside the shader
|
||||||
glUniformBlockBinding(shader->GetProgramHandle(),
|
glUniformBlockBinding(shader->GetProgramHandle(),
|
||||||
shader->GetProgramResourceIndex(used_buffer.GetName()),
|
shader->GetProgramResourceIndex(used_buffer),
|
||||||
current_bindpoint + bindpoint);
|
current_bindpoint + bindpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -733,7 +733,7 @@ u32 RasterizerOpenGL::SetupTextures(Maxwell::ShaderStage stage, Shader& shader,
|
||||||
|
|
||||||
// Bind the uniform to the sampler.
|
// Bind the uniform to the sampler.
|
||||||
|
|
||||||
glProgramUniform1i(shader->GetProgramHandle(), shader->GetUniformLocation(entry.GetName()),
|
glProgramUniform1i(shader->GetProgramHandle(), shader->GetUniformLocation(entry),
|
||||||
current_bindpoint);
|
current_bindpoint);
|
||||||
|
|
||||||
const auto texture = maxwell3d.GetStageTexture(entry.GetStage(), entry.GetOffset());
|
const auto texture = maxwell3d.GetStageTexture(entry.GetStage(), entry.GetOffset());
|
||||||
|
|
|
@ -85,23 +85,23 @@ CachedShader::CachedShader(VAddr addr, Maxwell::ShaderProgram program_type)
|
||||||
SetShaderUniformBlockBindings(program.handle);
|
SetShaderUniformBlockBindings(program.handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint CachedShader::GetProgramResourceIndex(const std::string& name) {
|
GLuint CachedShader::GetProgramResourceIndex(const GLShader::ConstBufferEntry& buffer) {
|
||||||
auto search{resource_cache.find(name)};
|
auto search{resource_cache.find(buffer.GetHash())};
|
||||||
if (search == resource_cache.end()) {
|
if (search == resource_cache.end()) {
|
||||||
const GLuint index{
|
const GLuint index{
|
||||||
glGetProgramResourceIndex(program.handle, GL_UNIFORM_BLOCK, name.c_str())};
|
glGetProgramResourceIndex(program.handle, GL_UNIFORM_BLOCK, buffer.GetName().c_str())};
|
||||||
resource_cache[name] = index;
|
resource_cache[buffer.GetHash()] = index;
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
return search->second;
|
return search->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLint CachedShader::GetUniformLocation(const std::string& name) {
|
GLint CachedShader::GetUniformLocation(const GLShader::SamplerEntry& sampler) {
|
||||||
auto search{uniform_cache.find(name)};
|
auto search{uniform_cache.find(sampler.GetHash())};
|
||||||
if (search == uniform_cache.end()) {
|
if (search == uniform_cache.end()) {
|
||||||
const GLint index{glGetUniformLocation(program.handle, name.c_str())};
|
const GLint index{glGetUniformLocation(program.handle, sampler.GetName().c_str())};
|
||||||
uniform_cache[name] = index;
|
uniform_cache[sampler.GetHash()] = index;
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "video_core/rasterizer_cache.h"
|
#include "video_core/rasterizer_cache.h"
|
||||||
|
@ -43,10 +43,10 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the GL program resource location for the specified resource, caching as needed
|
/// Gets the GL program resource location for the specified resource, caching as needed
|
||||||
GLuint GetProgramResourceIndex(const std::string& name);
|
GLuint GetProgramResourceIndex(const GLShader::ConstBufferEntry& buffer);
|
||||||
|
|
||||||
/// Gets the GL uniform location for the specified resource, caching as needed
|
/// Gets the GL uniform location for the specified resource, caching as needed
|
||||||
GLint GetUniformLocation(const std::string& name);
|
GLint GetUniformLocation(const GLShader::SamplerEntry& sampler);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VAddr addr;
|
VAddr addr;
|
||||||
|
@ -55,8 +55,8 @@ private:
|
||||||
GLShader::ShaderEntries entries;
|
GLShader::ShaderEntries entries;
|
||||||
OGLProgram program;
|
OGLProgram program;
|
||||||
|
|
||||||
std::unordered_map<std::string, GLuint> resource_cache;
|
std::map<u32, GLuint> resource_cache;
|
||||||
std::unordered_map<std::string, GLint> uniform_cache;
|
std::map<u32, GLint> uniform_cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ShaderCacheOpenGL final : public RasterizerCache<Shader> {
|
class ShaderCacheOpenGL final : public RasterizerCache<Shader> {
|
||||||
|
|
|
@ -53,6 +53,10 @@ public:
|
||||||
return BufferBaseNames[static_cast<size_t>(stage)] + std::to_string(index);
|
return BufferBaseNames[static_cast<size_t>(stage)] + std::to_string(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u32 GetHash() const {
|
||||||
|
return (static_cast<u32>(stage) << 16) | index;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr std::array<const char*, Maxwell::MaxShaderStage> BufferBaseNames = {
|
static constexpr std::array<const char*, Maxwell::MaxShaderStage> BufferBaseNames = {
|
||||||
"buffer_vs_c", "buffer_tessc_c", "buffer_tesse_c", "buffer_gs_c", "buffer_fs_c",
|
"buffer_vs_c", "buffer_tessc_c", "buffer_tesse_c", "buffer_gs_c", "buffer_fs_c",
|
||||||
|
@ -89,6 +93,10 @@ public:
|
||||||
std::to_string(sampler_index) + ']';
|
std::to_string(sampler_index) + ']';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u32 GetHash() const {
|
||||||
|
return (static_cast<u32>(stage) << 16) | static_cast<u32>(sampler_index);
|
||||||
|
}
|
||||||
|
|
||||||
static std::string GetArrayName(Maxwell::ShaderStage stage) {
|
static std::string GetArrayName(Maxwell::ShaderStage stage) {
|
||||||
return TextureSamplerNames[static_cast<size_t>(stage)];
|
return TextureSamplerNames[static_cast<size_t>(stage)];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue