summaryrefslogtreecommitdiffstats
path: root/src/video_core/renderer_opengl/gl_shader_cache.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/video_core/renderer_opengl/gl_shader_cache.h90
1 files changed, 37 insertions, 53 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.h b/src/video_core/renderer_opengl/gl_shader_cache.h
index 62b1733b4..904d15dd0 100644
--- a/src/video_core/renderer_opengl/gl_shader_cache.h
+++ b/src/video_core/renderer_opengl/gl_shader_cache.h
@@ -7,6 +7,9 @@
#include <array>
#include <map>
#include <memory>
+#include <tuple>
+
+#include <glad/glad.h>
#include "common/assert.h"
#include "common/common_types.h"
@@ -23,6 +26,16 @@ class RasterizerOpenGL;
using Shader = std::shared_ptr<CachedShader>;
using Maxwell = Tegra::Engines::Maxwell3D::Regs;
+struct BaseBindings {
+ u32 cbuf{};
+ u32 gmem{};
+ u32 sampler{};
+
+ bool operator<(const BaseBindings& rhs) const {
+ return std::tie(cbuf, gmem, sampler) < std::tie(rhs.cbuf, rhs.gmem, rhs.sampler);
+ }
+};
+
class CachedShader final : public RasterizerCacheObject {
public:
CachedShader(VAddr addr, Maxwell::ShaderProgram program_type);
@@ -44,71 +57,42 @@ public:
}
/// Gets the GL program handle for the shader
- GLuint GetProgramHandle(GLenum primitive_mode) {
- if (program_type != Maxwell::ShaderProgram::Geometry) {
- return program.handle;
- }
- switch (primitive_mode) {
- case GL_POINTS:
- return LazyGeometryProgram(geometry_programs.points, "points", 1, "ShaderPoints");
- case GL_LINES:
- case GL_LINE_STRIP:
- return LazyGeometryProgram(geometry_programs.lines, "lines", 2, "ShaderLines");
- case GL_LINES_ADJACENCY:
- case GL_LINE_STRIP_ADJACENCY:
- return LazyGeometryProgram(geometry_programs.lines_adjacency, "lines_adjacency", 4,
- "ShaderLinesAdjacency");
- case GL_TRIANGLES:
- case GL_TRIANGLE_STRIP:
- case GL_TRIANGLE_FAN:
- return LazyGeometryProgram(geometry_programs.triangles, "triangles", 3,
- "ShaderTriangles");
- case GL_TRIANGLES_ADJACENCY:
- case GL_TRIANGLE_STRIP_ADJACENCY:
- return LazyGeometryProgram(geometry_programs.triangles_adjacency, "triangles_adjacency",
- 6, "ShaderTrianglesAdjacency");
- default:
- UNREACHABLE_MSG("Unknown primitive mode.");
- return LazyGeometryProgram(geometry_programs.points, "points", 1, "ShaderPoints");
- }
- }
+ std::tuple<GLuint, BaseBindings> GetProgramHandle(GLenum primitive_mode,
+ BaseBindings base_bindings);
- /// Gets the GL program resource location for the specified resource, caching as needed
- GLuint GetProgramResourceIndex(const GLShader::ConstBufferEntry& buffer);
+private:
+ // Geometry programs. These are needed because GLSL needs an input topology but it's not
+ // declared by the hardware. Workaround this issue by generating a different shader per input
+ // topology class.
+ struct GeometryPrograms {
+ OGLProgram points;
+ OGLProgram lines;
+ OGLProgram lines_adjacency;
+ OGLProgram triangles;
+ OGLProgram triangles_adjacency;
+ };
- /// Gets the GL program resource location for the specified resource, caching as needed
- GLuint GetProgramResourceIndex(const GLShader::GlobalMemoryEntry& global_mem);
+ std::string AllocateBindings(BaseBindings base_bindings);
- /// Gets the GL uniform location for the specified resource, caching as needed
- GLint GetUniformLocation(const GLShader::SamplerEntry& sampler);
+ GLuint GetGeometryShader(GLenum primitive_mode, BaseBindings base_bindings);
-private:
/// Generates a geometry shader or returns one that already exists.
- GLuint LazyGeometryProgram(OGLProgram& target_program, const std::string& glsl_topology,
- u32 max_vertices, const std::string& debug_name);
+ GLuint LazyGeometryProgram(OGLProgram& target_program, BaseBindings base_bindings,
+ const std::string& glsl_topology, u32 max_vertices,
+ const std::string& debug_name);
void CalculateProperties();
- VAddr addr;
- std::size_t shader_length;
- Maxwell::ShaderProgram program_type;
+ VAddr addr{};
+ std::size_t shader_length{};
+ Maxwell::ShaderProgram program_type{};
GLShader::ShaderSetup setup;
GLShader::ShaderEntries entries;
- // Non-geometry program.
- OGLProgram program;
+ std::string code;
- // Geometry programs. These are needed because GLSL needs an input topology but it's not
- // declared by the hardware. Workaround this issue by generating a different shader per input
- // topology class.
- struct {
- std::string code;
- OGLProgram points;
- OGLProgram lines;
- OGLProgram lines_adjacency;
- OGLProgram triangles;
- OGLProgram triangles_adjacency;
- } geometry_programs;
+ std::map<BaseBindings, OGLProgram> programs;
+ std::map<BaseBindings, GeometryPrograms> geometry_programs;
std::map<u32, GLuint> cbuf_resource_cache;
std::map<u32, GLuint> gmem_resource_cache;