Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 46 additions & 17 deletions clean/fsr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ if(WG_MODEL_K)
else()
add_compile_definitions(WRONGGPU_MODEL_K=0)
endif()
# Model L in the front end (#89; src/model_l.h): its entry "WrongGPU Model L" in the hosted version list, its id,
# sr_model=L / model=L passed to the runtime (which needs WG_MODEL_L too), the model lookup's <place>\L\model.wgcm, its
# names in the overlay and the provider label. OFF (the default while Model L is not released): none of that; model=L
# from wronggpu.ini or WG_RUNTIME_OPTIONS is refused with one log line and Model M runs. Set on wg_fsr_core (and so on
# everything that links it), so that the tests below can also build a front end with Model L.
option(WG_MODEL_L "Offer Model L (hosted list entry, model=L); OFF = no Model L" OFF)
if(WG_MODEL_L)
set(WG_MODEL_L_VALUE 1)
else()
set(WG_MODEL_L_VALUE 0)
endif()

enable_testing()
# clean/wgshared: the registry, the shared settings block and wg_settings_io.h (with their own tests).
Expand All @@ -41,13 +52,14 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../wgshared ${CMAKE_BINARY_DIR}/wgs
# folder, spec 65.6): not built unless asked for. Its header-only unit tests still run.
option(WG_BUILD_ASI "Build the retired OptiScaler menu-patching plugin WrongGPU.asi" OFF)
add_executable(test_provider_label tests/test_provider_label.cpp)
target_compile_definitions(test_provider_label PRIVATE WRONGGPU_MODEL_L=${WG_MODEL_L_VALUE})
if(MSVC)
set_property(TARGET test_provider_label PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
add_test(NAME fsr_provider_label_unit COMMAND test_provider_label)

# Front-end logic without Windows or D3D12 (routing, forwarding, parameter mapping, log text, settings).
add_library(wg_fsr_core STATIC
set(WG_FSR_CORE_SOURCES
src/amd_compare.cpp
src/amd_provider.cpp
src/async_create.cpp
Expand All @@ -57,22 +69,26 @@ add_library(wg_fsr_core STATIC
src/fsr30_hook.cpp
src/fsr30_map.cpp
src/param_map.cpp)
target_include_directories(wg_fsr_core SYSTEM PUBLIC ${FFX_SDK_DIR})
target_include_directories(wg_fsr_core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(wg_fsr_core PUBLIC wg_shared_headers)
set_target_properties(wg_fsr_core PROPERTIES POSITION_INDEPENDENT_CODE ON)

if(MSVC)
target_compile_options(wg_fsr_core PRIVATE /Zi)
target_compile_options(wg_fsr_core PUBLIC /W4 $<$<COMPILE_LANGUAGE:CXX>:/permissive-> /utf-8 /wd4100)
target_compile_definitions(wg_fsr_core PUBLIC _CRT_SECURE_NO_WARNINGS NOMINMAX)
else()
target_compile_options(wg_fsr_core PUBLIC -Wall -Wextra)
endif()
if(MINGW)
# Struct-returning COM methods (GetDesc, GetCPUDescriptorHandleForHeapStart) need the MSVC calling convention.
target_compile_definitions(wg_fsr_core PUBLIC WIDL_EXPLICIT_AGGREGATE_RETURNS)
endif()
function(wg_fsr_core_library name model_l)
add_library(${name} STATIC ${WG_FSR_CORE_SOURCES})
target_include_directories(${name} SYSTEM PUBLIC ${FFX_SDK_DIR})
target_include_directories(${name} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(${name} PUBLIC wg_shared_headers)
target_compile_definitions(${name} PUBLIC WRONGGPU_MODEL_L=${model_l})
set_target_properties(${name} PROPERTIES POSITION_INDEPENDENT_CODE ON)
if(MSVC)
target_compile_options(${name} PRIVATE /Zi)
target_compile_options(${name} PUBLIC /W4 $<$<COMPILE_LANGUAGE:CXX>:/permissive-> /utf-8 /wd4100)
target_compile_definitions(${name} PUBLIC _CRT_SECURE_NO_WARNINGS NOMINMAX)
else()
target_compile_options(${name} PUBLIC -Wall -Wextra)
endif()
if(MINGW)
# Struct-returning COM methods (GetDesc, GetCPUDescriptorHandleForHeapStart) need the MSVC calling convention.
target_compile_definitions(${name} PUBLIC WIDL_EXPLICIT_AGGREGATE_RETURNS)
endif()
endfunction()
wg_fsr_core_library(wg_fsr_core ${WG_MODEL_L_VALUE})

# Host unit tests (any platform).
add_executable(test_amd_provider tests/test_amd_provider.cpp)
Expand All @@ -84,6 +100,13 @@ add_test(NAME fsr_frontend_unit COMMAND test_frontend)
add_executable(test_fsr30 tests/test_fsr30.cpp)
target_link_libraries(test_fsr30 PRIVATE wg_fsr_core)
add_test(NAME fsr30_hook_unit COMMAND test_fsr30)
# A build without Model L (the default) also tests a front end with it: the same tests, Model L built in.
if(NOT WG_MODEL_L)
wg_fsr_core_library(wg_fsr_core_model_l 1)
add_executable(test_frontend_model_l tests/test_frontend.cpp)
target_link_libraries(test_frontend_model_l PRIVATE wg_fsr_core_model_l)
add_test(NAME fsr_frontend_model_l_unit COMMAND test_frontend_model_l)
endif()

# WrongGPU OptiScaler ASI plugin: thunk logic (any OS) and the offline anchor scan of an OptiScaler binary
# (any OS; skips when WRONGGPU_OPTISCALER_BIN is not set). Header-only resolver/thunk, no extra libraries.
Expand All @@ -107,9 +130,15 @@ if(WIN32)
else()
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set_property(TARGET wg_fsr_core test_frontend test_fsr30 PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
if(TARGET test_frontend_model_l)
set_property(TARGET wg_fsr_core_model_l test_frontend_model_l PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
endif()
if(MINGW)
target_link_options(test_frontend PRIVATE ${WG_STATIC_RUNTIME})
if(TARGET test_frontend_model_l)
target_link_options(test_frontend_model_l PRIVATE ${WG_STATIC_RUNTIME})
endif()
target_link_options(test_fsr30 PRIVATE ${WG_STATIC_RUNTIME})
target_link_options(test_asi_thunk PRIVATE ${WG_STATIC_RUNTIME})
target_link_options(test_asi_scan PRIVATE ${WG_STATIC_RUNTIME})
Expand Down
46 changes: 37 additions & 9 deletions clean/fsr/src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ bool ModelBuiltIn(int32_t srModel) {
if (srModel < 0 || srModel >= WG_SR_MODEL_COUNT) return false;
// Models with a build flag (registry models[].build_flag): the one place of the front end that knows them.
if (std::strcmp(kWgModelRows[srModel].name, "K") == 0) return WRONGGPU_MODEL_K != 0;
if (std::strcmp(kWgModelRows[srModel].name, "L") == 0) return WRONGGPU_MODEL_L != 0;
return true;
}

Expand Down Expand Up @@ -181,7 +182,10 @@ const char* RuntimeProviderName(const std::string& runtimeOptions, const char* e
return name;
}

std::string WithoutModelK(const std::string& options, bool* removed) {
std::string WithoutModelK(const std::string& options, bool* removed) { return WithoutModel(options, 'K', removed); }

std::string WithoutModel(const std::string& options, char model, bool* removed) {
const char upper = char(std::toupper((unsigned char)model)), lower = char(std::tolower((unsigned char)model));
std::string kept;
bool any = false;
for (size_t a = 0; a < options.size();) {
Expand All @@ -190,7 +194,8 @@ std::string WithoutModelK(const std::string& options, bool* removed) {
const std::string item = options.substr(a, b - a);
const size_t equal = item.find('=');
const std::string value = equal == std::string::npos ? "" : Trim(item.substr(equal + 1));
if (equal != std::string::npos && Trim(item.substr(0, equal)) == "model" && (value == "K" || value == "k")) {
if (equal != std::string::npos && Trim(item.substr(0, equal)) == "model" && value.size() == 1 &&
(value[0] == upper || value[0] == lower)) {
any = true;
} else {
if (!kept.empty()) kept += options[a - 1]; // the separator in front of the item
Expand All @@ -202,13 +207,14 @@ std::string WithoutModelK(const std::string& options, bool* removed) {
return any ? kept : options;
}

#if !WRONGGPU_MODEL_K
std::string IgnoreModelK(Config& config) {
bool ini = false, env = false;
config.runtimeOptions = WithoutModelK(config.runtimeOptions, &ini);
#if !WRONGGPU_MODEL_K || !WRONGGPU_MODEL_L
// model=<letter> dropped from the ini's runtime options and from WG_RUNTIME_OPTIONS (also the process environment);
// *ini / *env: where it was.
static void DropModelOption(Config& config, char model, bool* ini, bool* env) {
config.runtimeOptions = WithoutModel(config.runtimeOptions, model, ini);
if (const char* value = std::getenv("WG_RUNTIME_OPTIONS")) {
const std::string kept = WithoutModelK(value, &env);
if (env) {
const std::string kept = WithoutModel(value, model, env);
if (*env) {
#ifdef _WIN32
_putenv_s("WG_RUNTIME_OPTIONS", kept.c_str()); // also the process environment; empty: removed
#else
Expand All @@ -217,6 +223,24 @@ std::string IgnoreModelK(Config& config) {
#endif
}
}
}
#endif

#if !WRONGGPU_MODEL_L
std::string IgnoreModelL(Config& config) {
bool ini = false, env = false;
DropModelOption(config, 'L', &ini, &env);
if (!ini && !env) return std::string();
return std::string("note: model=L (") + (ini ? "runtime_options in wronggpu.ini" : "") + (ini && env ? " and " : "") +
(env ? "WG_RUNTIME_OPTIONS" : "") + ") is refused: Model L is not part of this build of the front end "
"(CMake WG_MODEL_L); Model M is used";
}
#endif

#if !WRONGGPU_MODEL_K
std::string IgnoreModelK(Config& config) {
bool ini = false, env = false;
DropModelOption(config, 'K', &ini, &env);
if (!ini && !env) return std::string();
return std::string("note: model=K (") + (ini ? "runtime_options in wronggpu.ini" : "") + (ini && env ? " and " : "") +
(env ? "WG_RUNTIME_OPTIONS" : "") + ") is ignored: Model K is not part of this build; Model M is used";
Expand Down Expand Up @@ -394,8 +418,12 @@ std::string OptionValue(const std::string& options, const char* key, bool* found
}

ModelChoice ChooseModelDir(const std::vector<ModelPlace>& places, bool modelK, const std::function<bool(const std::string&)>& exists) {
return ChooseModelDir(places, modelK ? 'K' : 'M', exists);
}

ModelChoice ChooseModelDir(const std::vector<ModelPlace>& places, char model, const std::function<bool(const std::string&)>& exists) {
ModelChoice c;
const char* leaf = modelK ? "\\K\\model.wgcm" : "\\model.wgcm";
const char* leaf = model == 'K' ? "\\K\\model.wgcm" : model == 'L' ? "\\L\\model.wgcm" : "\\model.wgcm";
for (size_t i = 0; i < places.size(); ++i) {
const ModelPlace& p = places[i];
if (p.dir.empty()) continue;
Expand Down
11 changes: 11 additions & 0 deletions clean/fsr/src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <vector>

#include "model_k.h"
#include "model_l.h"
#include "wg_registry_gen.h" // clean/wgshared: options, version-list entries, models (plain C, no Windows headers)

namespace wgfsr {
Expand Down Expand Up @@ -131,6 +132,13 @@ std::string NormalizeOptions(const std::string& text);
// The options (items separated by ';' or ',') without their model=K items; *removed: whether there was one. For
// builds without Model K (model_k.h), which drop the item before the runtime reads it.
std::string WithoutModelK(const std::string& options, bool* removed);
// The same for any model letter (model=<letter>, either case): WithoutModelK is WithoutModel(options, 'K', removed).
std::string WithoutModel(const std::string& options, char model, bool* removed);
#if !WRONGGPU_MODEL_L
// A build without Model L (model_l.h, CMake WG_MODEL_L=OFF): drops model=L from config.runtimeOptions and from
// WG_RUNTIME_OPTIONS as IgnoreModelK does, so that Model M runs. Returns the one line for the log, or "".
std::string IgnoreModelL(Config& config);
#endif
#if !WRONGGPU_MODEL_K
// A build without Model K: drops model=K from config.runtimeOptions (wronggpu.ini) and from WG_RUNTIME_OPTIONS in the
// process environment, so that Model M runs (the runtime library refuses the option, and it reads the environment as
Expand Down Expand Up @@ -159,6 +167,9 @@ struct ModelChoice {
};
// The first place (in order) whose model file exists; a runtime-default place ends the search without a probe.
ModelChoice ChooseModelDir(const std::vector<ModelPlace>& places, bool modelK, const std::function<bool(const std::string&)>& exists);
// The same for a model by its letter: M looks for <place>\model.wgcm, K and L for <place>\K\model.wgcm and
// <place>\L\model.wgcm (the folders the launcher converts them into and the runtime reads under model_dir).
ModelChoice ChooseModelDir(const std::vector<ModelPlace>& places, char model, const std::function<bool(const std::string&)>& exists);

// Original process-specific synchronization default. Returns true when an option was added; explicit user
// choices and other games/backends are preserved. No image/model settings are changed.
Expand Down
Loading
Loading