clang-format

x

y
This commit is contained in:
SachinVin 2021-04-06 12:49:01 +05:30 committed by bunnei
parent 7a044d9586
commit f8dbaa2044
7 changed files with 139 additions and 128 deletions

View File

@ -145,10 +145,10 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) {
env->NewGlobalRef(env->FindClass("org/citra/citra_emu/NativeLibrary$SavestateInfo"))); env->NewGlobalRef(env->FindClass("org/citra/citra_emu/NativeLibrary$SavestateInfo")));
s_core_error_class = reinterpret_cast<jclass>( s_core_error_class = reinterpret_cast<jclass>(
env->NewGlobalRef(env->FindClass("org/citra/citra_emu/NativeLibrary$CoreError"))); env->NewGlobalRef(env->FindClass("org/citra/citra_emu/NativeLibrary$CoreError")));
s_disk_cache_progress_class = reinterpret_cast<jclass>( s_disk_cache_progress_class = reinterpret_cast<jclass>(env->NewGlobalRef(
env->NewGlobalRef(env->FindClass("org/citra/citra_emu/disk_shader_cache/DiskShaderCacheProgress"))); env->FindClass("org/citra/citra_emu/disk_shader_cache/DiskShaderCacheProgress")));
s_load_callback_stage_class = reinterpret_cast<jclass>( s_load_callback_stage_class = reinterpret_cast<jclass>(env->NewGlobalRef(env->FindClass(
env->NewGlobalRef(env->FindClass("org/citra/citra_emu/disk_shader_cache/DiskShaderCacheProgress$LoadCallbackStage"))); "org/citra/citra_emu/disk_shader_cache/DiskShaderCacheProgress$LoadCallbackStage")));
s_on_core_error = env->GetStaticMethodID( s_on_core_error = env->GetStaticMethodID(
s_native_library_class, "OnCoreError", s_native_library_class, "OnCoreError",
@ -169,8 +169,9 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) {
env->GetStaticMethodID(s_native_library_class, "RequestCameraPermission", "()Z"); env->GetStaticMethodID(s_native_library_class, "RequestCameraPermission", "()Z");
s_request_mic_permission = s_request_mic_permission =
env->GetStaticMethodID(s_native_library_class, "RequestMicPermission", "()Z"); env->GetStaticMethodID(s_native_library_class, "RequestMicPermission", "()Z");
s_disk_cache_load_progress = s_disk_cache_load_progress = env->GetStaticMethodID(
env->GetStaticMethodID(s_disk_cache_progress_class, "loadProgress", "(Lorg/citra/citra_emu/disk_shader_cache/DiskShaderCacheProgress$LoadCallbackStage;II)V"); s_disk_cache_progress_class, "loadProgress",
"(Lorg/citra/citra_emu/disk_shader_cache/DiskShaderCacheProgress$LoadCallbackStage;II)V");
MiiSelector::InitJNI(env); MiiSelector::InitJNI(env);
SoftwareKeyboard::InitJNI(env); SoftwareKeyboard::InitJNI(env);

View File

@ -133,13 +133,17 @@ static jobject ToJavaLoadCallbackStage(VideoCore::LoadCallbackStage stage) {
const jclass load_callback_stage_class = IDCache::GetDiskCacheLoadCallbackStageClass(); const jclass load_callback_stage_class = IDCache::GetDiskCacheLoadCallbackStageClass();
return env->GetStaticObjectField( return env->GetStaticObjectField(
load_callback_stage_class, env->GetStaticFieldID(load_callback_stage_class, name, load_callback_stage_class,
env->GetStaticFieldID(
load_callback_stage_class, name,
"Lorg/citra/citra_emu/disk_shader_cache/DiskShaderCacheProgress$LoadCallbackStage;")); "Lorg/citra/citra_emu/disk_shader_cache/DiskShaderCacheProgress$LoadCallbackStage;"));
} }
static void LoadDiskCacheProgress(VideoCore::LoadCallbackStage stage, int progress, int max) { static void LoadDiskCacheProgress(VideoCore::LoadCallbackStage stage, int progress, int max) {
JNIEnv* env = IDCache::GetEnvForThread(); JNIEnv* env = IDCache::GetEnvForThread();
env->CallStaticVoidMethod(IDCache::GetDiskCacheProgressClass(), IDCache::GetDiskCacheLoadProgress(), ToJavaLoadCallbackStage(stage), (jint) progress, (jint) max); env->CallStaticVoidMethod(IDCache::GetDiskCacheProgressClass(),
IDCache::GetDiskCacheLoadProgress(), ToJavaLoadCallbackStage(stage),
(jint)progress, (jint)max);
} }
static Camera::NDK::Factory* g_ndk_factory{}; static Camera::NDK::Factory* g_ndk_factory{};
@ -220,9 +224,7 @@ static Core::System::ResultStatus RunCitra(const std::string& filepath) {
cpu_context->MakeCurrent(); cpu_context->MakeCurrent();
} }
system.Renderer().Rasterizer()->LoadDiskResources( system.Renderer().Rasterizer()->LoadDiskResources(!is_running, &LoadDiskCacheProgress);
!is_running, &LoadDiskCacheProgress
);
if (Settings::values.use_asynchronous_gpu_emulation) { if (Settings::values.use_asynchronous_gpu_emulation) {
cpu_context->DoneCurrent(); cpu_context->DoneCurrent();

View File

@ -171,16 +171,17 @@ RasterizerOpenGL::RasterizerOpenGL(Frontend::EmuWindow& emu_window)
#ifdef __APPLE__ #ifdef __APPLE__
if (IsVendorIntel()) { if (IsVendorIntel()) {
shader_program_manager = std::make_unique<ShaderProgramManager>(emu_window, shader_program_manager = std::make_unique<ShaderProgramManager>(
emu_window,
VideoCore::g_separable_shader_enabled ? GLAD_GL_ARB_separate_shader_objects : false, VideoCore::g_separable_shader_enabled ? GLAD_GL_ARB_separate_shader_objects : false,
is_amd); is_amd);
} else { } else {
shader_program_manager = shader_program_manager = std::make_unique<ShaderProgramManager>(
std::make_unique<ShaderProgramManager>(emu_window, GLAD_GL_ARB_separate_shader_objects, is_amd); emu_window, GLAD_GL_ARB_separate_shader_objects, is_amd);
} }
#else #else
shader_program_manager = shader_program_manager = std::make_unique<ShaderProgramManager>(
std::make_unique<ShaderProgramManager>(emu_window, GLAD_GL_ARB_separate_shader_objects, is_amd); emu_window, GLAD_GL_ARB_separate_shader_objects, is_amd);
#endif #endif
glEnable(GL_BLEND); glEnable(GL_BLEND);

View File

@ -106,8 +106,8 @@ ShaderDiskCache::ShaderDiskCache(bool separable) : separable{separable} {}
std::optional<std::vector<ShaderDiskCacheRaw>> ShaderDiskCache::LoadTransferable() { std::optional<std::vector<ShaderDiskCacheRaw>> ShaderDiskCache::LoadTransferable() {
const bool has_title_id = GetProgramID() != 0; const bool has_title_id = GetProgramID() != 0;
if (!Settings::values.use_hw_shader || if (!Settings::values.use_hw_shader || !Settings::values.use_disk_shader_cache ||
!Settings::values.use_disk_shader_cache || !has_title_id) { !has_title_id) {
return std::nullopt; return std::nullopt;
} }
tried_to_load = true; tried_to_load = true;
@ -200,7 +200,8 @@ ShaderDiskCache::LoadPrecompiledFile(FileUtil::IOFile& file, bool compressed) {
std::vector<u8> precompiled_file(file.GetSize()); std::vector<u8> precompiled_file(file.GetSize());
file.ReadBytes(precompiled_file.data(), precompiled_file.size()); file.ReadBytes(precompiled_file.data(), precompiled_file.size());
if (compressed) { if (compressed) {
const std::vector<u8> decompressed = Common::Compression::DecompressDataZSTD(precompiled_file); const std::vector<u8> decompressed =
Common::Compression::DecompressDataZSTD(precompiled_file);
SaveArrayToPrecompiled(decompressed.data(), decompressed.size()); SaveArrayToPrecompiled(decompressed.data(), decompressed.size());
} else { } else {
SaveArrayToPrecompiled(precompiled_file.data(), precompiled_file.size()); SaveArrayToPrecompiled(precompiled_file.data(), precompiled_file.size());
@ -305,8 +306,7 @@ void ShaderDiskCache::SaveDecompiledToFile(FileUtil::IOFile& file, u64 unique_id
return; return;
if (file.WriteObject(static_cast<u32>(PrecompiledEntryKind::Decompiled)) != 1 || if (file.WriteObject(static_cast<u32>(PrecompiledEntryKind::Decompiled)) != 1 ||
file.WriteObject(unique_identifier) != 1 || file.WriteObject(unique_identifier) != 1 || file.WriteObject(sanitize_mul) != 1 ||
file.WriteObject(sanitize_mul) != 1 ||
file.WriteObject(static_cast<u32>(result.code.size())) != 1 || file.WriteObject(static_cast<u32>(result.code.size())) != 1 ||
file.WriteArray(result.code.data(), result.code.size()) != result.code.size()) { file.WriteArray(result.code.data(), result.code.size()) != result.code.size()) {
LOG_ERROR(Render_OpenGL, "Failed to save decompiled cache entry - removing"); LOG_ERROR(Render_OpenGL, "Failed to save decompiled cache entry - removing");
@ -435,7 +435,7 @@ void ShaderDiskCache::SaveDumpToFile(u64 unique_identifier, GLuint program, bool
if (file.WriteObject(static_cast<u32>(PrecompiledEntryKind::Dump)) != 1 || if (file.WriteObject(static_cast<u32>(PrecompiledEntryKind::Dump)) != 1 ||
file.WriteObject(unique_identifier) != 1 || file.WriteObject(unique_identifier) != 1 ||
file.WriteObject(static_cast<u32>(binary_format)) != 1 || file.WriteObject(static_cast<u32>(binary_format)) != 1 ||
file.WriteObject(static_cast<u32>(binary_length)) != 1|| file.WriteObject(static_cast<u32>(binary_length)) != 1 ||
file.WriteArray(binary.data(), binary.size()) != binary.size()) { file.WriteArray(binary.data(), binary.size()) != binary.size()) {
LOG_ERROR(Render_OpenGL, "Failed to save binary program file in shader={:016x} - removing", LOG_ERROR(Render_OpenGL, "Failed to save binary program file in shader={:016x} - removing",
unique_identifier); unique_identifier);

View File

@ -131,8 +131,8 @@ private:
std::optional<ShaderDiskCacheDecompiled> LoadDecompiledEntry(); std::optional<ShaderDiskCacheDecompiled> LoadDecompiledEntry();
/// Saves a decompiled entry to the passed file. Does not check for collisions. /// Saves a decompiled entry to the passed file. Does not check for collisions.
void SaveDecompiledToFile(FileUtil::IOFile& file, u64 unique_identifier, const ShaderDecompiler::ProgramResult& code, void SaveDecompiledToFile(FileUtil::IOFile& file, u64 unique_identifier,
bool sanitize_mul); const ShaderDecompiler::ProgramResult& code, bool sanitize_mul);
/// Saves a decompiled entry to the virtual precompiled cache. Does not check for collisions. /// Saves a decompiled entry to the virtual precompiled cache. Does not check for collisions.
bool SaveDecompiledToCache(u64 unique_identifier, const ShaderDecompiler::ProgramResult& code, bool SaveDecompiledToCache(u64 unique_identifier, const ShaderDecompiler::ProgramResult& code,

View File

@ -27,7 +27,8 @@ static u64 GetUniqueIdentifier(const Pica::Regs& regs, const ProgramCode& code)
} }
static OGLProgram GeneratePrecompiledProgram(const ShaderDiskCacheDump& dump, static OGLProgram GeneratePrecompiledProgram(const ShaderDiskCacheDump& dump,
const std::set<GLenum>& supported_formats, bool separable) { const std::set<GLenum>& supported_formats,
bool separable) {
if (supported_formats.find(dump.binary_format) == supported_formats.end()) { if (supported_formats.find(dump.binary_format) == supported_formats.end()) {
LOG_INFO(Render_OpenGL, "Precompiled cache entry with unsupported format - removing"); LOG_INFO(Render_OpenGL, "Precompiled cache entry with unsupported format - removing");
@ -384,7 +385,8 @@ public:
ShaderDiskCache disk_cache; ShaderDiskCache disk_cache;
}; };
ShaderProgramManager::ShaderProgramManager(Frontend::EmuWindow& emu_window_, bool separable, bool is_amd) ShaderProgramManager::ShaderProgramManager(Frontend::EmuWindow& emu_window_, bool separable,
bool is_amd)
: impl(std::make_unique<Impl>(separable, is_amd)), emu_window{emu_window_} {} : impl(std::make_unique<Impl>(separable, is_amd)), emu_window{emu_window_} {}
ShaderProgramManager::~ShaderProgramManager() = default; ShaderProgramManager::~ShaderProgramManager() = default;
@ -469,9 +471,11 @@ void ShaderProgramManager::ApplyTo(OpenGLState& state) {
cached_program = std::move(disk_program); cached_program = std::move(disk_program);
impl->disk_program_cache.erase(unique_identifier); impl->disk_program_cache.erase(unique_identifier);
} else { } else {
cached_program.Create(false, {impl->current.vs, impl->current.gs, impl->current.fs}); cached_program.Create(false,
{impl->current.vs, impl->current.gs, impl->current.fs});
auto& disk_cache = impl->disk_cache; auto& disk_cache = impl->disk_cache;
disk_cache.SaveDumpToFile(unique_identifier, cached_program.handle, VideoCore::g_hw_shader_accurate_mul); disk_cache.SaveDumpToFile(unique_identifier, cached_program.handle,
VideoCore::g_hw_shader_accurate_mul);
} }
SetShaderUniformBlockBindings(cached_program.handle); SetShaderUniformBlockBindings(cached_program.handle);
SetShaderSamplerBindings(cached_program.handle); SetShaderSamplerBindings(cached_program.handle);
@ -510,9 +514,10 @@ void ShaderProgramManager::LoadDiskCache(const std::atomic_bool& stop_loading,
} }
std::vector<std::size_t> load_raws_index; std::vector<std::size_t> load_raws_index;
// Loads both decompiled and precompiled shaders from the cache. If either one is missing for // Loads both decompiled and precompiled shaders from the cache. If either one is missing for
const auto LoadPrecompiledWorker = const auto LoadPrecompiledWorker = [&](std::size_t begin, std::size_t end,
[&](std::size_t begin, std::size_t end, const std::vector<ShaderDiskCacheRaw>& raw_cache, const std::vector<ShaderDiskCacheRaw>& raw_cache,
const ShaderDecompiledMap& decompiled_map, const ShaderDumpsMap& dump_map) { const ShaderDecompiledMap& decompiled_map,
const ShaderDumpsMap& dump_map) {
for (std::size_t i = begin; i < end; ++i) { for (std::size_t i = begin; i < end; ++i) {
if (stop_loading || compilation_failed) { if (stop_loading || compilation_failed) {
return; return;
@ -544,7 +549,8 @@ void ShaderProgramManager::LoadDiskCache(const std::atomic_bool& stop_loading,
} }
// If the shader is dumped, attempt to load it // If the shader is dumped, attempt to load it
shader = GeneratePrecompiledProgram(dump->second, supported_formats, impl->separable); shader =
GeneratePrecompiledProgram(dump->second, supported_formats, impl->separable);
if (shader.handle == 0) { if (shader.handle == 0) {
// If any shader failed, stop trying to compile, delete the cache, and start // If any shader failed, stop trying to compile, delete the cache, and start
// loading from raws // loading from raws
@ -581,10 +587,10 @@ void ShaderProgramManager::LoadDiskCache(const std::atomic_bool& stop_loading,
} }
}; };
const auto LoadPrecompiledProgram = const auto LoadPrecompiledProgram = [&](const ShaderDecompiledMap& decompiled_map,
[&](const ShaderDecompiledMap& decompiled_map, const ShaderDumpsMap& dump_map) { const ShaderDumpsMap& dump_map) {
std::size_t i{0}; std::size_t i{0};
for (const auto &dump : dump_map) { for (const auto& dump : dump_map) {
if (stop_loading) { if (stop_loading) {
break; break;
} }
@ -633,7 +639,8 @@ void ShaderProgramManager::LoadDiskCache(const std::atomic_bool& stop_loading,
compilation_failed = false; compilation_failed = false;
std::size_t built_shaders = 0; // It doesn't have be atomic since it's used behind a mutex std::size_t built_shaders = 0; // It doesn't have be atomic since it's used behind a mutex
const auto LoadTransferable = [&](Frontend::GraphicsContext* context, std::size_t begin, std::size_t end) { const auto LoadTransferable = [&](Frontend::GraphicsContext* context, std::size_t begin,
std::size_t end) {
Frontend::ScopeAcquireContext scope(*context); Frontend::ScopeAcquireContext scope(*context);
for (std::size_t i = begin; i < end; ++i) { for (std::size_t i = begin; i < end; ++i) {
if (stop_loading || compilation_failed) { if (stop_loading || compilation_failed) {
@ -655,7 +662,7 @@ void ShaderProgramManager::LoadDiskCache(const std::atomic_bool& stop_loading,
handle = stage.GetHandle(); handle = stage.GetHandle();
sanitize_mul = conf.state.sanitize_mul; sanitize_mul = conf.state.sanitize_mul;
std::scoped_lock lock(mutex); std::scoped_lock lock(mutex);
impl->programmable_vertex_shaders.Inject(conf, result->code,std::move(stage)); impl->programmable_vertex_shaders.Inject(conf, result->code, std::move(stage));
} else if (raw.GetProgramType() == ProgramType::FS) { } else if (raw.GetProgramType() == ProgramType::FS) {
PicaFSConfig conf = PicaFSConfig::BuildFromRegs(raw.GetRawShaderConfig()); PicaFSConfig conf = PicaFSConfig::BuildFromRegs(raw.GetRawShaderConfig());
result = GenerateFragmentShader(conf, impl->separable); result = GenerateFragmentShader(conf, impl->separable);