Skip to content

Commit

Permalink
FidelityFX CLI v1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
rys committed Aug 31, 2021
1 parent a2b2040 commit 8b8775d
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 17 deletions.
95 changes: 88 additions & 7 deletions FidelityFX_CLI.cpp
Expand Up @@ -59,7 +59,7 @@ namespace RCAS_Linear1

static const wchar_t* const APP_NAME = L"FidelityFX-CLI";
static const wchar_t* const EXE_NAME = L"FidelityFX_CLI";
static const wchar_t* const APP_VERSION = L"1.0.2";
static const wchar_t* const APP_VERSION = L"1.0.3";

enum class InterpolationMode
{
Expand Down Expand Up @@ -122,6 +122,16 @@ static inline bool InterpolationModeNeedsGpu(InterpolationMode mode)
#define CHECK_BOOL(expr) do { if(!(expr)) throw std::runtime_error(__FILE__ "(" LINE_STRING "): !( " #expr " )"); } while(false)
#define CHECK_HR(expr) do { if(FAILED(expr)) throw std::runtime_error(__FILE__ "(" LINE_STRING "): FAILED( " #expr " )"); } while(false)

struct vec2
{
float x, y;
vec2() { }
vec2(float x_, float y_) : x(x_), y(y_) { }

bool operator==(const vec2& rhs) const { return x == rhs.x && y == rhs.y; }
bool operator!=(const vec2& rhs) const { return x != rhs.x || y != rhs.y; }
};

struct uvec2
{
uint32_t x, y;
Expand Down Expand Up @@ -164,10 +174,19 @@ struct LaunchParameters
bool fp16 = false;
float sharpness = FLT_MAX;
uvec2 dstSize = uvec2(UINT32_MAX, UINT32_MAX);
vec2 dstSizePercent = vec2(0.f, 0.f);
std::vector<FileToProcess> filesToProcess;

bool HasScaling() const { return dstSize.x != UINT32_MAX || dstSize.y != UINT32_MAX; }
bool HasScaling() const
{
return dstSize.x != UINT32_MAX || dstSize.y != UINT32_MAX ||
dstSizePercent.x != 0.f || dstSizePercent.y != 0.f;
}
void ParseCommandLine(int argCount, const wchar_t* const* args);

private:
static void ParseScale(uint32_t& outScale, float& outScalePercent, const wchar_t* arg);
static bool ParseQualityMode(vec2& outScalePercent, const wchar_t* arg);
};

class CoInitializeObj
Expand Down Expand Up @@ -275,6 +294,13 @@ void LaunchParameters::PrintCommandLineSyntax()
wprintf(
L"Options:\n"
L"-Scale <DstWidth> <DstHeight>\n"
L" Width, Height can be:\n"
L" Number: -Scale 3840 2160\n"
L" Scale factor: -Scale 2x 2x\n"
L" Percent: -Scale 150%% 150%%\n"
L"-QualityMode <Quality>\n"
L" Specify instead of -Scale to use one of the predefined scaling factors.\n"
L" Quality can be: UltraQuality (1.3x), Quality (1.5x), Balanced (1.7x), Performance (2x)\n"
L"-Mode <Mode>\n"
L" Modes from FSR package:\n"
L" EASU - Edge Adaptive Spatial Upsampling (default) aliases: FSR, FSR1\n"
Expand Down Expand Up @@ -311,10 +337,15 @@ void LaunchParameters::ParseCommandLine(int argCount, const wchar_t* const* args
throw std::runtime_error("Invalid Mode.");
}
}
else if(wcscmp(args[i], L"-QualityMode") == 0 && i + 1 < argCount)
{
if(!ParseQualityMode(this->dstSizePercent, args[++i]))
throw std::runtime_error("Invalid -QualityMode argument.");
}
else if(wcscmp(args[i], L"-Scale") == 0 && i + 2 < argCount)
{
this->dstSize.x = (uint32_t)_wtoi(args[++i]);
this->dstSize.y = (uint32_t)_wtoi(args[++i]);
ParseScale(this->dstSize.x, this->dstSizePercent.x, args[++i]);
ParseScale(this->dstSize.y, this->dstSizePercent.y, args[++i]);
}
else if(wcscmp(args[i], L"-Linear") == 0)
{
Expand Down Expand Up @@ -368,6 +399,39 @@ void LaunchParameters::ParseCommandLine(int argCount, const wchar_t* const* args
}
}

void LaunchParameters::ParseScale(uint32_t& outScale, float& outScalePercent, const wchar_t* arg)
{
const size_t argLen = wcslen(arg);
if(argLen == 0)
return;
if(arg[argLen - 1] == 'x')
{
outScalePercent = (float)_wtof(arg);
}
else if(arg[argLen - 1] == '%')
{
outScalePercent = (float)_wtof(arg) * 0.01f;
}
else
outScale = (uint32_t)_wtoi(arg);
}

bool LaunchParameters::ParseQualityMode(vec2& outScalePercent, const wchar_t* arg)
{
if(_wcsicmp(arg, L"UltraQuality") == 0)
outScalePercent = vec2(1.3f, 1.3f);
else if(_wcsicmp(arg, L"Quality") == 0)
outScalePercent = vec2(1.5f, 1.5f);
else if(_wcsicmp(arg, L"Balanced") == 0)
outScalePercent = vec2(1.7f, 1.7f);
else if(_wcsicmp(arg, L"Performance") == 0)
outScalePercent = vec2(2.0f, 2.0f);
else
return false;

return true;
}

GpuResources::GpuResources(const LaunchParameters& params)
{
D3D_FEATURE_LEVEL featureLevels[] = { D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0 };
Expand Down Expand Up @@ -598,9 +662,26 @@ void Application::ProcessFile(const FileToProcess& fileToProcess) const
uvec2 srcSize = uvec2(0, 0);
CHECK_HR( frameDecode->GetSize(&srcSize.x, &srcSize.y) );

const uvec2 dstSize = uvec2(
m_Params.dstSize.x != UINT32_MAX ? m_Params.dstSize.x : srcSize.x,
m_Params.dstSize.y != UINT32_MAX ? m_Params.dstSize.y : srcSize.y);
uvec2 dstSize = srcSize;

if(m_Params.dstSize.x != UINT32_MAX)
dstSize.x = m_Params.dstSize.x;
else if(m_Params.dstSizePercent.x != 0.f)
dstSize.x = (uint32_t)(srcSize.x * m_Params.dstSizePercent.x + 0.5f);
if(m_Params.dstSize.y != UINT32_MAX)
dstSize.y = m_Params.dstSize.y;
else if(m_Params.dstSizePercent.y != 0.f)
dstSize.y = (uint32_t)(srcSize.y * m_Params.dstSizePercent.y + 0.5f);

if(dstSize == srcSize)
wprintf(L"Image size: %u x %u.\n", srcSize.x, srcSize.y);
else
{
wprintf(L"Image size: %u x %u scaled to %u x %u.\n", srcSize.x, srcSize.y, dstSize.x, dstSize.y);
if(dstSize.x > srcSize.x * 2 || dstSize.y > srcSize.y * 2)
wprintf(L"WARNING: SCALING RATIO HIGHER THAN 2X IN EITHER DIRECTION IS UNSUPPORTED!\n");

}

if(InterpolationModeNeedsGpu(m_Params.interpolationMode))
{
Expand Down
30 changes: 20 additions & 10 deletions README.md
Expand Up @@ -17,25 +17,36 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

## Overview
## Introduction

Simple command line tool that processes image files using the FidelityFX Super Resolution (FSR) or Contrast Adaptive Sharpening (CAS) shader systems.
FidelityFX Super Resolution (FSR) is an open source, high-quality solution for producing high resolution frames from lower resolution inputs. For more information, see dedciated page on [amd.com](https://www.amd.com/en/technologies/radeon-software-fidelityfx-super-resolution), [GPUOpen.com](https://gpuopen.com/fsr), [GitHub](https://github.com/GPUOpen-Effects/FidelityFX-FSR).

```
FidelityFX-CLI 1.0.2
Contrast Adaptive Sharpening (CAS) is a low overhead adaptive sharpening algorithm with optional up-sampling. For more information, see dedciated page on [amd.com](https://www.amd.com/en/technologies/radeon-software-fidelityfx), [GPUOpen.com](https://gpuopen.com/fidelityfx-cas/), [GitHub](https://github.com/GPUOpen-Effects/FidelityFX-CAS).

This project is a small command-line Windows tool that processes image files using the FSR or CAS algorithm. It allows to test how the shaders would affect screenshots from your game. Releases contain executable binary while this respository contains source code.

## Command line syntax

```
FidelityFX-CLI 1.0.3
Command line syntax:
FidelityFX_CLI.exe [Options] <SrcFile1> <DstFile1> <SrcFile2> <DstFile2> ...
Options:
-Scale <DstWidth> <DstHeight>
Width, Height can be:
Number: -Scale 3840 2160
Scale factor: -Scale 2x 2x
Percent: -Scale 150% 150%
-QualityMode <Quality>
Specify instead of -Scale to use one of the predefined scaling factors.
Quality can be: UltraQuality (1.3x), Quality (1.5x), Balanced (1.7x), Performance (2x)
-Mode <Mode>
Modes from FSR package:
EASU - Edge Adaptive Spatial Upsampling (default) aliases: FSR, FSR1
RCAS - Robust Contrast Adaptive Sharpening (doesn't support Scale)
Modes from CAS package:
CAS - Contrast Adaptive Sharpening
Modes from Windows Imaging Component (WICBitmapInterpolationMode):
Modes from Windows Imaging Component:
NearestNeighbor, Linear, Cubic, HighQualityCubic, Fant
-Sharpness <Value>
-Mode CAS: range from 0.0 (default) to 1.0 (maximum extra sharpness)
Expand All @@ -47,10 +58,9 @@ Options:
If not set (default), treats input and output image as sRGB.
If set, treats input and output image as linear.
Works only when -FP16 is not specified.
Supported input formats: BMP, PNG, ICO, JPG, TIF, GIF
Supported formats: BMP, PNG, ICO, JPG, TIF, GIF
```

Written in C++ using Visual Studio 2019. No external dependencies other than the WIC API and Direct3D 11. Image file formats are handled using the [Windows Imaging Component (WIC)](https://docs.microsoft.com/en-us/windows/win32/wic/-wic-about-windows-imaging-codec) framework. Shaders are compiled to H files (with a little help from the [Fx Batch Compiler](https://github.com/sawickiap/FxBatchCompiler) tool) and bundled with the source code to build the executable.

## Additional information

Written in C++ using Visual Studio 2019 and Cmake. No external dependencies other than the Windows API and Direct3D 11. Image file formats are handled using the [Windows Imaging Component (WIC)](https://docs.microsoft.com/en-us/windows/win32/wic/-wic-about-windows-imaging-codec) framework (part of Windows API). Shaders are compiled to H files (with a little help from the [Fx Batch Compiler](https://github.com/sawickiap/FxBatchCompiler) tool) and bundled with the source code to build the executable.

0 comments on commit 8b8775d

Please sign in to comment.