Compare commits

...

14 commits

Author SHA1 Message Date
Xu Liu
08df43628d bump: v0.8.2 2022-04-30 21:41:37 +08:00
Xu Liu
dc719bcc65 chore: 更新依赖 2022-04-30 21:33:24 +08:00
Xu Liu
64f67d9517 Merge branch 'main' into release/v0.8 2022-04-08 19:24:20 +08:00
刘旭
7a7f7ef9dd fix: 适配鼠标加速关闭的情况
fixes #345
2022-04-08 15:19:41 +08:00
Xu Liu
2660489250 Merge branch 'main' into release/v0.8 2022-03-20 21:07:00 +08:00
刘旭
f843ed530e
perf: 降低 Anime4K_Upscale_GAN_x2_S 的显存占用 2022-03-13 14:45:28 +08:00
刘旭
dd743ad557 fix: 启用“在 3D 游戏中限制光标”时不使用多屏幕
fixes #321
2022-03-12 21:25:23 +08:00
Xu Liu
f711309ddf fix: 修复 Anime4K_Thin_HQ 的移植错误 2022-03-12 18:41:52 +08:00
Xu Liu
92a656b36c fix: 修复 Anime4K 降噪系列的移植错误 2022-03-05 22:02:17 +08:00
Xu Liu
c231abe376 fix:优化着色器签名 2022-01-30 22:09:05 +08:00
Xu Liu
9ee4e90da7 chore: 优化日志记录 2022-01-30 21:19:09 +08:00
刘旭
5610c23424
Update README.md 2022-01-30 20:12:11 +08:00
Xu Liu
3d0a655db1 fix: 使用 SEQUENTIAL 交换链而不是 DISCARD
只要显卡支持始终启用 DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING
调试模式下开启 DXGI 调试
2022-01-30 19:13:10 +08:00
刘旭
5eb4ff606d fix: 优化创建全屏窗口的时机 2022-01-28 15:57:23 +08:00
19 changed files with 119 additions and 104 deletions

View file

@ -62,8 +62,8 @@ float4 Pass1(float2 pos) {
float ss = SPATIAL_SIGMA; float ss = SPATIAL_SIGMA;
for (uint i = 0; i < KERNELLEN; i++) { for (uint i = 0; i < KERNELLEN; i++) {
float2 ipos = pos + GETOFFSET(i) * float2(inputPtX, inputPtY); int2 ipos = GETOFFSET(i);
float3 v = INPUT.Sample(sam, ipos).rgb; float3 v = INPUT.Sample(sam, pos + ipos * float2(inputPtX, inputPtY)).rgb;
float3 d = gaussian_vec(v, is, vc) * gaussian(length(ipos), ss, 0.0); float3 d = gaussian_vec(v, is, vc) * gaussian(length(ipos), ss, 0.0);
sum += d * v; sum += d * v;
n += d; n += d;

View file

@ -102,9 +102,10 @@ float4 Pass2(float2 pos) {
uint i; uint i;
for (i = 0; i < KERNELLEN; i++) { for (i = 0; i < KERNELLEN; i++) {
float2 ipos = pos + GETOFFSET(i) * float2(inputPtX, inputPtY); int2 ipos = GETOFFSET(i);
histogram_v[i] = INPUT.Sample(sam, ipos).rgb; float2 ppos = pos + ipos * float2(inputPtX, inputPtY);
histogram_l[i] = lumaTex.Sample(sam, ipos).x; histogram_v[i] = INPUT.Sample(sam, ppos).rgb;
histogram_l[i] = lumaTex.Sample(sam, ppos).x;
histogram_w[i] = gaussian(histogram_l[i], is, vc) * gaussian(length(ipos), ss, 0.0); histogram_w[i] = gaussian(histogram_l[i], is, vc) * gaussian(length(ipos), ss, 0.0);
n += histogram_w[i]; n += histogram_w[i];
} }

View file

@ -82,9 +82,10 @@ float4 Pass2(float2 pos) {
uint i; uint i;
for (i = 0; i < KERNELLEN; i++) { for (i = 0; i < KERNELLEN; i++) {
float2 ipos = pos + GETOFFSET(i) * float2(inputPtX, inputPtY); int2 ipos = GETOFFSET(i);
histogram_v[i] = INPUT.Sample(sam, ipos).rgb; float2 ppos = pos + ipos * float2(inputPtX, inputPtY);
histogram_l[i] = lumaTex.Sample(sam, ipos).x; histogram_v[i] = INPUT.Sample(sam, ppos).rgb;
histogram_l[i] = lumaTex.Sample(sam, ppos).x;
histogram_w[i] = gaussian(histogram_l[i], is, vc) * gaussian(length(ipos), ss, 0.0); histogram_w[i] = gaussian(histogram_l[i], is, vc) * gaussian(length(ipos), ss, 0.0);
histogram_wn[i] = 0.0; histogram_wn[i] = 0.0;
} }

View file

@ -154,13 +154,13 @@ float4 Pass4(float2 pos) {
} }
//!PASS 5 //!PASS 5
//!BIND tex1 //!BIND tex2
//!SAVE tex2 //!SAVE tex1
float4 Pass5(float2 pos) { float4 Pass5(float2 pos) {
float l = tex1.Sample(sam, float2(pos.x - inputPtX, pos.y)).x; float l = tex2.Sample(sam, float2(pos.x - inputPtX, pos.y)).x;
float c = tex1.Sample(sam, pos).x; float c = tex2.Sample(sam, pos).x;
float r = tex1.Sample(sam, float2(pos.x + inputPtX, pos.y)).x; float r = tex2.Sample(sam, float2(pos.x + inputPtX, pos.y)).x;
float xgrad = (-l + r); float xgrad = (-l + r);
float ygrad = (l + c + c + r); float ygrad = (l + c + c + r);
@ -169,13 +169,13 @@ float4 Pass5(float2 pos) {
} }
//!PASS 6 //!PASS 6
//!BIND tex2 //!BIND tex1
//!SAVE tex1 //!SAVE tex2
float4 Pass6(float2 pos) { float4 Pass6(float2 pos) {
float2 t = tex2.Sample(sam, float2(pos.x, pos.y - inputPtY)).xy; float2 t = tex1.Sample(sam, float2(pos.x, pos.y - inputPtY)).xy;
float cx = tex2.Sample(sam, pos).x; float cx = tex1.Sample(sam, pos).x;
float2 b = tex2.Sample(sam, float2(pos.x, pos.y + inputPtY)).xy; float2 b = tex1.Sample(sam, float2(pos.x, pos.y + inputPtY)).xy;
float xgrad = (t.x + cx + cx + b.x) / 8.0; float xgrad = (t.x + cx + cx + b.x) / 8.0;
@ -186,18 +186,18 @@ float4 Pass6(float2 pos) {
} }
//!PASS 7 //!PASS 7
//!BIND tex1, INPUT //!BIND tex2, INPUT
#define STRENGTH strength #define STRENGTH strength
#define ITERATIONS iterations #define ITERATIONS iterations
float4 Pass7(float2 pos) { float4 Pass7(float2 pos) {
float2 d = {inputPtX, inputPtY}; float2 d = { inputPtX, inputPtY };
float relstr = inputHeight / 1080.0 * STRENGTH; float relstr = inputHeight / 1080.0 * STRENGTH;
for (int i = 0; i < ITERATIONS; i++) { for (int i = 0; i < ITERATIONS; i++) {
float2 dn = tex1.SampleLevel(sam1, pos, 0).xy; float2 dn = tex2.SampleLevel(sam1, pos, 0).xy;
float2 dd = (dn / (length(dn) + 0.01)) * d * relstr; //Quasi-normalization for large vectors, avoids divide by zero float2 dd = (dn / (length(dn) + 0.01)) * d * relstr; //Quasi-normalization for large vectors, avoids divide by zero
pos -= dd; pos -= dd;
} }

View file

@ -83,12 +83,6 @@ Texture2D tex7;
//!FORMAT R16G16B16A16_FLOAT //!FORMAT R16G16B16A16_FLOAT
Texture2D tex8; Texture2D tex8;
//!TEXTURE
//!WIDTH INPUT_WIDTH
//!HEIGHT INPUT_HEIGHT
//!FORMAT R16G16B16A16_FLOAT
Texture2D tex9;
//!PASS 1 //!PASS 1
//!BIND INPUT //!BIND INPUT
@ -480,7 +474,7 @@ void Pass5(float2 pos, out float4 target1, out float4 target2, out float4 target
//!PASS 6 //!PASS 6
//!BIND tex7, tex1, tex3, tex2, tex4, tex5 //!BIND tex7, tex1, tex3, tex2, tex4, tex5
//!SAVE tex8, tex9 //!SAVE tex6, tex8
void Pass6(float2 pos, out float4 target1, out float4 target2) { void Pass6(float2 pos, out float4 target1, out float4 target2) {
// [ a, d, g ] // [ a, d, g ]
@ -591,21 +585,21 @@ void Pass6(float2 pos, out float4 target1, out float4 target2) {
//!PASS 7 //!PASS 7
//!BIND tex8, tex9, INPUT //!BIND tex6, tex8, INPUT
float4 Pass7(float2 pos) { float4 Pass7(float2 pos) {
// [ a, d, g ] // [ a, d, g ]
// [ b, e, h ] // [ b, e, h ]
// [ c, f, i ] // [ c, f, i ]
float4 a1 = tex8.Sample(sam1, pos + float2(-outputPtX, -outputPtY)); float4 a1 = tex6.Sample(sam1, pos + float2(-outputPtX, -outputPtY));
float4 b1 = tex8.Sample(sam1, pos + float2(-outputPtX, 0)); float4 b1 = tex6.Sample(sam1, pos + float2(-outputPtX, 0));
float4 c1 = tex8.Sample(sam1, pos + float2(-outputPtX, outputPtY)); float4 c1 = tex6.Sample(sam1, pos + float2(-outputPtX, outputPtY));
float4 d1 = tex8.Sample(sam1, pos + float2(0, -outputPtY)); float4 d1 = tex6.Sample(sam1, pos + float2(0, -outputPtY));
float4 e1 = tex8.Sample(sam1, pos); float4 e1 = tex6.Sample(sam1, pos);
float4 f1 = tex8.Sample(sam1, pos + float2(0, outputPtY)); float4 f1 = tex6.Sample(sam1, pos + float2(0, outputPtY));
float4 g1 = tex8.Sample(sam1, pos + float2(outputPtX, -outputPtY)); float4 g1 = tex6.Sample(sam1, pos + float2(outputPtX, -outputPtY));
float4 h1 = tex8.Sample(sam1, pos + float2(outputPtX, 0)); float4 h1 = tex6.Sample(sam1, pos + float2(outputPtX, 0));
float4 i1 = tex8.Sample(sam1, pos + float2(outputPtX, outputPtY)); float4 i1 = tex6.Sample(sam1, pos + float2(outputPtX, outputPtY));
float4 na1 = max(-a1, 0); float4 na1 = max(-a1, 0);
float4 nb1 = max(-b1, 0); float4 nb1 = max(-b1, 0);
@ -627,15 +621,15 @@ float4 Pass7(float2 pos) {
h1 = max(h1, 0); h1 = max(h1, 0);
i1 = max(i1, 0); i1 = max(i1, 0);
float4 a2 = tex9.Sample(sam1, pos + float2(-outputPtX, -outputPtY)); float4 a2 = tex8.Sample(sam1, pos + float2(-outputPtX, -outputPtY));
float4 b2 = tex9.Sample(sam1, pos + float2(-outputPtX, 0)); float4 b2 = tex8.Sample(sam1, pos + float2(-outputPtX, 0));
float4 c2 = tex9.Sample(sam1, pos + float2(-outputPtX, outputPtY)); float4 c2 = tex8.Sample(sam1, pos + float2(-outputPtX, outputPtY));
float4 d2 = tex9.Sample(sam1, pos + float2(0, -outputPtY)); float4 d2 = tex8.Sample(sam1, pos + float2(0, -outputPtY));
float4 e2 = tex9.Sample(sam1, pos); float4 e2 = tex8.Sample(sam1, pos);
float4 f2 = tex9.Sample(sam1, pos + float2(0, outputPtY)); float4 f2 = tex8.Sample(sam1, pos + float2(0, outputPtY));
float4 g2 = tex9.Sample(sam1, pos + float2(outputPtX, -outputPtY)); float4 g2 = tex8.Sample(sam1, pos + float2(outputPtX, -outputPtY));
float4 h2 = tex9.Sample(sam1, pos + float2(outputPtX, 0)); float4 h2 = tex8.Sample(sam1, pos + float2(outputPtX, 0));
float4 i2 = tex9.Sample(sam1, pos + float2(outputPtX, outputPtY)); float4 i2 = tex8.Sample(sam1, pos + float2(outputPtX, outputPtY));
float4 na2 = max(-a2, 0); float4 na2 = max(-a2, 0);
float4 nb2 = max(-b2, 0); float4 nb2 = max(-b2, 0);

View file

@ -33,7 +33,7 @@ namespace Magpie {
/// Interaction logic for App.xaml /// Interaction logic for App.xaml
/// </summary> /// </summary>
public partial class App : Application { public partial class App : Application {
public static readonly Version APP_VERSION = new("0.8.1.0"); public static readonly Version APP_VERSION = new("0.8.2.0");
public static readonly string SCALE_MODELS_JSON_PATH = ".\\ScaleModels.json"; public static readonly string SCALE_MODELS_JSON_PATH = ".\\ScaleModels.json";
public static readonly string LOGS_FOLDER = ".\\logs\\"; public static readonly string LOGS_FOLDER = ".\\logs\\";

View file

@ -63,7 +63,7 @@
<PackageReference Include="MouseKeyHook" Version="5.6.0"> <PackageReference Include="MouseKeyHook" Version="5.6.0">
<NoWarn>NU1701</NoWarn> <NoWarn>NU1701</NoWarn>
</PackageReference> </PackageReference>
<PackageReference Include="NLog" Version="4.7.12" /> <PackageReference Include="NLog" Version="4.7.15" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View file

@ -19,8 +19,8 @@ using System.Windows;
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示: //通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.8.1.0")] [assembly: AssemblyVersion("0.8.2.0")]
[assembly: AssemblyFileVersion("0.8.1.0")] [assembly: AssemblyFileVersion("0.8.2.0")]
// 将 ComVisible 设置为 false 会使此程序集中的类型 // 将 ComVisible 设置为 false 会使此程序集中的类型

View file

@ -6,6 +6,8 @@
🌍 **简体中文** | [English](./README_EN.md) 🌍 **简体中文** | [English](./README_EN.md)
**此分支维护一个支持 Direct3D 功能级别 10 的版本,不再添加新功能。**
Magpie 可以将任意窗口放大至全屏,内置大量缩放算法/滤镜。主要用于游戏窗口的放大显示,适用于不支持全屏模式,或者内置的全屏模式会使画面模糊的情况。 Magpie 可以将任意窗口放大至全屏,内置大量缩放算法/滤镜。主要用于游戏窗口的放大显示,适用于不支持全屏模式,或者内置的全屏模式会使画面模糊的情况。
使用中遇到问题请提交 issue。 使用中遇到问题请提交 issue。

View file

@ -136,7 +136,7 @@ bool App::Run(
if (_srcFrameRect == RECT{}) { if (_srcFrameRect == RECT{}) {
// FrameSource 初始化完成后计算窗口边框,因为初始化过程中可能改变窗口位置 // FrameSource 初始化完成后计算窗口边框,因为初始化过程中可能改变窗口位置
if (!UpdateSrcFrameRect()) { if (!UpdateSrcFrameRect()) {
SPDLOG_LOGGER_ERROR(logger, "UpdateSrcFrameRect 失败"); SPDLOG_LOGGER_CRITICAL(logger, "UpdateSrcFrameRect 失败");
return false; return false;
} }
} }
@ -144,13 +144,6 @@ bool App::Run(
SPDLOG_LOGGER_INFO(logger, fmt::format("源窗口尺寸:{}x{}", SPDLOG_LOGGER_INFO(logger, fmt::format("源窗口尺寸:{}x{}",
_srcFrameRect.right - _srcFrameRect.left, _srcFrameRect.bottom - _srcFrameRect.top)); _srcFrameRect.right - _srcFrameRect.left, _srcFrameRect.bottom - _srcFrameRect.top));
if (!_renderer->InitializeEffectsAndCursor(effectsJson)) {
SPDLOG_LOGGER_CRITICAL(logger, "初始化效果失败,即将退出");
Close();
_Run();
return false;
}
// 禁用窗口圆角 // 禁用窗口圆角
if (_frameSource->HasRoundCornerInWin11()) { if (_frameSource->HasRoundCornerInWin11()) {
const auto& version = Utils::GetOSVersion(); const auto& version = Utils::GetOSVersion();
@ -170,6 +163,22 @@ bool App::Run(
} }
} }
if (IsDisableDirectFlip() && !IsBreakpointMode()) {
// 在此处创建的 DDF 窗口不会立刻显示
if (!_DisableDirectFlip()) {
SPDLOG_LOGGER_ERROR(logger, "_DisableDirectFlip 失败");
}
}
if (!_renderer->InitializeEffectsAndCursor(effectsJson)) {
SPDLOG_LOGGER_CRITICAL(logger, "初始化效果失败,即将退出");
Close();
_Run();
return false;
}
ShowWindow(_hwndHost, SW_NORMAL);
_Run(); _Run();
return true; return true;
@ -192,12 +201,14 @@ void App::_Run() {
_renderer->Render(); _renderer->Render();
// 第二帧(等待时或完成后)创建 DDF 窗口 // 第二帧(等待时或完成后)显示 DDF 窗口
// 如果在 Run 中创建会有短暂的灰屏 // 如果在 Run 中创建会有短暂的灰屏
// 选择第二帧的原因:当 GetFrameCount() 返回 1 时第一帧可能处于等待状态而没有渲染,见 Renderer::Render() // 选择第二帧的原因:当 GetFrameCount() 返回 1 时第一帧可能处于等待状态而没有渲染,见 Renderer::Render()
if (_renderer->GetTimer().GetFrameCount() == 2 && !_hwndDDF && IsDisableDirectFlip() && !IsBreakpointMode()) { if (_renderer->GetTimer().GetFrameCount() == 2 && _hwndDDF) {
if (!_DisableDirectFlip()) { ShowWindow(_hwndDDF, SW_NORMAL);
SPDLOG_LOGGER_ERROR(logger, "_DisableDirectFlip 失败");
if (!SetWindowPos(_hwndDDF, _hwndHost, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOREDRAW)) {
SPDLOG_LOGGER_ERROR(logger, MakeWin32ErrorMsg("SetWindowPos 失败"));
} }
} }
} }
@ -355,8 +366,8 @@ bool App::_CreateHostWnd() {
} }
// 主窗口没有覆盖 Virtual Screen 则使用多屏幕模式 // 主窗口没有覆盖 Virtual Screen 则使用多屏幕模式
// 打开断点模式时不使用多屏幕模式 // 启用“在 3D 游戏中限制光标”或断点模式时不使用多屏幕模式
_isMultiMonitorMode = !IsBreakpointMode() && GetMultiMonitorUsage() != 2 && _isMultiMonitorMode = !IsConfineCursorIn3DGames() && !IsBreakpointMode() && GetMultiMonitorUsage() != 2 &&
((_hostWndRect.right - _hostWndRect.left) < GetSystemMetrics(SM_CXVIRTUALSCREEN) || ((_hostWndRect.right - _hostWndRect.left) < GetSystemMetrics(SM_CXVIRTUALSCREEN) ||
(_hostWndRect.bottom - _hostWndRect.top) < GetSystemMetrics(SM_CYVIRTUALSCREEN)); (_hostWndRect.bottom - _hostWndRect.top) < GetSystemMetrics(SM_CYVIRTUALSCREEN));
@ -364,7 +375,7 @@ bool App::_CreateHostWnd() {
(IsBreakpointMode() ? 0 : WS_EX_TOPMOST) | WS_EX_NOACTIVATE | WS_EX_LAYERED | WS_EX_TRANSPARENT, (IsBreakpointMode() ? 0 : WS_EX_TOPMOST) | WS_EX_NOACTIVATE | WS_EX_LAYERED | WS_EX_TRANSPARENT,
HOST_WINDOW_CLASS_NAME, HOST_WINDOW_CLASS_NAME,
HOST_WINDOW_TITLE, HOST_WINDOW_TITLE,
WS_CLIPCHILDREN | WS_POPUP | WS_VISIBLE, WS_POPUP,
_hostWndRect.left, _hostWndRect.left,
_hostWndRect.top, _hostWndRect.top,
_hostWndRect.right - _hostWndRect.left, _hostWndRect.right - _hostWndRect.left,
@ -388,10 +399,6 @@ bool App::_CreateHostWnd() {
SPDLOG_LOGGER_ERROR(logger, MakeWin32ErrorMsg("SetLayeredWindowAttributes 失败")); SPDLOG_LOGGER_ERROR(logger, MakeWin32ErrorMsg("SetLayeredWindowAttributes 失败"));
} }
if (!ShowWindow(_hwndHost, SW_NORMAL)) {
SPDLOG_LOGGER_ERROR(logger, MakeWin32ErrorMsg("ShowWindow 失败"));
}
SPDLOG_LOGGER_INFO(logger, "已创建主窗口"); SPDLOG_LOGGER_INFO(logger, "已创建主窗口");
return true; return true;
} }
@ -403,7 +410,7 @@ bool App::_DisableDirectFlip() {
WS_EX_NOACTIVATE | WS_EX_LAYERED | WS_EX_TRANSPARENT, WS_EX_NOACTIVATE | WS_EX_LAYERED | WS_EX_TRANSPARENT,
DDF_WINDOW_CLASS_NAME, DDF_WINDOW_CLASS_NAME,
NULL, NULL,
WS_CLIPCHILDREN | WS_POPUP | WS_VISIBLE, WS_POPUP,
_hostWndRect.left, _hostWndRect.left,
_hostWndRect.top, _hostWndRect.top,
_hostWndRect.right - _hostWndRect.left, _hostWndRect.right - _hostWndRect.left,
@ -434,14 +441,6 @@ bool App::_DisableDirectFlip() {
} }
} }
if (!ShowWindow(_hwndDDF, SW_NORMAL)) {
SPDLOG_LOGGER_ERROR(logger, MakeWin32ErrorMsg("ShowWindow 失败"));
}
if (!SetWindowPos(_hwndDDF, _hwndHost, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOREDRAW)) {
SPDLOG_LOGGER_ERROR(logger, MakeWin32ErrorMsg("SetWindowPos 失败"));
}
SPDLOG_LOGGER_INFO(logger, "已创建 DDF 主窗口"); SPDLOG_LOGGER_INFO(logger, "已创建 DDF 主窗口");
return true; return true;
} }

View file

@ -11,7 +11,7 @@ Texture2D originTex : register(t0);
Texture2D maskTex : register(t1); Texture2D maskTex : register(t1);
SamplerState sam : register(s0); SamplerState sam : register(s0);
float4 main(float4 pos : SV_POSITION, float2 coord : TEXCOORD) : SV_Target{ float4 main(float2 coord : TEXCOORD) : SV_Target{
float2 masks = maskTex.Sample(sam, coord).xy; float2 masks = maskTex.Sample(sam, coord).xy;
if (masks.x > 0.5) { if (masks.x > 0.5) {
float3 origin = originTex.Sample(sam, coord).rgb; float3 origin = originTex.Sample(sam, coord).rgb;

View file

@ -30,5 +30,5 @@ private:
// 缓存版本 // 缓存版本
// 当缓存文件结构有更改时将更新它,使得所有旧缓存失效 // 当缓存文件结构有更改时将更新它,使得所有旧缓存失效
static constexpr const UINT _VERSION = 2; static constexpr const UINT _VERSION = 3;
}; };

View file

@ -955,11 +955,11 @@ UINT ResolvePass(std::string_view block, EffectDesc& desc, std::vector<std::stri
// main 函数 // main 函数
if (passDesc.outputs.size() <= 1) { if (passDesc.outputs.size() <= 1) {
passHlsl.append(fmt::format("float4 __M(float4 p:SV_POSITION,float2 c:TEXCOORD):SV_TARGET" passHlsl.append(fmt::format("float4 __M(float2 c:TEXCOORD):SV_TARGET"
"{{return Pass{}(c);}}", index)); "{{return Pass{}(c);}}", index));
} else { } else {
// 多渲染目标 // 多渲染目标
passHlsl.append("void __M(float4 p:SV_POSITION,float2 c:TEXCOORD,out float4 t0:SV_TARGET0,out float4 t1:SV_TARGET1"); passHlsl.append("void __M(float2 c:TEXCOORD,out float4 t0:SV_TARGET0,out float4 t1:SV_TARGET1");
for (int i = 2; i < passDesc.outputs.size(); ++i) { for (int i = 2; i < passDesc.outputs.size(); ++i) {
passHlsl.append(fmt::format(",out float4 t{0}:SV_TARGET{0}", i)); passHlsl.append(fmt::format(",out float4 t{0}:SV_TARGET{0}", i));
} }

View file

@ -7,6 +7,9 @@
#include "EffectCompiler.h" #include "EffectCompiler.h"
#include <rapidjson/document.h> #include <rapidjson/document.h>
#pragma push_macro("GetObject")
#undef GetObject
#include <rapidjson/document.h>
extern std::shared_ptr<spdlog::logger> logger; extern std::shared_ptr<spdlog::logger> logger;
@ -110,7 +113,7 @@ bool Renderer::GetShaderResourceView(ID3D11Texture2D* texture, ID3D11ShaderResou
bool Renderer::SetFillVS() { bool Renderer::SetFillVS() {
if (!_fillVS) { if (!_fillVS) {
const char* src = "void m(uint i:SV_VERTEXID,out float4 p:SV_POSITION,out float2 c:TEXCOORD){c=float2(i&1,i>>1)*2;p=float4(c.x*2-1,-c.y*2+1,0,1);}"; const char* src = "void m(uint i:SV_VERTEXID,out float2 c:TEXCOORD,out float4 p:SV_POSITION){c=float2(i&1,i>>1)*2;p=float4(c.x*2-1,-c.y*2+1,0,1);}";
ComPtr<ID3DBlob> blob; ComPtr<ID3DBlob> blob;
if (!CompileShader(true, src, "m", &blob, "FillVS")) { if (!CompileShader(true, src, "m", &blob, "FillVS")) {
@ -135,7 +138,7 @@ bool Renderer::SetFillVS() {
bool Renderer::SetCopyPS(ID3D11SamplerState* sampler, ID3D11ShaderResourceView* input) { bool Renderer::SetCopyPS(ID3D11SamplerState* sampler, ID3D11ShaderResourceView* input) {
if (!_copyPS) { if (!_copyPS) {
const char* src = "Texture2D t:register(t0);SamplerState s:register(s0);float4 m(float4 p:SV_POSITION,float2 c:TEXCOORD):SV_Target{return t.Sample(s,c);}"; const char* src = "Texture2D t:register(t0);SamplerState s:register(s0);float4 m(float2 c:TEXCOORD):SV_Target{return t.Sample(s,c);}";
ComPtr<ID3DBlob> blob; ComPtr<ID3DBlob> blob;
if (!CompileShader(false, src, "m", &blob, "CopyPS")) { if (!CompileShader(false, src, "m", &blob, "CopyPS")) {
@ -160,7 +163,7 @@ bool Renderer::SetCopyPS(ID3D11SamplerState* sampler, ID3D11ShaderResourceView*
bool Renderer::SetSimpleVS(ID3D11Buffer* simpleVB) { bool Renderer::SetSimpleVS(ID3D11Buffer* simpleVB) {
if (!_simpleVS) { if (!_simpleVS) {
const char* src = "void m(float4 p:SV_POSITION,float2 c:TEXCOORD,out float4 q:SV_POSITION,out float2 d:TEXCOORD) {q=p;d=c;}"; const char* src = "void m(float4 p:SV_POSITION,float2 c:TEXCOORD,out float2 d:TEXCOORD,out float4 q:SV_POSITION) {q=p;d=c;}";
ComPtr<ID3DBlob> blob; ComPtr<ID3DBlob> blob;
if (!CompileShader(true, src, "m", &blob, "SimpleVS")) { if (!CompileShader(true, src, "m", &blob, "SimpleVS")) {
@ -316,7 +319,13 @@ bool Renderer::IsDebugLayersAvailable() {
} }
bool Renderer::_InitD3D() { bool Renderer::_InitD3D() {
HRESULT hr = CreateDXGIFactory1(IID_PPV_ARGS(_dxgiFactory.ReleaseAndGetAddressOf())); #ifdef _DEBUG
UINT flag = DXGI_CREATE_FACTORY_DEBUG;
#else
UINT flag = 0;
#endif // _DEBUG
HRESULT hr = CreateDXGIFactory2(flag, IID_PPV_ARGS(_dxgiFactory.ReleaseAndGetAddressOf()));
if (FAILED(hr)) { if (FAILED(hr)) {
return false; return false;
} }
@ -333,6 +342,7 @@ bool Renderer::_InitD3D() {
SPDLOG_LOGGER_WARN(logger, MakeComErrorMsg("CheckFeatureSupport 失败", hr)); SPDLOG_LOGGER_WARN(logger, MakeComErrorMsg("CheckFeatureSupport 失败", hr));
} }
} }
_supportTearing = !!supportTearing;
SPDLOG_LOGGER_INFO(logger, fmt::format("可变刷新率支持:{}", supportTearing ? "" : "")); SPDLOG_LOGGER_INFO(logger, fmt::format("可变刷新率支持:{}", supportTearing ? "" : ""));
@ -448,8 +458,13 @@ bool Renderer::_CreateSwapChain() {
sd.SampleDesc.Quality = 0; sd.SampleDesc.Quality = 0;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_SHADER_INPUT; sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_SHADER_INPUT;
sd.BufferCount = (App::GetInstance().IsDisableLowLatency() && App::GetInstance().GetFrameRate() == 0) ? 3 : 2; sd.BufferCount = (App::GetInstance().IsDisableLowLatency() && App::GetInstance().GetFrameRate() == 0) ? 3 : 2;
sd.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD; // 使用 DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL 而不是 DXGI_SWAP_EFFECT_FLIP_DISCARD
sd.Flags = App::GetInstance().GetFrameRate() != 0 ? DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING : DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT; // 不渲染四周(可能存在的)黑边,因此必须保证交换链缓冲区不被改变
// 否则将不得不在每帧渲染前清空后缓冲区,这个操作在一些显卡上比较耗时
sd.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
// 只要显卡支持始终启用 DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING
sd.Flags = (_supportTearing ? DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING : 0)
| (App::GetInstance().GetFrameRate() == 0 ? DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT : 0);
ComPtr<IDXGISwapChain1> dxgiSwapChain = nullptr; ComPtr<IDXGISwapChain1> dxgiSwapChain = nullptr;
HRESULT hr = _dxgiFactory->CreateSwapChainForHwnd( HRESULT hr = _dxgiFactory->CreateSwapChainForHwnd(
@ -1022,3 +1037,5 @@ bool Renderer::GetSampler(EffectSamplerFilterType filterType, EffectSamplerAddre
*result = *sampler; *result = *sampler;
return true; return true;
} }
#pragma pop_macro("GetObject")

View file

@ -82,6 +82,7 @@ private:
RECT _srcWndRect{}; RECT _srcWndRect{};
D3D_FEATURE_LEVEL _featureLevel = D3D_FEATURE_LEVEL_10_0; D3D_FEATURE_LEVEL _featureLevel = D3D_FEATURE_LEVEL_10_0;
bool _supportTearing = false;
ComPtr<IDXGIFactory2> _dxgiFactory; ComPtr<IDXGIFactory2> _dxgiFactory;
ComPtr<IDXGIDevice1> _dxgiDevice; ComPtr<IDXGIDevice1> _dxgiDevice;

View file

@ -26,8 +26,8 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_DEFAULT
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,8,1,0 FILEVERSION 0,8,2,0
PRODUCTVERSION 0,8,1,0 PRODUCTVERSION 0,8,2,0
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -42,12 +42,12 @@ BEGIN
BEGIN BEGIN
BLOCK "040004b0" BLOCK "040004b0"
BEGIN BEGIN
VALUE "FileVersion", "0.8.1.0" VALUE "FileVersion", "0.8.2.0"
VALUE "InternalName", "Runtime.dll" VALUE "InternalName", "Runtime.dll"
VALUE "LegalCopyright", "Copyright (C) 2021 Liu Xu" VALUE "LegalCopyright", "Copyright (C) 2021 Liu Xu"
VALUE "OriginalFilename", "Runtime.dll" VALUE "OriginalFilename", "Runtime.dll"
VALUE "ProductName", "Magpie" VALUE "ProductName", "Magpie"
VALUE "ProductVersion", "0.8.1.0" VALUE "ProductVersion", "0.8.2.0"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.211028.7\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.211028.7\build\native\Microsoft.Windows.CppWinRT.props')" /> <Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.220418.1\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.220418.1\build\native\Microsoft.Windows.CppWinRT.props')" />
<ItemGroup Label="ProjectConfigurations"> <ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64"> <ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration> <Configuration>Debug</Configuration>
@ -205,17 +205,17 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.211028.7\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.211028.7\build\native\Microsoft.Windows.CppWinRT.targets')" />
<Import Project="..\packages\Microsoft.XAudio2.Redist.1.2.8\build\native\Microsoft.XAudio2.Redist.targets" Condition="Exists('..\packages\Microsoft.XAudio2.Redist.1.2.8\build\native\Microsoft.XAudio2.Redist.targets')" /> <Import Project="..\packages\Microsoft.XAudio2.Redist.1.2.8\build\native\Microsoft.XAudio2.Redist.targets" Condition="Exists('..\packages\Microsoft.XAudio2.Redist.1.2.8\build\native\Microsoft.XAudio2.Redist.targets')" />
<Import Project="..\packages\directxtk_desktop_2017.2021.11.8.1\build\native\directxtk_desktop_2017.targets" Condition="Exists('..\packages\directxtk_desktop_2017.2021.11.8.1\build\native\directxtk_desktop_2017.targets')" /> <Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.220418.1\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.220418.1\build\native\Microsoft.Windows.CppWinRT.targets')" />
<Import Project="..\packages\directxtk_desktop_2017.2022.3.24.2\build\native\directxtk_desktop_2017.targets" Condition="Exists('..\packages\directxtk_desktop_2017.2022.3.24.2\build\native\directxtk_desktop_2017.targets')" />
</ImportGroup> </ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup> <PropertyGroup>
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText> <ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
</PropertyGroup> </PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.211028.7\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.211028.7\build\native\Microsoft.Windows.CppWinRT.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.211028.7\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.211028.7\build\native\Microsoft.Windows.CppWinRT.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.XAudio2.Redist.1.2.8\build\native\Microsoft.XAudio2.Redist.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.XAudio2.Redist.1.2.8\build\native\Microsoft.XAudio2.Redist.targets'))" /> <Error Condition="!Exists('..\packages\Microsoft.XAudio2.Redist.1.2.8\build\native\Microsoft.XAudio2.Redist.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.XAudio2.Redist.1.2.8\build\native\Microsoft.XAudio2.Redist.targets'))" />
<Error Condition="!Exists('..\packages\directxtk_desktop_2017.2021.11.8.1\build\native\directxtk_desktop_2017.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\directxtk_desktop_2017.2021.11.8.1\build\native\directxtk_desktop_2017.targets'))" /> <Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.220418.1\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.220418.1\build\native\Microsoft.Windows.CppWinRT.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.220418.1\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.220418.1\build\native\Microsoft.Windows.CppWinRT.targets'))" />
<Error Condition="!Exists('..\packages\directxtk_desktop_2017.2022.3.24.2\build\native\directxtk_desktop_2017.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\directxtk_desktop_2017.2022.3.24.2\build\native\directxtk_desktop_2017.targets'))" />
</Target> </Target>
</Project> </Project>

View file

@ -1,9 +1,9 @@
[requires] [requires]
fmt/8.0.1 fmt/8.1.1
spdlog/1.9.1 spdlog/1.10.0
muparser/2.3.2 muparser/2.3.2
yas/7.1.0 yas/7.1.0
rapidjson/cci.20200410 rapidjson/cci.20211112
[generators] [generators]
visual_studio visual_studio

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="directxtk_desktop_2017" version="2021.11.8.1" targetFramework="native" /> <package id="directxtk_desktop_2017" version="2022.3.24.2" targetFramework="native" />
<package id="Microsoft.Windows.CppWinRT" version="2.0.211028.7" targetFramework="native" /> <package id="Microsoft.Windows.CppWinRT" version="2.0.220418.1" targetFramework="native" />
<package id="Microsoft.XAudio2.Redist" version="1.2.8" targetFramework="native" /> <package id="Microsoft.XAudio2.Redist" version="1.2.8" targetFramework="native" />
</packages> </packages>