Repository navigation
Expand file tree
/
Copy pathpresent_sdr_restore_policy.hpp
More file actions
67 lines (55 loc) · 2.08 KB
/
Copy pathpresent_sdr_restore_policy.hpp
File metadata and controls
67 lines (55 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* Copyright (C) 2026
* SPDX-License-Identifier: MIT
*/
#pragma once
#include <cstdint>
namespace renodx::addons::dlss5::present_sdr_restore {
enum class Policy : uint32_t {
LEGACY = 0,
OFF = 1,
LEGACY_AUTO = 2,
LEGACY_EVERY_BLOCK = 3,
LEGACY_SMOOTH = 4,
};
inline constexpr uint32_t CONFIG_VERSION = 1;
inline constexpr Policy DEFAULT_POLICY = Policy::OFF;
inline constexpr Policy FALLBACK_POLICY = Policy::LEGACY;
// This is the unchanged legacy shader cap in encoded SDR units, not linear light.
inline constexpr float ENCODED_CAP = 0.025f;
struct Configuration {
Policy policy = DEFAULT_POLICY;
uint32_t version = CONFIG_VERSION;
bool writable = true;
};
inline constexpr Policy SanitizePolicy(uint32_t value) {
return (value <= static_cast<uint32_t>(Policy::LEGACY_SMOOTH)
? static_cast<Policy>(value) : FALLBACK_POLICY);
}
inline constexpr Configuration LoadPolicy(uint32_t value, uint32_t version,
bool policy_present = true, bool legacy_explicit = false) {
// A newer schema owns both keys; do not reinterpret or overwrite it.
if (version > CONFIG_VERSION) {
return {.policy = FALLBACK_POLICY, .version = version, .writable = false};
}
if (!policy_present) {
return {.policy = (legacy_explicit ? Policy::LEGACY : DEFAULT_POLICY),
.version = CONFIG_VERSION, .writable = true};
}
return {.policy = SanitizePolicy(value), .version = CONFIG_VERSION, .writable = true};
}
inline constexpr uint32_t EffectiveLegacyMode(Policy policy, uint32_t legacy_mode) {
switch (policy) {
case Policy::LEGACY_AUTO: return 0;
case Policy::LEGACY_EVERY_BLOCK: return 1;
case Policy::LEGACY_SMOOTH: return 2;
default: return (legacy_mode <= 2u ? legacy_mode : 0u);
}
}
inline constexpr bool ShouldRestore(Policy policy, uint8_t hdr_mode, bool diagnostic_bypass) {
return hdr_mode == 0 && policy != Policy::OFF && !diagnostic_bypass;
}
inline constexpr float EncodedGate(uint32_t legacy_mode) {
return (legacy_mode == 1u ? 2.f : 0.061f);
}
} // namespace renodx::addons::dlss5::present_sdr_restore