some adjustments to the chain enable

This commit is contained in:
CamilleLaVey
2026-09-04 14:37:12 -04:00
parent aa8d2000f4
commit 93cd28e44f
5 changed files with 41 additions and 8 deletions
@@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#include <array>
#include <string>
#include <jni.h>
@@ -37,6 +38,22 @@ nlohmann::json SerializeUniform(const VideoCore::FxUniformDesc& uniform) {
return out;
}
std::array<f32, 4> DefaultValueOf(size_t index, const std::string& uniform) {
const auto entries = VideoCore::FxChain::Instance().Entries();
if (index >= entries.size()) {
return {};
}
const VideoCore::FxEffectDesc* effect = VideoCore::FindFxEffect(entries[index].file);
if (effect == nullptr) {
return {};
}
const VideoCore::FxUniformDesc* desc = VideoCore::FindFxUniform(*effect, uniform);
if (desc == nullptr) {
return {};
}
return desc->default_value;
}
#endif
} // Anonymous namespace
@@ -164,10 +181,15 @@ void Java_org_yuzu_yuzu_1emu_utils_NativePostProcessing_setValue(JNIEnv* env, jo
}
const std::string uniform = Common::Android::GetJString(env, juniform);
auto& chain = VideoCore::FxChain::Instance();
const auto slot = static_cast<size_t>(index);
auto current = chain.GetValue(slot, uniform);
if (!chain.HasValue(slot, uniform)) {
current = DefaultValueOf(slot, uniform);
}
auto current = chain.GetValue(static_cast<size_t>(index), uniform);
current[static_cast<size_t>(component)] = value;
chain.SetValue(static_cast<size_t>(index), uniform, current);
chain.SetValue(slot, uniform, current);
#endif
}
@@ -227,6 +227,14 @@ std::array<f32, 4> FxChain::GetValue(size_t index, std::string_view uniform) con
return it->second;
}
std::map<std::string, std::array<f32, 4>> FxChain::EntryValues(size_t index) const {
std::scoped_lock lock{mutex};
if (index >= entries.size()) {
return {};
}
return entries[index].values;
}
bool FxChain::HasValue(size_t index, std::string_view uniform) const {
std::scoped_lock lock{mutex};
if (index >= entries.size()) {
@@ -55,6 +55,8 @@ public:
std::array<f32, 4> GetValue(size_t index, std::string_view uniform) const;
std::map<std::string, std::array<f32, 4>> EntryValues(size_t index) const;
bool HasValue(size_t index, std::string_view uniform) const;
void ResetValues(size_t index);
@@ -52,7 +52,7 @@ FxCompileResult CompileFxEffect(const std::filesystem::path& path, u32 width, u3
}
std::unique_ptr<reshadefx::codegen> backend(
reshadefx::create_codegen_spirv(true, false, false, false, false));
reshadefx::create_codegen_spirv(true, false, false, false, true));
reshadefx::parser parser;
if (!parser.parse(preprocessor.output(), backend.get())) {
@@ -506,11 +506,6 @@ bool PostProcessChain::BuildEffects(const Device& device, MemoryAllocator& alloc
}
}
const auto override = entry.values.find(uniform.name);
if (override != entry.values.end()) {
write.fallback = override->second;
}
write.args = {0.0f, 1.0f, 1.0f, 0.0f};
for (const auto& annotation : uniform.annotations) {
if (annotation.name == "min" && annotation.type.is_floating_point()) {
@@ -697,10 +692,16 @@ void PostProcessChain::UpdateUniforms(Effect& effect, size_t image_index, f32 de
std::vector<u8> staging(effect.uniform_size, 0);
const f32 elapsed =
std::chrono::duration<f32>(std::chrono::steady_clock::now() - m_start).count();
const auto overrides = VideoCore::FxChain::Instance().EntryValues(effect.entry_index);
for (auto& uniform : effect.uniforms) {
std::array<f32, 4> value = uniform.fallback;
const auto override = overrides.find(uniform.name);
if (override != overrides.end()) {
value = override->second;
}
switch (uniform.source) {
case UniformSource::FrameTime:
value[0] = delta_seconds * 1000.0f;