diff options
| author | 2020-07-18 00:48:27 -0400 | |
|---|---|---|
| committer | 2020-07-18 00:48:27 -0400 | |
| commit | 90cbcaa44a3901a832556258b5b97d8d7de34ca9 (patch) | |
| tree | 570ff95dae035757fb2831804aae4f4ca681d354 /src/video_core/renderer_opengl | |
| parent | Merge pull request #4364 from lioncash/desig5 (diff) | |
| parent | Fix style issues (diff) | |
| download | yuzu-90cbcaa44a3901a832556258b5b97d8d7de34ca9.tar.gz yuzu-90cbcaa44a3901a832556258b5b97d8d7de34ca9.tar.xz yuzu-90cbcaa44a3901a832556258b5b97d8d7de34ca9.zip | |
Merge pull request #4273 from ogniK5377/async-shaders-prod
video_core: Add asynchronous shader decompilation and compilation
Diffstat (limited to 'src/video_core/renderer_opengl')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_device.cpp | 2 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_device.h | 5 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 24 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.h | 10 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_resource_manager.h | 6 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_cache.cpp | 181 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_cache.h | 36 |
7 files changed, 206 insertions, 58 deletions
diff --git a/src/video_core/renderer_opengl/gl_device.cpp b/src/video_core/renderer_opengl/gl_device.cpp index c1f20f0ab..630acb73b 100644 --- a/src/video_core/renderer_opengl/gl_device.cpp +++ b/src/video_core/renderer_opengl/gl_device.cpp | |||
| @@ -233,6 +233,8 @@ Device::Device() | |||
| 233 | GLAD_GL_NV_gpu_program5 && GLAD_GL_NV_compute_program5 && | 233 | GLAD_GL_NV_gpu_program5 && GLAD_GL_NV_compute_program5 && |
| 234 | GLAD_GL_NV_transform_feedback && GLAD_GL_NV_transform_feedback2; | 234 | GLAD_GL_NV_transform_feedback && GLAD_GL_NV_transform_feedback2; |
| 235 | 235 | ||
| 236 | use_asynchronous_shaders = Settings::values.use_asynchronous_shaders.GetValue(); | ||
| 237 | |||
| 236 | LOG_INFO(Render_OpenGL, "Renderer_VariableAOFFI: {}", has_variable_aoffi); | 238 | LOG_INFO(Render_OpenGL, "Renderer_VariableAOFFI: {}", has_variable_aoffi); |
| 237 | LOG_INFO(Render_OpenGL, "Renderer_ComponentIndexingBug: {}", has_component_indexing_bug); | 239 | LOG_INFO(Render_OpenGL, "Renderer_ComponentIndexingBug: {}", has_component_indexing_bug); |
| 238 | LOG_INFO(Render_OpenGL, "Renderer_PreciseBug: {}", has_precise_bug); | 240 | LOG_INFO(Render_OpenGL, "Renderer_PreciseBug: {}", has_precise_bug); |
diff --git a/src/video_core/renderer_opengl/gl_device.h b/src/video_core/renderer_opengl/gl_device.h index e1d811966..94d38d7d1 100644 --- a/src/video_core/renderer_opengl/gl_device.h +++ b/src/video_core/renderer_opengl/gl_device.h | |||
| @@ -104,6 +104,10 @@ public: | |||
| 104 | return use_assembly_shaders; | 104 | return use_assembly_shaders; |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | bool UseAsynchronousShaders() const { | ||
| 108 | return use_asynchronous_shaders; | ||
| 109 | } | ||
| 110 | |||
| 107 | private: | 111 | private: |
| 108 | static bool TestVariableAoffi(); | 112 | static bool TestVariableAoffi(); |
| 109 | static bool TestPreciseBug(); | 113 | static bool TestPreciseBug(); |
| @@ -127,6 +131,7 @@ private: | |||
| 127 | bool has_fast_buffer_sub_data{}; | 131 | bool has_fast_buffer_sub_data{}; |
| 128 | bool has_nv_viewport_array2{}; | 132 | bool has_nv_viewport_array2{}; |
| 129 | bool use_assembly_shaders{}; | 133 | bool use_assembly_shaders{}; |
| 134 | bool use_asynchronous_shaders{}; | ||
| 130 | }; | 135 | }; |
| 131 | 136 | ||
| 132 | } // namespace OpenGL | 137 | } // namespace OpenGL |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index e960a0ef1..c3fad563c 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp | |||
| @@ -149,7 +149,8 @@ RasterizerOpenGL::RasterizerOpenGL(Core::System& system, Core::Frontend::EmuWind | |||
| 149 | shader_cache{*this, system, emu_window, device}, query_cache{system, *this}, | 149 | shader_cache{*this, system, emu_window, device}, query_cache{system, *this}, |
| 150 | buffer_cache{*this, system, device, STREAM_BUFFER_SIZE}, | 150 | buffer_cache{*this, system, device, STREAM_BUFFER_SIZE}, |
| 151 | fence_manager{system, *this, texture_cache, buffer_cache, query_cache}, system{system}, | 151 | fence_manager{system, *this, texture_cache, buffer_cache, query_cache}, system{system}, |
| 152 | screen_info{info}, program_manager{program_manager}, state_tracker{state_tracker} { | 152 | screen_info{info}, program_manager{program_manager}, state_tracker{state_tracker}, |
| 153 | async_shaders{emu_window} { | ||
| 153 | CheckExtensions(); | 154 | CheckExtensions(); |
| 154 | 155 | ||
| 155 | unified_uniform_buffer.Create(); | 156 | unified_uniform_buffer.Create(); |
| @@ -162,6 +163,23 @@ RasterizerOpenGL::RasterizerOpenGL(Core::System& system, Core::Frontend::EmuWind | |||
| 162 | nullptr, 0); | 163 | nullptr, 0); |
| 163 | } | 164 | } |
| 164 | } | 165 | } |
| 166 | |||
| 167 | if (device.UseAsynchronousShaders()) { | ||
| 168 | // Max worker threads we should allow | ||
| 169 | constexpr auto MAX_THREADS = 2u; | ||
| 170 | // Amount of threads we should reserve for other parts of yuzu | ||
| 171 | constexpr auto RESERVED_THREADS = 6u; | ||
| 172 | // Get the amount of threads we can use(this can return zero) | ||
| 173 | const auto cpu_thread_count = | ||
| 174 | std::max(RESERVED_THREADS, std::thread::hardware_concurrency()); | ||
| 175 | // Deduce how many "extra" threads we have to use. | ||
| 176 | const auto max_threads_unused = cpu_thread_count - RESERVED_THREADS; | ||
| 177 | // Always allow at least 1 thread regardless of our settings | ||
| 178 | const auto max_worker_count = std::max(1u, max_threads_unused); | ||
| 179 | // Don't use more than MAX_THREADS | ||
| 180 | const auto worker_count = std::min(max_worker_count, MAX_THREADS); | ||
| 181 | async_shaders.AllocateWorkers(worker_count); | ||
| 182 | } | ||
| 165 | } | 183 | } |
| 166 | 184 | ||
| 167 | RasterizerOpenGL::~RasterizerOpenGL() { | 185 | RasterizerOpenGL::~RasterizerOpenGL() { |
| @@ -336,7 +354,7 @@ void RasterizerOpenGL::SetupShaders(GLenum primitive_mode) { | |||
| 336 | continue; | 354 | continue; |
| 337 | } | 355 | } |
| 338 | 356 | ||
| 339 | Shader* const shader = shader_cache.GetStageProgram(program); | 357 | Shader* shader = shader_cache.GetStageProgram(program, async_shaders); |
| 340 | 358 | ||
| 341 | if (device.UseAssemblyShaders()) { | 359 | if (device.UseAssemblyShaders()) { |
| 342 | // Check for ARB limitation. We only have 16 SSBOs per context state. To workaround this | 360 | // Check for ARB limitation. We only have 16 SSBOs per context state. To workaround this |
| @@ -353,7 +371,7 @@ void RasterizerOpenGL::SetupShaders(GLenum primitive_mode) { | |||
| 353 | SetupDrawTextures(stage, shader); | 371 | SetupDrawTextures(stage, shader); |
| 354 | SetupDrawImages(stage, shader); | 372 | SetupDrawImages(stage, shader); |
| 355 | 373 | ||
| 356 | const GLuint program_handle = shader->GetHandle(); | 374 | const GLuint program_handle = shader->IsBuilt() ? shader->GetHandle() : 0; |
| 357 | switch (program) { | 375 | switch (program) { |
| 358 | case Maxwell::ShaderProgram::VertexA: | 376 | case Maxwell::ShaderProgram::VertexA: |
| 359 | case Maxwell::ShaderProgram::VertexB: | 377 | case Maxwell::ShaderProgram::VertexB: |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index 4f082592f..a95646936 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h | |||
| @@ -33,6 +33,7 @@ | |||
| 33 | #include "video_core/renderer_opengl/gl_state_tracker.h" | 33 | #include "video_core/renderer_opengl/gl_state_tracker.h" |
| 34 | #include "video_core/renderer_opengl/gl_texture_cache.h" | 34 | #include "video_core/renderer_opengl/gl_texture_cache.h" |
| 35 | #include "video_core/renderer_opengl/utils.h" | 35 | #include "video_core/renderer_opengl/utils.h" |
| 36 | #include "video_core/shader/async_shaders.h" | ||
| 36 | #include "video_core/textures/texture.h" | 37 | #include "video_core/textures/texture.h" |
| 37 | 38 | ||
| 38 | namespace Core { | 39 | namespace Core { |
| @@ -91,6 +92,14 @@ public: | |||
| 91 | return num_queued_commands > 0; | 92 | return num_queued_commands > 0; |
| 92 | } | 93 | } |
| 93 | 94 | ||
| 95 | VideoCommon::Shader::AsyncShaders& GetAsyncShaders() { | ||
| 96 | return async_shaders; | ||
| 97 | } | ||
| 98 | |||
| 99 | const VideoCommon::Shader::AsyncShaders& GetAsyncShaders() const { | ||
| 100 | return async_shaders; | ||
| 101 | } | ||
| 102 | |||
| 94 | private: | 103 | private: |
| 95 | /// Configures the color and depth framebuffer states. | 104 | /// Configures the color and depth framebuffer states. |
| 96 | void ConfigureFramebuffers(); | 105 | void ConfigureFramebuffers(); |
| @@ -242,6 +251,7 @@ private: | |||
| 242 | ScreenInfo& screen_info; | 251 | ScreenInfo& screen_info; |
| 243 | ProgramManager& program_manager; | 252 | ProgramManager& program_manager; |
| 244 | StateTracker& state_tracker; | 253 | StateTracker& state_tracker; |
| 254 | VideoCommon::Shader::AsyncShaders async_shaders; | ||
| 245 | 255 | ||
| 246 | static constexpr std::size_t STREAM_BUFFER_SIZE = 128 * 1024 * 1024; | 256 | static constexpr std::size_t STREAM_BUFFER_SIZE = 128 * 1024 * 1024; |
| 247 | 257 | ||
diff --git a/src/video_core/renderer_opengl/gl_resource_manager.h b/src/video_core/renderer_opengl/gl_resource_manager.h index f8b322227..b05cb641c 100644 --- a/src/video_core/renderer_opengl/gl_resource_manager.h +++ b/src/video_core/renderer_opengl/gl_resource_manager.h | |||
| @@ -177,6 +177,12 @@ public: | |||
| 177 | Release(); | 177 | Release(); |
| 178 | } | 178 | } |
| 179 | 179 | ||
| 180 | OGLAssemblyProgram& operator=(OGLAssemblyProgram&& o) noexcept { | ||
| 181 | Release(); | ||
| 182 | handle = std::exchange(o.handle, 0); | ||
| 183 | return *this; | ||
| 184 | } | ||
| 185 | |||
| 180 | /// Deletes the internal OpenGL resource | 186 | /// Deletes the internal OpenGL resource |
| 181 | void Release(); | 187 | void Release(); |
| 182 | 188 | ||
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp index c6a3bf3a1..f469ed656 100644 --- a/src/video_core/renderer_opengl/gl_shader_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp | |||
| @@ -31,6 +31,7 @@ | |||
| 31 | #include "video_core/shader/registry.h" | 31 | #include "video_core/shader/registry.h" |
| 32 | #include "video_core/shader/shader_ir.h" | 32 | #include "video_core/shader/shader_ir.h" |
| 33 | #include "video_core/shader_cache.h" | 33 | #include "video_core/shader_cache.h" |
| 34 | #include "video_core/shader_notify.h" | ||
| 34 | 35 | ||
| 35 | namespace OpenGL { | 36 | namespace OpenGL { |
| 36 | 37 | ||
| @@ -140,9 +141,24 @@ std::shared_ptr<Registry> MakeRegistry(const ShaderDiskCacheEntry& entry) { | |||
| 140 | return registry; | 141 | return registry; |
| 141 | } | 142 | } |
| 142 | 143 | ||
| 144 | std::unordered_set<GLenum> GetSupportedFormats() { | ||
| 145 | GLint num_formats; | ||
| 146 | glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &num_formats); | ||
| 147 | |||
| 148 | std::vector<GLint> formats(num_formats); | ||
| 149 | glGetIntegerv(GL_PROGRAM_BINARY_FORMATS, formats.data()); | ||
| 150 | |||
| 151 | std::unordered_set<GLenum> supported_formats; | ||
| 152 | for (const GLint format : formats) { | ||
| 153 | supported_formats.insert(static_cast<GLenum>(format)); | ||
| 154 | } | ||
| 155 | return supported_formats; | ||
| 156 | } | ||
| 157 | |||
| 158 | } // Anonymous namespace | ||
| 159 | |||
| 143 | ProgramSharedPtr BuildShader(const Device& device, ShaderType shader_type, u64 unique_identifier, | 160 | ProgramSharedPtr BuildShader(const Device& device, ShaderType shader_type, u64 unique_identifier, |
| 144 | const ShaderIR& ir, const Registry& registry, | 161 | const ShaderIR& ir, const Registry& registry, bool hint_retrievable) { |
| 145 | bool hint_retrievable = false) { | ||
| 146 | const std::string shader_id = MakeShaderID(unique_identifier, shader_type); | 162 | const std::string shader_id = MakeShaderID(unique_identifier, shader_type); |
| 147 | LOG_INFO(Render_OpenGL, "{}", shader_id); | 163 | LOG_INFO(Render_OpenGL, "{}", shader_id); |
| 148 | 164 | ||
| @@ -181,30 +197,17 @@ ProgramSharedPtr BuildShader(const Device& device, ShaderType shader_type, u64 u | |||
| 181 | return program; | 197 | return program; |
| 182 | } | 198 | } |
| 183 | 199 | ||
| 184 | std::unordered_set<GLenum> GetSupportedFormats() { | ||
| 185 | GLint num_formats; | ||
| 186 | glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &num_formats); | ||
| 187 | |||
| 188 | std::vector<GLint> formats(num_formats); | ||
| 189 | glGetIntegerv(GL_PROGRAM_BINARY_FORMATS, formats.data()); | ||
| 190 | |||
| 191 | std::unordered_set<GLenum> supported_formats; | ||
| 192 | for (const GLint format : formats) { | ||
| 193 | supported_formats.insert(static_cast<GLenum>(format)); | ||
| 194 | } | ||
| 195 | return supported_formats; | ||
| 196 | } | ||
| 197 | |||
| 198 | } // Anonymous namespace | ||
| 199 | |||
| 200 | Shader::Shader(std::shared_ptr<VideoCommon::Shader::Registry> registry_, ShaderEntries entries_, | 200 | Shader::Shader(std::shared_ptr<VideoCommon::Shader::Registry> registry_, ShaderEntries entries_, |
| 201 | ProgramSharedPtr program_) | 201 | ProgramSharedPtr program_, bool is_built) |
| 202 | : registry{std::move(registry_)}, entries{std::move(entries_)}, program{std::move(program_)} { | 202 | : registry{std::move(registry_)}, entries{std::move(entries_)}, program{std::move(program_)}, |
| 203 | is_built(is_built) { | ||
| 203 | handle = program->assembly_program.handle; | 204 | handle = program->assembly_program.handle; |
| 204 | if (handle == 0) { | 205 | if (handle == 0) { |
| 205 | handle = program->source_program.handle; | 206 | handle = program->source_program.handle; |
| 206 | } | 207 | } |
| 207 | ASSERT(handle != 0); | 208 | if (is_built) { |
| 209 | ASSERT(handle != 0); | ||
| 210 | } | ||
| 208 | } | 211 | } |
| 209 | 212 | ||
| 210 | Shader::~Shader() = default; | 213 | Shader::~Shader() = default; |
| @@ -214,42 +217,82 @@ GLuint Shader::GetHandle() const { | |||
| 214 | return handle; | 217 | return handle; |
| 215 | } | 218 | } |
| 216 | 219 | ||
| 217 | std::unique_ptr<Shader> Shader::CreateStageFromMemory(const ShaderParameters& params, | 220 | bool Shader::IsBuilt() const { |
| 218 | Maxwell::ShaderProgram program_type, | 221 | return is_built; |
| 219 | ProgramCode code, ProgramCode code_b) { | 222 | } |
| 223 | |||
| 224 | void Shader::AsyncOpenGLBuilt(OGLProgram new_program) { | ||
| 225 | program->source_program = std::move(new_program); | ||
| 226 | handle = program->source_program.handle; | ||
| 227 | is_built = true; | ||
| 228 | } | ||
| 229 | |||
| 230 | void Shader::AsyncGLASMBuilt(OGLAssemblyProgram new_program) { | ||
| 231 | program->assembly_program = std::move(new_program); | ||
| 232 | handle = program->assembly_program.handle; | ||
| 233 | is_built = true; | ||
| 234 | } | ||
| 235 | |||
| 236 | std::unique_ptr<Shader> Shader::CreateStageFromMemory( | ||
| 237 | const ShaderParameters& params, Maxwell::ShaderProgram program_type, ProgramCode code, | ||
| 238 | ProgramCode code_b, VideoCommon::Shader::AsyncShaders& async_shaders, VAddr cpu_addr) { | ||
| 220 | const auto shader_type = GetShaderType(program_type); | 239 | const auto shader_type = GetShaderType(program_type); |
| 221 | const std::size_t size_in_bytes = code.size() * sizeof(u64); | 240 | const std::size_t size_in_bytes = code.size() * sizeof(u64); |
| 222 | 241 | ||
| 223 | auto registry = std::make_shared<Registry>(shader_type, params.system.GPU().Maxwell3D()); | 242 | auto& gpu = params.system.GPU(); |
| 224 | const ShaderIR ir(code, STAGE_MAIN_OFFSET, COMPILER_SETTINGS, *registry); | 243 | gpu.ShaderNotify().MarkSharderBuilding(); |
| 225 | // TODO(Rodrigo): Handle VertexA shaders | 244 | |
| 226 | // std::optional<ShaderIR> ir_b; | 245 | auto registry = std::make_shared<Registry>(shader_type, gpu.Maxwell3D()); |
| 227 | // if (!code_b.empty()) { | 246 | if (!async_shaders.IsShaderAsync(params.system.GPU()) || |
| 228 | // ir_b.emplace(code_b, STAGE_MAIN_OFFSET); | 247 | !params.device.UseAsynchronousShaders()) { |
| 229 | // } | 248 | const ShaderIR ir(code, STAGE_MAIN_OFFSET, COMPILER_SETTINGS, *registry); |
| 230 | auto program = BuildShader(params.device, shader_type, params.unique_identifier, ir, *registry); | 249 | // TODO(Rodrigo): Handle VertexA shaders |
| 250 | // std::optional<ShaderIR> ir_b; | ||
| 251 | // if (!code_b.empty()) { | ||
| 252 | // ir_b.emplace(code_b, STAGE_MAIN_OFFSET); | ||
| 253 | // } | ||
| 254 | auto program = | ||
| 255 | BuildShader(params.device, shader_type, params.unique_identifier, ir, *registry); | ||
| 256 | ShaderDiskCacheEntry entry; | ||
| 257 | entry.type = shader_type; | ||
| 258 | entry.code = std::move(code); | ||
| 259 | entry.code_b = std::move(code_b); | ||
| 260 | entry.unique_identifier = params.unique_identifier; | ||
| 261 | entry.bound_buffer = registry->GetBoundBuffer(); | ||
| 262 | entry.graphics_info = registry->GetGraphicsInfo(); | ||
| 263 | entry.keys = registry->GetKeys(); | ||
| 264 | entry.bound_samplers = registry->GetBoundSamplers(); | ||
| 265 | entry.bindless_samplers = registry->GetBindlessSamplers(); | ||
| 266 | params.disk_cache.SaveEntry(std::move(entry)); | ||
| 267 | |||
| 268 | gpu.ShaderNotify().MarkShaderComplete(); | ||
| 269 | |||
| 270 | return std::unique_ptr<Shader>(new Shader(std::move(registry), | ||
| 271 | MakeEntries(params.device, ir, shader_type), | ||
| 272 | std::move(program), true)); | ||
| 273 | } else { | ||
| 274 | // Required for entries | ||
| 275 | const ShaderIR ir(code, STAGE_MAIN_OFFSET, COMPILER_SETTINGS, *registry); | ||
| 276 | auto entries = MakeEntries(params.device, ir, shader_type); | ||
| 231 | 277 | ||
| 232 | ShaderDiskCacheEntry entry; | 278 | async_shaders.QueueOpenGLShader(params.device, shader_type, params.unique_identifier, |
| 233 | entry.type = shader_type; | 279 | std::move(code), std::move(code_b), STAGE_MAIN_OFFSET, |
| 234 | entry.code = std::move(code); | 280 | COMPILER_SETTINGS, *registry, cpu_addr); |
| 235 | entry.code_b = std::move(code_b); | ||
| 236 | entry.unique_identifier = params.unique_identifier; | ||
| 237 | entry.bound_buffer = registry->GetBoundBuffer(); | ||
| 238 | entry.graphics_info = registry->GetGraphicsInfo(); | ||
| 239 | entry.keys = registry->GetKeys(); | ||
| 240 | entry.bound_samplers = registry->GetBoundSamplers(); | ||
| 241 | entry.bindless_samplers = registry->GetBindlessSamplers(); | ||
| 242 | params.disk_cache.SaveEntry(std::move(entry)); | ||
| 243 | 281 | ||
| 244 | return std::unique_ptr<Shader>(new Shader( | 282 | auto program = std::make_shared<ProgramHandle>(); |
| 245 | std::move(registry), MakeEntries(params.device, ir, shader_type), std::move(program))); | 283 | return std::unique_ptr<Shader>( |
| 284 | new Shader(std::move(registry), std::move(entries), std::move(program), false)); | ||
| 285 | } | ||
| 246 | } | 286 | } |
| 247 | 287 | ||
| 248 | std::unique_ptr<Shader> Shader::CreateKernelFromMemory(const ShaderParameters& params, | 288 | std::unique_ptr<Shader> Shader::CreateKernelFromMemory(const ShaderParameters& params, |
| 249 | ProgramCode code) { | 289 | ProgramCode code) { |
| 250 | const std::size_t size_in_bytes = code.size() * sizeof(u64); | 290 | const std::size_t size_in_bytes = code.size() * sizeof(u64); |
| 251 | 291 | ||
| 252 | auto& engine = params.system.GPU().KeplerCompute(); | 292 | auto& gpu = params.system.GPU(); |
| 293 | gpu.ShaderNotify().MarkSharderBuilding(); | ||
| 294 | |||
| 295 | auto& engine = gpu.KeplerCompute(); | ||
| 253 | auto registry = std::make_shared<Registry>(ShaderType::Compute, engine); | 296 | auto registry = std::make_shared<Registry>(ShaderType::Compute, engine); |
| 254 | const ShaderIR ir(code, KERNEL_MAIN_OFFSET, COMPILER_SETTINGS, *registry); | 297 | const ShaderIR ir(code, KERNEL_MAIN_OFFSET, COMPILER_SETTINGS, *registry); |
| 255 | const u64 uid = params.unique_identifier; | 298 | const u64 uid = params.unique_identifier; |
| @@ -266,6 +309,8 @@ std::unique_ptr<Shader> Shader::CreateKernelFromMemory(const ShaderParameters& p | |||
| 266 | entry.bindless_samplers = registry->GetBindlessSamplers(); | 309 | entry.bindless_samplers = registry->GetBindlessSamplers(); |
| 267 | params.disk_cache.SaveEntry(std::move(entry)); | 310 | params.disk_cache.SaveEntry(std::move(entry)); |
| 268 | 311 | ||
| 312 | gpu.ShaderNotify().MarkShaderComplete(); | ||
| 313 | |||
| 269 | return std::unique_ptr<Shader>(new Shader(std::move(registry), | 314 | return std::unique_ptr<Shader>(new Shader(std::move(registry), |
| 270 | MakeEntries(params.device, ir, ShaderType::Compute), | 315 | MakeEntries(params.device, ir, ShaderType::Compute), |
| 271 | std::move(program))); | 316 | std::move(program))); |
| @@ -436,14 +481,51 @@ ProgramSharedPtr ShaderCacheOpenGL::GeneratePrecompiledProgram( | |||
| 436 | return program; | 481 | return program; |
| 437 | } | 482 | } |
| 438 | 483 | ||
| 439 | Shader* ShaderCacheOpenGL::GetStageProgram(Maxwell::ShaderProgram program) { | 484 | Shader* ShaderCacheOpenGL::GetStageProgram(Maxwell::ShaderProgram program, |
| 485 | VideoCommon::Shader::AsyncShaders& async_shaders) { | ||
| 440 | if (!system.GPU().Maxwell3D().dirty.flags[Dirty::Shaders]) { | 486 | if (!system.GPU().Maxwell3D().dirty.flags[Dirty::Shaders]) { |
| 441 | return last_shaders[static_cast<std::size_t>(program)]; | 487 | auto* last_shader = last_shaders[static_cast<std::size_t>(program)]; |
| 488 | if (last_shader->IsBuilt()) { | ||
| 489 | return last_shader; | ||
| 490 | } | ||
| 442 | } | 491 | } |
| 443 | 492 | ||
| 444 | auto& memory_manager{system.GPU().MemoryManager()}; | 493 | auto& memory_manager{system.GPU().MemoryManager()}; |
| 445 | const GPUVAddr address{GetShaderAddress(system, program)}; | 494 | const GPUVAddr address{GetShaderAddress(system, program)}; |
| 446 | 495 | ||
| 496 | if (device.UseAsynchronousShaders() && async_shaders.HasCompletedWork()) { | ||
| 497 | auto completed_work = async_shaders.GetCompletedWork(); | ||
| 498 | for (auto& work : completed_work) { | ||
| 499 | Shader* shader = TryGet(work.cpu_address); | ||
| 500 | auto& gpu = system.GPU(); | ||
| 501 | gpu.ShaderNotify().MarkShaderComplete(); | ||
| 502 | if (shader == nullptr) { | ||
| 503 | continue; | ||
| 504 | } | ||
| 505 | using namespace VideoCommon::Shader; | ||
| 506 | if (work.backend == AsyncShaders::Backend::OpenGL) { | ||
| 507 | shader->AsyncOpenGLBuilt(std::move(work.program.opengl)); | ||
| 508 | } else if (work.backend == AsyncShaders::Backend::GLASM) { | ||
| 509 | shader->AsyncGLASMBuilt(std::move(work.program.glasm)); | ||
| 510 | } | ||
| 511 | |||
| 512 | ShaderDiskCacheEntry entry; | ||
| 513 | entry.type = work.shader_type; | ||
| 514 | entry.code = std::move(work.code); | ||
| 515 | entry.code_b = std::move(work.code_b); | ||
| 516 | entry.unique_identifier = work.uid; | ||
| 517 | |||
| 518 | auto& registry = shader->GetRegistry(); | ||
| 519 | |||
| 520 | entry.bound_buffer = registry.GetBoundBuffer(); | ||
| 521 | entry.graphics_info = registry.GetGraphicsInfo(); | ||
| 522 | entry.keys = registry.GetKeys(); | ||
| 523 | entry.bound_samplers = registry.GetBoundSamplers(); | ||
| 524 | entry.bindless_samplers = registry.GetBindlessSamplers(); | ||
| 525 | disk_cache.SaveEntry(std::move(entry)); | ||
| 526 | } | ||
| 527 | } | ||
| 528 | |||
| 447 | // Look up shader in the cache based on address | 529 | // Look up shader in the cache based on address |
| 448 | const auto cpu_addr{memory_manager.GpuToCpuAddress(address)}; | 530 | const auto cpu_addr{memory_manager.GpuToCpuAddress(address)}; |
| 449 | if (Shader* const shader{cpu_addr ? TryGet(*cpu_addr) : null_shader.get()}) { | 531 | if (Shader* const shader{cpu_addr ? TryGet(*cpu_addr) : null_shader.get()}) { |
| @@ -471,7 +553,8 @@ Shader* ShaderCacheOpenGL::GetStageProgram(Maxwell::ShaderProgram program) { | |||
| 471 | std::unique_ptr<Shader> shader; | 553 | std::unique_ptr<Shader> shader; |
| 472 | const auto found = runtime_cache.find(unique_identifier); | 554 | const auto found = runtime_cache.find(unique_identifier); |
| 473 | if (found == runtime_cache.end()) { | 555 | if (found == runtime_cache.end()) { |
| 474 | shader = Shader::CreateStageFromMemory(params, program, std::move(code), std::move(code_b)); | 556 | shader = Shader::CreateStageFromMemory(params, program, std::move(code), std::move(code_b), |
| 557 | async_shaders, cpu_addr.value_or(0)); | ||
| 475 | } else { | 558 | } else { |
| 476 | shader = Shader::CreateFromCache(params, found->second); | 559 | shader = Shader::CreateFromCache(params, found->second); |
| 477 | } | 560 | } |
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.h b/src/video_core/renderer_opengl/gl_shader_cache.h index 994aaeaf2..7528ac686 100644 --- a/src/video_core/renderer_opengl/gl_shader_cache.h +++ b/src/video_core/renderer_opengl/gl_shader_cache.h | |||
| @@ -33,6 +33,10 @@ namespace Core::Frontend { | |||
| 33 | class EmuWindow; | 33 | class EmuWindow; |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | namespace VideoCommon::Shader { | ||
| 37 | class AsyncShaders; | ||
| 38 | } | ||
| 39 | |||
| 36 | namespace OpenGL { | 40 | namespace OpenGL { |
| 37 | 41 | ||
| 38 | class Device; | 42 | class Device; |
| @@ -61,6 +65,11 @@ struct ShaderParameters { | |||
| 61 | u64 unique_identifier; | 65 | u64 unique_identifier; |
| 62 | }; | 66 | }; |
| 63 | 67 | ||
| 68 | ProgramSharedPtr BuildShader(const Device& device, Tegra::Engines::ShaderType shader_type, | ||
| 69 | u64 unique_identifier, const VideoCommon::Shader::ShaderIR& ir, | ||
| 70 | const VideoCommon::Shader::Registry& registry, | ||
| 71 | bool hint_retrievable = false); | ||
| 72 | |||
| 64 | class Shader final { | 73 | class Shader final { |
| 65 | public: | 74 | public: |
| 66 | ~Shader(); | 75 | ~Shader(); |
| @@ -68,15 +77,28 @@ public: | |||
| 68 | /// Gets the GL program handle for the shader | 77 | /// Gets the GL program handle for the shader |
| 69 | GLuint GetHandle() const; | 78 | GLuint GetHandle() const; |
| 70 | 79 | ||
| 80 | bool IsBuilt() const; | ||
| 81 | |||
| 71 | /// Gets the shader entries for the shader | 82 | /// Gets the shader entries for the shader |
| 72 | const ShaderEntries& GetEntries() const { | 83 | const ShaderEntries& GetEntries() const { |
| 73 | return entries; | 84 | return entries; |
| 74 | } | 85 | } |
| 75 | 86 | ||
| 76 | static std::unique_ptr<Shader> CreateStageFromMemory(const ShaderParameters& params, | 87 | const VideoCommon::Shader::Registry& GetRegistry() const { |
| 77 | Maxwell::ShaderProgram program_type, | 88 | return *registry; |
| 78 | ProgramCode program_code, | 89 | } |
| 79 | ProgramCode program_code_b); | 90 | |
| 91 | /// Mark a OpenGL shader as built | ||
| 92 | void AsyncOpenGLBuilt(OGLProgram new_program); | ||
| 93 | |||
| 94 | /// Mark a GLASM shader as built | ||
| 95 | void AsyncGLASMBuilt(OGLAssemblyProgram new_program); | ||
| 96 | |||
| 97 | static std::unique_ptr<Shader> CreateStageFromMemory( | ||
| 98 | const ShaderParameters& params, Maxwell::ShaderProgram program_type, | ||
| 99 | ProgramCode program_code, ProgramCode program_code_b, | ||
| 100 | VideoCommon::Shader::AsyncShaders& async_shaders, VAddr cpu_addr); | ||
| 101 | |||
| 80 | static std::unique_ptr<Shader> CreateKernelFromMemory(const ShaderParameters& params, | 102 | static std::unique_ptr<Shader> CreateKernelFromMemory(const ShaderParameters& params, |
| 81 | ProgramCode code); | 103 | ProgramCode code); |
| 82 | 104 | ||
| @@ -85,12 +107,13 @@ public: | |||
| 85 | 107 | ||
| 86 | private: | 108 | private: |
| 87 | explicit Shader(std::shared_ptr<VideoCommon::Shader::Registry> registry, ShaderEntries entries, | 109 | explicit Shader(std::shared_ptr<VideoCommon::Shader::Registry> registry, ShaderEntries entries, |
| 88 | ProgramSharedPtr program); | 110 | ProgramSharedPtr program, bool is_built = true); |
| 89 | 111 | ||
| 90 | std::shared_ptr<VideoCommon::Shader::Registry> registry; | 112 | std::shared_ptr<VideoCommon::Shader::Registry> registry; |
| 91 | ShaderEntries entries; | 113 | ShaderEntries entries; |
| 92 | ProgramSharedPtr program; | 114 | ProgramSharedPtr program; |
| 93 | GLuint handle = 0; | 115 | GLuint handle = 0; |
| 116 | bool is_built{}; | ||
| 94 | }; | 117 | }; |
| 95 | 118 | ||
| 96 | class ShaderCacheOpenGL final : public VideoCommon::ShaderCache<Shader> { | 119 | class ShaderCacheOpenGL final : public VideoCommon::ShaderCache<Shader> { |
| @@ -104,7 +127,8 @@ public: | |||
| 104 | const VideoCore::DiskResourceLoadCallback& callback); | 127 | const VideoCore::DiskResourceLoadCallback& callback); |
| 105 | 128 | ||
| 106 | /// Gets the current specified shader stage program | 129 | /// Gets the current specified shader stage program |
| 107 | Shader* GetStageProgram(Maxwell::ShaderProgram program); | 130 | Shader* GetStageProgram(Maxwell::ShaderProgram program, |
| 131 | VideoCommon::Shader::AsyncShaders& async_shaders); | ||
| 108 | 132 | ||
| 109 | /// Gets a compute kernel in the passed address | 133 | /// Gets a compute kernel in the passed address |
| 110 | Shader* GetComputeKernel(GPUVAddr code_addr); | 134 | Shader* GetComputeKernel(GPUVAddr code_addr); |