summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Markus Wick2018-11-20 20:14:48 +0100
committerGravatar Markus Wick2018-11-20 21:58:31 +0100
commitcfbae58b2b3020a614a79326f0da3ecdf8bb70bf (patch)
treee28b40c809fc2e5f1ac4043fca8340c667cbbf67 /src
parentMerge pull request #1667 from DarkLordZach/swkbd (diff)
downloadyuzu-cfbae58b2b3020a614a79326f0da3ecdf8bb70bf.tar.gz
yuzu-cfbae58b2b3020a614a79326f0da3ecdf8bb70bf.tar.xz
yuzu-cfbae58b2b3020a614a79326f0da3ecdf8bb70bf.zip
shader_cache: Only lock covered instructions.
Diffstat (limited to 'src')
-rw-r--r--src/video_core/renderer_opengl/gl_shader_cache.cpp1
-rw-r--r--src/video_core/renderer_opengl/gl_shader_cache.h3
-rw-r--r--src/video_core/renderer_opengl/gl_shader_decompiler.cpp27
-rw-r--r--src/video_core/renderer_opengl/gl_shader_gen.h1
4 files changed, 24 insertions, 8 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp
index a85a7c0c5..038b25c75 100644
--- a/src/video_core/renderer_opengl/gl_shader_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp
@@ -84,6 +84,7 @@ CachedShader::CachedShader(VAddr addr, Maxwell::ShaderProgram program_type)
84 } 84 }
85 85
86 entries = program_result.second; 86 entries = program_result.second;
87 shader_length = entries.shader_length;
87 88
88 if (program_type != Maxwell::ShaderProgram::Geometry) { 89 if (program_type != Maxwell::ShaderProgram::Geometry) {
89 OGLShader shader; 90 OGLShader shader;
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.h b/src/video_core/renderer_opengl/gl_shader_cache.h
index ffbf21831..08f470de3 100644
--- a/src/video_core/renderer_opengl/gl_shader_cache.h
+++ b/src/video_core/renderer_opengl/gl_shader_cache.h
@@ -30,7 +30,7 @@ public:
30 } 30 }
31 31
32 std::size_t GetSizeInBytes() const override { 32 std::size_t GetSizeInBytes() const override {
33 return GLShader::MAX_PROGRAM_CODE_LENGTH * sizeof(u64); 33 return shader_length;
34 } 34 }
35 35
36 // We do not have to flush this cache as things in it are never modified by us. 36 // We do not have to flush this cache as things in it are never modified by us.
@@ -82,6 +82,7 @@ private:
82 u32 max_vertices, const std::string& debug_name); 82 u32 max_vertices, const std::string& debug_name);
83 83
84 VAddr addr; 84 VAddr addr;
85 std::size_t shader_length;
85 Maxwell::ShaderProgram program_type; 86 Maxwell::ShaderProgram program_type;
86 GLShader::ShaderSetup setup; 87 GLShader::ShaderSetup setup;
87 GLShader::ShaderEntries entries; 88 GLShader::ShaderEntries entries;
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
index 5fde22ad4..8e7b10c4c 100644
--- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
@@ -85,7 +85,8 @@ struct Subroutine {
85class ControlFlowAnalyzer { 85class ControlFlowAnalyzer {
86public: 86public:
87 ControlFlowAnalyzer(const ProgramCode& program_code, u32 main_offset, const std::string& suffix) 87 ControlFlowAnalyzer(const ProgramCode& program_code, u32 main_offset, const std::string& suffix)
88 : program_code(program_code) { 88 : program_code(program_code), shader_coverage_begin(main_offset),
89 shader_coverage_end(main_offset + 1) {
89 90
90 // Recursively finds all subroutines. 91 // Recursively finds all subroutines.
91 const Subroutine& program_main = AddSubroutine(main_offset, PROGRAM_END, suffix); 92 const Subroutine& program_main = AddSubroutine(main_offset, PROGRAM_END, suffix);
@@ -97,10 +98,16 @@ public:
97 return std::move(subroutines); 98 return std::move(subroutines);
98 } 99 }
99 100
101 std::size_t GetShaderLength() const {
102 return shader_coverage_end * sizeof(u64);
103 }
104
100private: 105private:
101 const ProgramCode& program_code; 106 const ProgramCode& program_code;
102 std::set<Subroutine> subroutines; 107 std::set<Subroutine> subroutines;
103 std::map<std::pair<u32, u32>, ExitMethod> exit_method_map; 108 std::map<std::pair<u32, u32>, ExitMethod> exit_method_map;
109 u32 shader_coverage_begin;
110 u32 shader_coverage_end;
104 111
105 /// Adds and analyzes a new subroutine if it is not added yet. 112 /// Adds and analyzes a new subroutine if it is not added yet.
106 const Subroutine& AddSubroutine(u32 begin, u32 end, const std::string& suffix) { 113 const Subroutine& AddSubroutine(u32 begin, u32 end, const std::string& suffix) {
@@ -142,6 +149,9 @@ private:
142 return exit_method; 149 return exit_method;
143 150
144 for (u32 offset = begin; offset != end && offset != PROGRAM_END; ++offset) { 151 for (u32 offset = begin; offset != end && offset != PROGRAM_END; ++offset) {
152 shader_coverage_begin = std::min(shader_coverage_begin, offset);
153 shader_coverage_end = std::max(shader_coverage_end, offset + 1);
154
145 const Instruction instr = {program_code[offset]}; 155 const Instruction instr = {program_code[offset]};
146 if (const auto opcode = OpCode::Decode(instr)) { 156 if (const auto opcode = OpCode::Decode(instr)) {
147 switch (opcode->get().GetId()) { 157 switch (opcode->get().GetId()) {
@@ -951,9 +961,10 @@ private:
951class GLSLGenerator { 961class GLSLGenerator {
952public: 962public:
953 GLSLGenerator(const std::set<Subroutine>& subroutines, const ProgramCode& program_code, 963 GLSLGenerator(const std::set<Subroutine>& subroutines, const ProgramCode& program_code,
954 u32 main_offset, Maxwell3D::Regs::ShaderStage stage, const std::string& suffix) 964 u32 main_offset, Maxwell3D::Regs::ShaderStage stage, const std::string& suffix,
965 std::size_t shader_length)
955 : subroutines(subroutines), program_code(program_code), main_offset(main_offset), 966 : subroutines(subroutines), program_code(program_code), main_offset(main_offset),
956 stage(stage), suffix(suffix) { 967 stage(stage), suffix(suffix), shader_length(shader_length) {
957 std::memcpy(&header, program_code.data(), sizeof(Tegra::Shader::Header)); 968 std::memcpy(&header, program_code.data(), sizeof(Tegra::Shader::Header));
958 local_memory_size = header.GetLocalMemorySize(); 969 local_memory_size = header.GetLocalMemorySize();
959 regs.SetLocalMemory(local_memory_size); 970 regs.SetLocalMemory(local_memory_size);
@@ -966,7 +977,7 @@ public:
966 977
967 /// Returns entries in the shader that are useful for external functions 978 /// Returns entries in the shader that are useful for external functions
968 ShaderEntries GetEntries() const { 979 ShaderEntries GetEntries() const {
969 return {regs.GetConstBuffersDeclarations(), regs.GetSamplers()}; 980 return {regs.GetConstBuffersDeclarations(), regs.GetSamplers(), shader_length};
970 } 981 }
971 982
972private: 983private:
@@ -3827,6 +3838,7 @@ private:
3827 Maxwell3D::Regs::ShaderStage stage; 3838 Maxwell3D::Regs::ShaderStage stage;
3828 const std::string& suffix; 3839 const std::string& suffix;
3829 u64 local_memory_size; 3840 u64 local_memory_size;
3841 std::size_t shader_length;
3830 3842
3831 ShaderWriter shader; 3843 ShaderWriter shader;
3832 ShaderWriter declarations; 3844 ShaderWriter declarations;
@@ -3845,9 +3857,10 @@ std::optional<ProgramResult> DecompileProgram(const ProgramCode& program_code, u
3845 Maxwell3D::Regs::ShaderStage stage, 3857 Maxwell3D::Regs::ShaderStage stage,
3846 const std::string& suffix) { 3858 const std::string& suffix) {
3847 try { 3859 try {
3848 const auto subroutines = 3860 ControlFlowAnalyzer analyzer(program_code, main_offset, suffix);
3849 ControlFlowAnalyzer(program_code, main_offset, suffix).GetSubroutines(); 3861 const auto subroutines = analyzer.GetSubroutines();
3850 GLSLGenerator generator(subroutines, program_code, main_offset, stage, suffix); 3862 GLSLGenerator generator(subroutines, program_code, main_offset, stage, suffix,
3863 analyzer.GetShaderLength());
3851 return ProgramResult{generator.GetShaderCode(), generator.GetEntries()}; 3864 return ProgramResult{generator.GetShaderCode(), generator.GetEntries()};
3852 } catch (const DecompileFail& exception) { 3865 } catch (const DecompileFail& exception) {
3853 LOG_ERROR(HW_GPU, "Shader decompilation failed: {}", exception.what()); 3866 LOG_ERROR(HW_GPU, "Shader decompilation failed: {}", exception.what());
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.h b/src/video_core/renderer_opengl/gl_shader_gen.h
index 520b9d4e3..b425d98ae 100644
--- a/src/video_core/renderer_opengl/gl_shader_gen.h
+++ b/src/video_core/renderer_opengl/gl_shader_gen.h
@@ -163,6 +163,7 @@ private:
163struct ShaderEntries { 163struct ShaderEntries {
164 std::vector<ConstBufferEntry> const_buffer_entries; 164 std::vector<ConstBufferEntry> const_buffer_entries;
165 std::vector<SamplerEntry> texture_samplers; 165 std::vector<SamplerEntry> texture_samplers;
166 std::size_t shader_length;
166}; 167};
167 168
168using ProgramResult = std::pair<std::string, ShaderEntries>; 169using ProgramResult = std::pair<std::string, ShaderEntries>;