From 8d4bb10d443060dc56d6c6ddd9b84bbea00874d3 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Sat, 10 Nov 2018 02:41:33 -0300 Subject: gl_shader_decompiler: Guard out of bound geometry shader input reads Geometry shaders follow a pattern that results in out of bound reads. This pattern is: - VSETP to predicate - Use that predicate to conditionally set a register a big number - Use the register to access geometry shaders At the time of writing this commit I don't know what's the intent of this number. Some drivers argue about these out of bound reads. To avoid this issue, input reads are guarded limiting reads to the highest posible vertex input of the current topology (e.g. points to 1 and triangles to 3). --- src/video_core/renderer_opengl/gl_shader_cache.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/video_core/renderer_opengl/gl_shader_cache.cpp') diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp index 9522fd344..31ccf4ab8 100644 --- a/src/video_core/renderer_opengl/gl_shader_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp @@ -121,12 +121,16 @@ GLint CachedShader::GetUniformLocation(const GLShader::SamplerEntry& sampler) { } GLuint CachedShader::LazyGeometryProgram(OGLProgram& target_program, - const std::string& glsl_topology, + const std::string& glsl_topology, u32 max_vertices, const std::string& debug_name) { if (target_program.handle != 0) { return target_program.handle; } - const std::string source{geometry_programs.code + "layout (" + glsl_topology + ") in;\n"}; + std::string source = "#version 430 core\n"; + source += "layout (" + glsl_topology + ") in;\n"; + source += "#define MAX_VERTEX_INPUT " + std::to_string(max_vertices) + '\n'; + source += geometry_programs.code; + OGLShader shader; shader.Create(source.c_str(), GL_GEOMETRY_SHADER); target_program.Create(true, shader.handle); -- cgit v1.2.3