[host] all: make the downsample rule matching common

This commit is contained in:
Geoffrey McRae 2023-11-07 10:19:24 +11:00
parent 6c7f3c4197
commit 30c577beeb
6 changed files with 37 additions and 120 deletions

View File

@ -37,6 +37,8 @@ extern Vector downsampleRules;
bool downsampleParser(struct Option * opt, const char * str);
DownsampleRule * downsampleRule_match(int x, int y);
#define DOWNSAMPLE_PARSER(moduleName) \
{ \
.module = moduleName, \

View File

@ -91,14 +91,6 @@ static bool d3d12_create(struct DXGIInterface * intf)
if (!d3d12)
return false;
if (dxgi->downsampleLevel > 0)
{
DEBUG_WARN("The D3D12 backend does not support downsampling yet");
dxgi->downsampleLevel = 0;
dxgi->outputWidth = dxgi->width;
dxgi->outputHeight = dxgi->height;
}
if (dxgi->debug)
{
D3D12GetDebugInterface_t D3D12GetDebugInterface = (D3D12GetDebugInterface_t)

View File

@ -20,6 +20,7 @@
#include "interface/capture.h"
#include "interface/platform.h"
#include "downsample_parser.h"
#include "common/array.h"
#include "common/debug.h"
#include "common/windebug.h"
@ -65,18 +66,6 @@ typedef struct
}
PostProcessInstance;
typedef struct
{
unsigned int id;
bool greater;
unsigned int x;
unsigned int y;
unsigned int level;
}
DownsampleRule;
static Vector downsampleRules = {0};
// locals
static struct DXGIInterface * this = NULL;
@ -112,58 +101,6 @@ static const char * dxgi_getName(void)
return name;
}
static bool downsampleOptParser(struct Option * opt, const char * str)
{
if (!str)
return false;
opt->value.x_string = strdup(str);
if (downsampleRules.data)
vector_destroy(&downsampleRules);
if (!vector_create(&downsampleRules, sizeof(DownsampleRule), 10))
{
DEBUG_ERROR("Failed to allocate ram");
return false;
}
char * tmp = strdup(str);
char * token = strtok(tmp, ",");
int count = 0;
while(token)
{
DownsampleRule rule = {0};
if (token[0] == '>')
{
rule.greater = true;
++token;
}
if (sscanf(token, "%ux%u:%u", &rule.x, &rule.y, &rule.level) != 3)
return false;
rule.id = count++;
DEBUG_INFO(
"Rule %u: %u%% IF X %s %4u %s Y %s %4u",
rule.id,
100 / (1 << rule.level),
rule.greater ? "> " : "==",
rule.x,
rule.greater ? "OR " : "AND",
rule.greater ? "> " : "==",
rule.y
);
vector_push(&downsampleRules, &rule);
token = strtok(NULL, ",");
}
free(tmp);
return true;
}
static void dxgi_initOptions(void)
{
struct Option options[] =
@ -182,14 +119,7 @@ static void dxgi_initOptions(void)
.type = OPTION_TYPE_STRING,
.value.x_string = NULL
},
{
.module = "dxgi",
.name = "downsample", //dxgi:downsample=1920x1200:1,
.description = "Downsample conditions and levels, format: [>](width)x(height):level",
.type = OPTION_TYPE_STRING,
.value.x_string = NULL,
.parser = downsampleOptParser
},
DOWNSAMPLE_PARSER("dxgi"),
{
.module = "dxgi",
.name = "maxTextures",
@ -761,27 +691,13 @@ static bool dxgi_init(void)
goto fail;
}
this->downsampleLevel = 0;
this->outputWidth = this->width;
this->outputHeight = this->height;
DownsampleRule * rule, * match = NULL;
vector_forEachRef(rule, &downsampleRules)
this->outputWidth = this->width;
this->outputHeight = this->height;
DownsampleRule * rule = downsampleRule_match(this->width, this->height);
if (rule)
{
if (
( rule->greater && (this->width > rule->x || this->height > rule->y)) ||
(!rule->greater && (this->width == rule->x && this->height == rule->y)))
{
match = rule;
}
}
if (match)
{
DEBUG_INFO("Matched downsample rule %d", rule->id);
this->downsampleLevel = match->level;
this->outputWidth >>= match->level;
this->outputHeight >>= match->level;
this->outputWidth = rule->targetX;
this->outputHeight = rule->targetY;
}
DEBUG_INFO("Request Size : %u x %u", this->outputWidth, this->outputHeight);
@ -940,10 +856,10 @@ static void rectToFrameDamageRect(RECT * src, FrameDamageRect * dst)
{
*dst = (FrameDamageRect)
{
.x = src->left >> this->downsampleLevel,
.y = src->top >> this->downsampleLevel,
.width = (src->right - src->left) >> this->downsampleLevel,
.height = (src->bottom - src->top) >> this->downsampleLevel
.x = src->left ,
.y = src->top ,
.width = (src->right - src->left),
.height = (src->bottom - src->top)
};
}

View File

@ -105,7 +105,6 @@ struct DXGIInterface
unsigned int formatVer;
unsigned int width , outputWidth , dataWidth;
unsigned int height, outputHeight, dataHeight;
unsigned int downsampleLevel;
unsigned int pitch;
unsigned int stride;
unsigned int padding;

View File

@ -191,23 +191,12 @@ static bool nvfbc_create(
static void updateScale(void)
{
DownsampleRule * rule, * match = NULL;
vector_forEachRef(rule, &downsampleRules)
DownsampleRule * rule = downsampleRule_match(this->width, this->height);
if (rule)
{
if (
( rule->greater && (this->width > rule->x || this->height > rule->y)) ||
(!rule->greater && (this->width == rule->x && this->height == rule->y)))
{
match = rule;
}
}
if (match)
{
DEBUG_INFO("Matched downsample rule %d", rule->id);
this->scale = true;
this->targetWidth = match->targetX;
this->targetHeight = match->targetY;
this->targetWidth = rule->targetX;
this->targetHeight = rule->targetY;
return;
}

View File

@ -84,3 +84,22 @@ bool downsampleParser(struct Option * opt, const char * str)
return true;
}
DownsampleRule * downsampleRule_match(int x, int y)
{
DownsampleRule * rule, * match = NULL;
vector_forEachRef(rule, &downsampleRules)
{
if (
( rule->greater && (x > rule->x || y > rule->y)) ||
(!rule->greater && (x == rule->x && y == rule->y)))
{
match = rule;
}
}
if (match)
DEBUG_INFO("Matched downsample rule %d", rule->id);
return match;
}