[FX] 不再支持 GetFrameCount (#1165)

* feat: 不再正式支持 GetFrameCount

* docs: 更新文档

* feat: 删除 GetFrameCount 定义

* feat: USE 和 CAPABILITY 标志不再区分大小写
This commit is contained in:
Xu 2025-05-27 19:22:56 +08:00 committed by GitHub
commit 424576b0cf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 20 additions and 49 deletions

View file

@ -71,7 +71,7 @@ Magpie ships with a handful of effects that can be used in combinations. Most of
* Brightness Boost
* Dilation
* CRT_Geom: One of the most popular CRT shaders. Aims to emulate arcade machines. Check [Emulation General Wiki](https://emulation.gametechwiki.com/index.php/CRT_Geom).
* CRT_Geom: One of the most popular CRT shaders, designed to emulate the look of Arcade-machine. This implementation does not support interlacing simulation. Check [Emulation General Wiki](https://emulation.gametechwiki.com/index.php/CRT_Geom).
* Output size: determined by scale configuration
* Parameters
* Target Gamma
@ -89,8 +89,7 @@ Magpie ships with a handful of effects that can be used in combinations. Most of
* Sharpness: The larger the value is, the clear the image becomes
* Scanline Weight
* Luminance Boost
* Interlacing: Whether to emulate interlacing
* CRT_Hyllian: Provides sharp and clear outputs with slight rims. Similar to Sony BVM displays.
* Output size: determined by scale configuration
* Parameters

View file

@ -5,7 +5,6 @@ MagpieFX is based on DirectX 11 compute shader
//!VERSION 4
// Use the "USE" directive to declare the features being utilized. The following values can be combined:
// MulAdd: Enables the "MulAdd" function.
// Dynamic: Enables the "GetFrameCount" function.
//!USE MulAdd, Dynamic
// Use the "CAPABILITY" directive to declare the capabilities supported by this effect. Whether they
// are enabled depends on user configuration. The following values can be combined:
@ -157,8 +156,6 @@ void Pass2(uint2 blockStart, uint3 threadId) {
**uint2 Rmp8x8(uint id)**: Maps the values of 0 to 63 to coordinates in an 8x8 square in swizzle order, which can improve texture cache hit rate.
**uint GetFrameCount()**: Retrieves the total number of frames rendered so far. When using this function, you must specify "USE Dynamic".
**MF{n} MulAdd(MF{m} x, MF{m}x{n} y, MF{n} a)**: Equivalent to `mul(x, y) + a`, but with higher performance, making it particularly useful for machine learning-based effects. To use this function, you must declare "USE MulAdd". For details, see [#1049](https://github.com/Blinue/Magpie/pull/1049).

View file

@ -5,8 +5,7 @@ MagpieFX 基于 DirectX 11 计算着色器
//!VERSION 4
// 使用 USE 指令声明使用的功能,支持以下值的组合:
// MulAdd使 MulAdd 函数可用
// Dynamic使 GetFrameCount 函数可用
//!USE MulAdd, Dynamic
//!USE MulAdd
// 使用 CAPABILITY 指令声明效果所支持的技术,但是否使用这些技术取决于用户配置。支持以下值的组合:
// FP16声明对 FP16 的支持
//!CAPABILITY FP16
@ -150,8 +149,6 @@ void Pass2(uint2 blockStart, uint3 threadId) {
**uint2 Rmp8x8(uint id)**:将 0~63 的值以 swizzle 顺序映射到 8x8 的正方形内的坐标,用以提高纹理缓存的命中率。
**uint GetFrameCount()**:获取当前总计帧数。必须声明 "USE Dynamic" 才能使用此函数。
**MF{n} MulAdd(MF{m} x, MF{m}x{n} y, MF{n} a)**:等效于 `mul(x, y) + a`,但性能更高,在基于机器学习的效果中非常有用。必须声明 "USE MulAdd" 才能使用此函数。原理参见 [#1049](https://github.com/Blinue/Magpie/pull/1049)。

View file

@ -71,7 +71,7 @@ Magpie 内置了大量效果供组合使用,大部分提供了参数选项以
* Brightness Boost用于提高亮度
* Dilation
* CRT_Geom最流行的 CRT 着色器之一,旨在模拟 Arcade-machine。见 [Emulation General Wiki](https://emulation.gametechwiki.com/index.php/CRT_Geom)
* CRT_Geom最流行的 CRT 着色器之一,旨在模拟 Arcade-machine。此实现不支持模拟隔行扫描。见 [Emulation General Wiki](https://emulation.gametechwiki.com/index.php/CRT_Geom)
* 输出尺寸:取决于缩放选项
* 参数
* Target Gamma
@ -89,8 +89,7 @@ Magpie 内置了大量效果供组合使用,大部分提供了参数选项以
* Sharpness值越大图像越清晰
* Scanline Weight
* Luminance Boost用于提升亮度
* Interlacing是否模拟隔行扫描
* CRT_Hyllian提供锐利清晰的输出并带有轻微的光晕类似于索尼的 BVM 系列显示器
* 输出尺寸:取决于缩放选项
* 参数

View file

@ -25,7 +25,6 @@
//!MAGPIE EFFECT
//!VERSION 4
//!USE Dynamic
//!PARAMETER
@ -148,15 +147,6 @@ float scanlineWeight;
//!STEP 0.01
float lum;
//!PARAMETER
//!LABEL Interlacing
//!DEFAULT 0
//!MIN 0
//!MAX 1
//!STEP 1
int interlace;
//!TEXTURE
Texture2D INPUT;
@ -167,7 +157,6 @@ Texture2D OUTPUT;
//!FILTER POINT
SamplerState sam;
//!PASS 1
//!STYLE PS
//!IN INPUT
@ -184,11 +173,9 @@ SamplerState sam;
#define TEX2D(c) pow(INPUT.SampleLevel(sam, (c), 0), CRTGamma)
// aspect ratio
#define aspect float2(1.0, 0.75)
float intersect(float2 xy, float4 sin_cos_angle) {
float A = dot(xy, xy) + distance * distance;
float B = 2.0 * (radius * (dot(xy, sin_cos_angle.xy) - distance * sin_cos_angle.zw.x * sin_cos_angle.zw.y) - distance * distance);
@ -269,7 +256,7 @@ float4 Pass1(float2 pos) {
float2 TextureSize = float2(sharper * inputSize.x, inputSize.y);
// Resulting X pixel-coordinate of the pixel we're drawing.
float mod_factor = pos.x * outputSize.x;
float2 ilfac = { 1.0, clamp(floor(inputSize.y / (200.0 * (-4 * interlace + 5))), 1.0, 2.0)};
float2 ilfac = { 1.0, clamp(floor(inputSize.y / 1000.0), 1.0, 2.0)};
float2 one = ilfac / TextureSize;
// Here's a helpful diagram to keep in mind while trying to
@ -311,18 +298,14 @@ float4 Pass1(float2 pos) {
float dist = sqrt(dot(cd2, cd2));
float cval = clamp((cdist.x - dist) * cornerSmooth, 0.0, 1.0);
// Of all the pixels that are mapped onto the texel we are
// currently rendering, which pixel are we currently rendering?
float2 ilfloat = float2(0.0, ilfac.y > 1.5 ? fmod(GetFrameCount(), 2.0) : 0.0);
float2 ratio_scale = (xy * TextureSize - 0.5 + ilfloat) / ilfac;
float2 ratio_scale = (xy * TextureSize - 0.5) / ilfac;
float filter = rcp(GetScale().y);
float2 uv_ratio = frac(ratio_scale);
// Snap to the center of the underlying texel.
xy = (floor(ratio_scale) * ilfac + 0.5 - ilfloat) / TextureSize;
xy = (floor(ratio_scale) * ilfac + 0.5) / TextureSize;
// Calculate Lanczos scaling coefficients describing the effect
// of various neighbour texels in a scanline on the current

View file

@ -274,17 +274,19 @@ static uint32_t ResolveUseFlags(std::string_view& block, uint32_t& effectFlags)
std::bitset<2> processed;
for (std::string_view& flag : StrHelper::Split(flags, ',')) {
StrHelper::Trim(flag);
for (std::string_view& token : StrHelper::Split(flags, ',')) {
StrHelper::Trim(token);
std::string flag = StrHelper::ToUpperCase(token);
if (flag == "MulAdd") {
if (flag == "MULADD") {
if (processed[0]) {
return 1;
}
processed[0] = true;
effectFlags |= EffectFlags::UseMulAdd;
} else if (flag == "Dynamic") {
} else if (flag == "_DYNAMIC") {
// Dynamic 不再正式支持,但功能仍然保留
if (processed[1]) {
return 1;
}
@ -292,7 +294,7 @@ static uint32_t ResolveUseFlags(std::string_view& block, uint32_t& effectFlags)
effectFlags |= EffectFlags::UseDynamic;
} else {
Logger::Get().Warn(StrHelper::Concat("使用了未知 USE 标志: ", flag));
Logger::Get().Warn(StrHelper::Concat("使用了未知 USE 标志: ", token));
}
}
@ -307,8 +309,9 @@ static uint32_t ResolveCapabilityFlags(std::string_view& block, uint32_t& effect
std::bitset<1> processed;
for (std::string_view& flag : StrHelper::Split(flags, ',')) {
StrHelper::Trim(flag);
for (std::string_view& token : StrHelper::Split(flags, ',')) {
StrHelper::Trim(token);
std::string flag = StrHelper::ToUpperCase(token);
if (flag == "FP16") {
if (processed[0]) {
@ -321,7 +324,7 @@ static uint32_t ResolveCapabilityFlags(std::string_view& block, uint32_t& effect
effectFlags |= EffectFlags::FP16;
}
} else {
Logger::Get().Warn(StrHelper::Concat("使用了未知 CAPABILITY 标志: ", flag));
Logger::Get().Warn(StrHelper::Concat("使用了未知 CAPABILITY 标志: ", token));
}
}
@ -1320,14 +1323,7 @@ MF4 MulAdd(MF4 x, MF4x4 y, MF4 a) {
)");
}
if (desc.flags & EffectFlags::UseDynamic) {
result.append(R"(uint GetFrameCount() { return __frameCount; }
)");
} else {
result.push_back('\n');
}
result.push_back('\n');
for (std::string_view commonBlock : commonBlocks) {
result.append(commonBlock);