VERY experimental Nintendo Switch 2 emulator
C++
Merge pull request #2601 from FernandoS27/texture_cache
Zach Hilman3f7c8053c676
diff --cc src/video_core/renderer_opengl/gl_shader_cache.cppindex 8d3d7bfdc0,1bd182d980..f9b2b03a0a--- a/src/video_core/renderer_opengl/gl_shader_cache.cpp+++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp@@@ -221,53 -244,58 +244,51 @@@ std::set<GLenum> GetSupportedFormats()} // Anonymous namespace-CachedShader::CachedShader(const Device& device, VAddr cpu_addr, u64 unique_identifier,- Maxwell::ShaderProgram program_type, ShaderDiskCacheOpenGL& disk_cache,- const PrecompiledPrograms& precompiled_programs,- ProgramCode&& program_code, ProgramCode&& program_code_b, u8* host_ptr)- : RasterizerCacheObject{host_ptr}, host_ptr{host_ptr}, cpu_addr{cpu_addr},- unique_identifier{unique_identifier}, program_type{program_type}, disk_cache{disk_cache},- precompiled_programs{precompiled_programs} {- const std::size_t code_size{CalculateProgramSize(program_code)};- const std::size_t code_size_b{program_code_b.empty() ? 0- : CalculateProgramSize(program_code_b)};- GLShader::ProgramResult program_result{- CreateProgram(device, program_type, program_code, program_code_b)};- if (program_result.first.empty()) {+CachedShader::CachedShader(const ShaderParameters& params, Maxwell::ShaderProgram program_type,+ GLShader::ProgramResult result)+ : RasterizerCacheObject{params.host_ptr}, host_ptr{params.host_ptr}, cpu_addr{params.cpu_addr},+ unique_identifier{params.unique_identifier}, program_type{program_type},+ disk_cache{params.disk_cache}, precompiled_programs{params.precompiled_programs},+ entries{result.second}, code{std::move(result.first)}, shader_length{entries.shader_length} {}++Shader CachedShader::CreateStageFromMemory(const ShaderParameters& params,+ Maxwell::ShaderProgram program_type,+ ProgramCode&& program_code,+ ProgramCode&& program_code_b) {+ const auto code_size{CalculateProgramSize(program_code)};+ const auto code_size_b{CalculateProgramSize(program_code_b)};+ auto result{CreateProgram(params.device, program_type, program_code, program_code_b)};+ if (result.first.empty()) {// TODO(Rodrigo): Unimplemented shader stages hit here, avoid using these for now- return;+ return {};}- code = program_result.first;- entries = program_result.second;- shader_length = entries.shader_length;+ params.disk_cache.SaveRaw(ShaderDiskCacheRaw(+ params.unique_identifier, program_type, static_cast<u32>(code_size / sizeof(u64)),+ static_cast<u32>(code_size_b / sizeof(u64)), std::move(program_code),+ std::move(program_code_b)));- const ShaderDiskCacheRaw raw(unique_identifier, program_type,- static_cast<u32>(code_size / sizeof(u64)),- static_cast<u32>(code_size_b / sizeof(u64)),- std::move(program_code), std::move(program_code_b));- disk_cache.SaveRaw(raw);+ return std::shared_ptr<CachedShader>(new CachedShader(params, program_type, std::move(result)));}-CachedShader::CachedShader(VAddr cpu_addr, u64 unique_identifier,- Maxwell::ShaderProgram program_type, ShaderDiskCacheOpenGL& disk_cache,- const PrecompiledPrograms& precompiled_programs,- GLShader::ProgramResult result, u8* host_ptr)- : RasterizerCacheObject{host_ptr}, cpu_addr{cpu_addr}, unique_identifier{unique_identifier},- program_type{program_type}, disk_cache{disk_cache}, precompiled_programs{- precompiled_programs} {- code = std::move(result.first);- entries = result.second;- shader_length = entries.shader_length;+Shader CachedShader::CreateStageFromCache(const ShaderParameters& params,+ Maxwell::ShaderProgram program_type,+ GLShader::ProgramResult result) {+ return std::shared_ptr<CachedShader>(new CachedShader(params, program_type, std::move(result)));}- std::tuple<GLuint, BaseBindings> CachedShader::GetProgramHandle(GLenum primitive_mode,- BaseBindings base_bindings) {+ std::tuple<GLuint, BaseBindings> CachedShader::GetProgramHandle(const ProgramVariant& variant) {GLuint handle{};if (program_type == Maxwell::ShaderProgram::Geometry) {- handle = GetGeometryShader(primitive_mode, base_bindings);+ handle = GetGeometryShader(variant);} else {- const auto [entry, is_cache_miss] = programs.try_emplace(base_bindings);+ const auto [entry, is_cache_miss] = programs.try_emplace(variant);auto& program = entry->second;if (is_cache_miss) {- program = TryLoadProgram(primitive_mode, base_bindings);+ program = TryLoadProgram(variant);if (!program) {- program =- SpecializeShader(code, entries, program_type, base_bindings, primitive_mode);- disk_cache.SaveUsage(GetUsage(primitive_mode, base_bindings));+ program = SpecializeShader(code, entries, program_type, variant);+ disk_cache.SaveUsage(GetUsage(variant));}LabelGLObject(GL_PROGRAM, program->handle, cpu_addr);diff --cc src/video_core/renderer_opengl/gl_shader_cache.hindex 01af9b28a2,59bcb14e82..bbb53cdf4e--- a/src/video_core/renderer_opengl/gl_shader_cache.h+++ b/src/video_core/renderer_opengl/gl_shader_cache.h@@@ -74,13 -68,9 +75,12 @@@ public}/// Gets the GL program handle for the shader- std::tuple<GLuint, BaseBindings> GetProgramHandle(GLenum primitive_mode,- BaseBindings base_bindings);+ std::tuple<GLuint, BaseBindings> GetProgramHandle(const ProgramVariant& variant);private:+ explicit CachedShader(const ShaderParameters& params, Maxwell::ShaderProgram program_type,+ GLShader::ProgramResult result);+// 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.@@@ -109,12 -98,13 +108,12 @@@ShaderDiskCacheOpenGL& disk_cache;const PrecompiledPrograms& precompiled_programs;- std::size_t shader_length{};GLShader::ShaderEntries entries;-std::string code;+ std::size_t shader_length{};- std::unordered_map<BaseBindings, CachedProgram> programs;- std::unordered_map<BaseBindings, GeometryPrograms> geometry_programs;+ std::unordered_map<ProgramVariant, CachedProgram> programs;+ std::unordered_map<ProgramVariant, GeometryPrograms> geometry_programs;std::unordered_map<u32, GLuint> cbuf_resource_cache;std::unordered_map<u32, GLuint> gmem_resource_cache;