Skip to content

Commit

Permalink
[host] all: don't combine the downsampler rules
Browse files Browse the repository at this point in the history
  • Loading branch information
gnif committed Nov 8, 2023
1 parent 46781ee commit e1b5649
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 19 deletions.
2 changes: 2 additions & 0 deletions common/include/common/option.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ struct Option
char * description;
const char shortopt;
bool preset;
void * opaque;

enum OptionType type;
union
Expand All @@ -67,6 +68,7 @@ struct Option
bool (*validator)(struct Option * opt, const char ** error);
char * (*toString )(struct Option * opt);
StringList (*getValues)(struct Option * opt);
void (*cleanup )(struct Option * opt);

void (*printHelp)(void);

Expand Down
3 changes: 3 additions & 0 deletions common/src/option.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ void option_free(void)
for(int i = 0; i < state.oCount; ++i)
{
struct Option * o = state.options[i];
if (o->cleanup)
o->cleanup(o);

if (o->type == OPTION_TYPE_STRING && o->value.x_string)
free(o->value.x_string);
free(o);
Expand Down
12 changes: 7 additions & 5 deletions host/include/downsample_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

typedef struct
{
const char * module;
unsigned int id;
bool greater;
unsigned int x;
Expand All @@ -33,18 +34,19 @@ typedef struct
}
DownsampleRule;

extern Vector downsampleRules;

bool downsampleParser(struct Option * opt, const char * str);
void downsampleCleanup(struct Option * opt);

DownsampleRule * downsampleRule_match(int x, int y);
DownsampleRule * downsampleRule_match(Vector * rules, int x, int y);

#define DOWNSAMPLE_PARSER(moduleName) \
#define DOWNSAMPLE_PARSER(moduleName, vector) \
{ \
.module = moduleName, \
.name = "downsample", \
.description = "Downsample rules, format: [>](width)x(height):(toWidth)x(toHeight)", \
.type = OPTION_TYPE_STRING, \
.value.x_string = NULL, \
.parser = downsampleParser \
.parser = downsampleParser, \
.cleanup = downsampleCleanup, \
.opaque = (void*)(vector) \
}
7 changes: 5 additions & 2 deletions host/platform/Windows/capture/DXGI/src/pp/downsample.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ typedef struct
}
DownsampleInst;

static Vector downsampleRules = {0};

static void downsample_earlyInit(void)
{
struct Option options[] =
{
DOWNSAMPLE_PARSER("dxgi"),
DOWNSAMPLE_PARSER("dxgi", &downsampleRules),
{0}
};

Expand Down Expand Up @@ -99,7 +100,9 @@ static bool downsample_configure(void * opaque,

if (!this.pshader)
{
DownsampleRule * rule = downsampleRule_match(*width, *height);
DownsampleRule * rule = downsampleRule_match(&downsampleRules,
*width, *height);

if (!rule || (rule->targetX == *width && rule->targetY == *height))
{
this.disabled = true;
Expand Down
8 changes: 6 additions & 2 deletions host/platform/Windows/capture/NVFBC/src/nvfbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,13 @@ static const char * nvfbc_getName(void)
return "NVFBC";
};

static Vector downsampleRules = {0};

static void nvfbc_initOptions(void)
{
struct Option options[] =
{
DOWNSAMPLE_PARSER("nvfbc"),
DOWNSAMPLE_PARSER("nvfbc", &downsampleRules),
{
.module = "nvfbc",
.name = "decoupleCursor",
Expand Down Expand Up @@ -202,12 +204,14 @@ static bool nvfbc_create(

static void updateScale(void)
{
DownsampleRule * rule = downsampleRule_match(this->width, this->height);
DownsampleRule * rule = downsampleRule_match(&downsampleRules,
this->width, this->height);
if (rule)
{
this->scale = true;
this->targetWidth = rule->targetX;
this->targetHeight = rule->targetY;
DEBUG_INFO("Downsampling to %dx%d", this->targetWidth, this->targetHeight);
return;
}

Expand Down
30 changes: 20 additions & 10 deletions host/src/downsample_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ bool downsampleParser(struct Option * opt, const char * str)

opt->value.x_string = strdup(str);

if (downsampleRules.data)
vector_destroy(&downsampleRules);
Vector * downsampleRules = (Vector *)opt->opaque;
if (downsampleRules->data)
vector_destroy(downsampleRules);

if (!vector_create(&downsampleRules, sizeof(DownsampleRule), 10))
if (!vector_create(downsampleRules, sizeof(DownsampleRule), 10))
{
DEBUG_ERROR("Failed to allocate ram");
return false;
Expand All @@ -53,6 +54,7 @@ bool downsampleParser(struct Option * opt, const char * str)
++token;
}

rule.module = opt->module;
if (sscanf(token, "%ux%u:%ux%u",
&rule.x,
&rule.y,
Expand All @@ -66,7 +68,9 @@ bool downsampleParser(struct Option * opt, const char * str)
rule.id = count++;

DEBUG_INFO(
"Rule %u: %ux%u IF X %s %4u %s Y %s %4u",
"%s:%s rule %u: %ux%u IF X %s %4u %s Y %s %4u",
opt->module,
opt->name,
rule.id,
rule.targetX,
rule.targetY,
Expand All @@ -76,7 +80,7 @@ bool downsampleParser(struct Option * opt, const char * str)
rule.greater ? "> " : "==",
rule.y
);
vector_push(&downsampleRules, &rule);
vector_push(downsampleRules, &rule);

token = strtok(NULL, ",");
}
Expand All @@ -85,14 +89,20 @@ bool downsampleParser(struct Option * opt, const char * str)
return true;
}

DownsampleRule * downsampleRule_match(int x, int y)
void downsampleCleanup(struct Option * opt)
{
Vector * downsampleRules = (Vector *)opt->opaque;
if (downsampleRules->data)
vector_destroy(downsampleRules);
}

DownsampleRule * downsampleRule_match(Vector * rules, int x, int y)
{
DownsampleRule * rule, * match = NULL;
vector_forEachRef(rule, &downsampleRules)
vector_forEachRef(rule, rules)
{
if (
( rule->greater && (x > rule->x || y > rule->y)) ||
(!rule->greater && (x == rule->x && y == rule->y)))
if (( rule->greater && (x > rule->x || y > rule->y)) ||
(!rule->greater && (x == rule->x && y == rule->y)))
{
match = rule;
}
Expand Down

0 comments on commit e1b5649

Please sign in to comment.