[host] d12: make effects fully self-contained

This commit is contained in:
Geoffrey McRae 2024-02-28 16:05:56 +11:00
parent 2d41cda640
commit 97d91a32c8
5 changed files with 135 additions and 75 deletions

View File

@ -32,7 +32,7 @@
#include "com_ref.h" #include "com_ref.h"
#include "backend.h" #include "backend.h"
#include "effect.h" #include "effects.h"
#include "command_group.h" #include "command_group.h"
#include <dxgi.h> #include <dxgi.h>
@ -80,8 +80,6 @@ struct D12Interface
// options // options
bool debug; bool debug;
bool trackDamage; bool trackDamage;
bool allowRGB24;
bool hdr16to10;
unsigned frameBufferCount; unsigned frameBufferCount;
// must be last // must be last
@ -152,22 +150,6 @@ static void d12_initOptions(void)
.type = OPTION_TYPE_BOOL, .type = OPTION_TYPE_BOOL,
.value.x_bool = true .value.x_bool = true
}, },
{
.module = "d12",
.name = "allowRGB24",
.description =
"Losslessly pack 32-bit RGBA8 into 24-bit RGB (saves bandwidth)",
.type = OPTION_TYPE_BOOL,
.value.x_bool = false
},
{
.module = "d12",
.name = "HDR16to10",
.description =
"Convert HDR16/8bpp to HDR10/4bpp (saves bandwidth)",
.type = OPTION_TYPE_BOOL,
.value.x_bool = true
},
{ {
.module = "d12", .module = "d12",
.name = "debug", .name = "debug",
@ -179,6 +161,9 @@ static void d12_initOptions(void)
}; };
option_register(options); option_register(options);
for(const D12Effect ** effect = D12Effects; *effect; ++effect)
d12_effectInitOptions(*effect);
} }
static bool d12_create( static bool d12_create(
@ -196,14 +181,10 @@ static bool d12_create(
this->debug = option_get_bool("d12", "debug" ); this->debug = option_get_bool("d12", "debug" );
this->trackDamage = option_get_bool("d12", "trackDamage" ); this->trackDamage = option_get_bool("d12", "trackDamage" );
this->allowRGB24 = option_get_bool("d12", "allowRGB24" );
this->hdr16to10 = option_get_bool("d12", "HDR16to10" );
DEBUG_INFO( DEBUG_INFO(
"debug:%d trackDamage:%d allowRGB24:%d", "debug:%d trackDamage:%d",
this->debug, this->debug, this->trackDamage);
this->trackDamage,
this->allowRGB24);
this->d3d12 = LoadLibrary("d3d12.dll"); this->d3d12 = LoadLibrary("d3d12.dll");
if (!this->d3d12) if (!this->d3d12)
@ -385,24 +366,25 @@ retryCreateCommandQueue:
// create the vector of effects // create the vector of effects
vector_create(&this->effects, sizeof(D12Effect *), 0); vector_create(&this->effects, sizeof(D12Effect *), 0);
D12Effect * effect;
if (this->hdr16to10) // create all the effects
for(const D12Effect ** effect = D12Effects; *effect; ++effect)
{ {
if (!d12_effectCreate(&D12Effect_HDR16to10, &effect, *device, D12Effect * instance;
&this->displayPathInfo)) switch(d12_effectCreate(*effect, &instance, *device, &this->displayPathInfo))
goto exit; {
vector_push(&this->effects, &effect); case D12_EFFECT_STATUS_OK:
} DEBUG_INFO("D12 Created Effect: %s", (*effect)->name);
vector_push(&this->effects, &instance);
break;
/* if RGB24 conversion is enabled add the effect to the list case D12_EFFECT_STATUS_BYPASS:
NOTE: THIS MUST BE THE LAST EFFECT */ continue;
if (this->allowRGB24)
{ case D12_EFFECT_STATUS_ERROR:
if (!d12_effectCreate(&D12Effect_RGB24, &effect, *device, DEBUG_ERROR("Failed to create effect: %s", (*effect)->name);
&this->displayPathInfo)) goto exit;
goto exit; }
vector_push(&this->effects, &effect);
} }
comRef_toGlobal(this->factory , factory ); comRef_toGlobal(this->factory , factory );
@ -545,6 +527,7 @@ static CaptureResult d12_waitFrame(unsigned frameBufferIndex,
this->effectsActive = true; this->effectsActive = true;
curFormat = dstFormat; curFormat = dstFormat;
effect->enabled = true; effect->enabled = true;
DEBUG_INFO("D12 Effect Active: %s", effect->name);
break; break;
case D12_EFFECT_STATUS_ERROR: case D12_EFFECT_STATUS_ERROR:

View File

@ -42,7 +42,9 @@ struct D12Effect
bool enabled; bool enabled;
bool (*create)(D12Effect ** instance, ID3D12Device3 * device, void (*initOptions)(void);
D12EffectStatus (*create)(D12Effect ** instance, ID3D12Device3 * device,
const DISPLAYCONFIG_PATH_INFO * displayPathInfo); const DISPLAYCONFIG_PATH_INFO * displayPathInfo);
void (*free)(D12Effect ** instance); void (*free)(D12Effect ** instance);
@ -61,14 +63,18 @@ struct D12Effect
unsigned * nbDirtyRects); unsigned * nbDirtyRects);
}; };
static inline bool d12_effectCreate(const D12Effect * effect, static inline void d12_effectInitOptions(const D12Effect * effect)
{ if (effect->initOptions) effect->initOptions(); }
static inline D12EffectStatus d12_effectCreate(const D12Effect * effect,
D12Effect ** instance, ID3D12Device3 * device, D12Effect ** instance, ID3D12Device3 * device,
const DISPLAYCONFIG_PATH_INFO * displayPathInfo) const DISPLAYCONFIG_PATH_INFO * displayPathInfo)
{ {
if (!effect->create(instance, device, displayPathInfo)) *instance = NULL;
return false; D12EffectStatus status = effect->create(instance, device, displayPathInfo);
memcpy(*instance, effect, sizeof(*effect)); if (status == D12_EFFECT_STATUS_OK)
return true; memcpy(*instance, effect, sizeof(*effect));
return status;
} }
static inline void d12_effectFree(D12Effect ** instance) static inline void d12_effectFree(D12Effect ** instance)
@ -93,9 +99,4 @@ static inline ID3D12Resource * d12_effectRun(D12Effect * effect,
{ return effect->run(effect, device, commandList, src, { return effect->run(effect, device, commandList, src,
dirtyRects, nbDirtyRects); } dirtyRects, nbDirtyRects); }
// effect defines
extern const D12Effect D12Effect_RGB24;
extern const D12Effect D12Effect_HDR16to10;
#endif #endif

View File

@ -8,6 +8,7 @@
#include "common/windebug.h" #include "common/windebug.h"
#include "common/array.h" #include "common/array.h"
#include "common/display.h" #include "common/display.h"
#include "common/option.h"
#include <d3dcompiler.h> #include <d3dcompiler.h>
@ -34,17 +35,38 @@ HDR16to10Inst;
#define THREADS 8 #define THREADS 8
static bool d12_effect_hdr16to10Create(D12Effect ** instance, static void d12_effect_hdr16to10InitOptions(void)
{
struct Option options[] =
{
{
.module = "d12",
.name = "HDR16to10",
.description =
"Convert HDR16/8bpp to HDR10/4bpp (saves bandwidth)",
.type = OPTION_TYPE_BOOL,
.value.x_bool = true
},
{0}
};
option_register(options);
}
static D12EffectStatus d12_effect_hdr16to10Create(D12Effect ** instance,
ID3D12Device3 * device, const DISPLAYCONFIG_PATH_INFO * displayPathInfo) ID3D12Device3 * device, const DISPLAYCONFIG_PATH_INFO * displayPathInfo)
{ {
if (!option_get_bool("d12", "HDR16to10"))
return D12_EFFECT_STATUS_BYPASS;
HDR16to10Inst * this = calloc(1, sizeof(*this)); HDR16to10Inst * this = calloc(1, sizeof(*this));
if (!this) if (!this)
{ {
DEBUG_ERROR("out of memory"); DEBUG_ERROR("out of memory");
return false; return D12_EFFECT_STATUS_ERROR;
} }
bool result = false; bool result = D12_EFFECT_STATUS_ERROR;
HRESULT hr; HRESULT hr;
comRef_scopePush(10); comRef_scopePush(10);
@ -241,12 +263,11 @@ static bool d12_effect_hdr16to10Create(D12Effect ** instance,
comRef_toGlobal(this->descHeap , descHeap ); comRef_toGlobal(this->descHeap , descHeap );
comRef_toGlobal(this->constBuffer , constBuffer ); comRef_toGlobal(this->constBuffer , constBuffer );
result = true; result = D12_EFFECT_STATUS_OK;
*instance = &this->base;
exit: exit:
if (result) if (!*instance)
*instance = &this->base;
else
free(this); free(this);
comRef_scopePop(); comRef_scopePop();
@ -446,9 +467,10 @@ static ID3D12Resource * d12_effect_hdr16to10Run(D12Effect * effect,
const D12Effect D12Effect_HDR16to10 = const D12Effect D12Effect_HDR16to10 =
{ {
.name = "HDR16to10", .name = "HDR16to10",
.create = d12_effect_hdr16to10Create, .initOptions = d12_effect_hdr16to10InitOptions,
.free = d12_effect_hdr16to10Free, .create = d12_effect_hdr16to10Create,
.setFormat = d12_effect_hdr16to10SetFormat, .free = d12_effect_hdr16to10Free,
.run = d12_effect_hdr16to10Run .setFormat = d12_effect_hdr16to10SetFormat,
.run = d12_effect_hdr16to10Run
}; };

View File

@ -7,6 +7,7 @@
#include "common/debug.h" #include "common/debug.h"
#include "common/windebug.h" #include "common/windebug.h"
#include "common/array.h" #include "common/array.h"
#include "common/option.h"
#include <d3dcompiler.h> #include <d3dcompiler.h>
@ -25,17 +26,38 @@ TestInstance;
#define THREADS 8 #define THREADS 8
static bool d12_effect_rgb24Create(D12Effect ** instance, ID3D12Device3 * device, static void d12_effect_rgb24InitOptions(void)
{
struct Option options[] =
{
{
.module = "d12",
.name = "allowRGB24",
.description =
"Losslessly pack 32-bit RGBA8 into 24-bit RGB (saves bandwidth)",
.type = OPTION_TYPE_BOOL,
.value.x_bool = false
},
{0}
};
option_register(options);
}
static D12EffectStatus d12_effect_rgb24Create(D12Effect ** instance, ID3D12Device3 * device,
const DISPLAYCONFIG_PATH_INFO * displayPathInfo) const DISPLAYCONFIG_PATH_INFO * displayPathInfo)
{ {
if (!option_get_bool("d12", "allowRGB24"))
return D12_EFFECT_STATUS_BYPASS;
TestInstance * this = calloc(1, sizeof(*this)); TestInstance * this = calloc(1, sizeof(*this));
if (!this) if (!this)
{ {
DEBUG_ERROR("out of memory"); DEBUG_ERROR("out of memory");
return false; return D12_EFFECT_STATUS_ERROR;
} }
bool result = false; D12EffectStatus result = D12_EFFECT_STATUS_ERROR;
HRESULT hr; HRESULT hr;
comRef_scopePush(10); comRef_scopePush(10);
@ -195,12 +217,11 @@ static bool d12_effect_rgb24Create(D12Effect ** instance, ID3D12Device3 * device
comRef_toGlobal(this->pso , pso ); comRef_toGlobal(this->pso , pso );
comRef_toGlobal(this->descHeap , descHeap ); comRef_toGlobal(this->descHeap , descHeap );
result = true; result = D12_EFFECT_STATUS_OK;
*instance = &this->base;
exit: exit:
if (result) if (!*instance)
*instance = &this->base;
else
free(this); free(this);
comRef_scopePop(); comRef_scopePop();
@ -381,9 +402,10 @@ static ID3D12Resource * d12_effect_rgb24Run(D12Effect * effect,
const D12Effect D12Effect_RGB24 = const D12Effect D12Effect_RGB24 =
{ {
.name = "RGB24", .name = "RGB24",
.create = d12_effect_rgb24Create, .initOptions = d12_effect_rgb24InitOptions,
.free = d12_effect_rgb24Free, .create = d12_effect_rgb24Create,
.setFormat = d12_effect_rgb24SetFormat, .free = d12_effect_rgb24Free,
.run = d12_effect_rgb24Run .setFormat = d12_effect_rgb24SetFormat,
.run = d12_effect_rgb24Run
}; };

View File

@ -0,0 +1,32 @@
/**
* Looking Glass
* Copyright © 2017-2024 The Looking Glass Authors
* https://looking-glass.io
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 59
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "effect.h"
extern const D12Effect D12Effect_HDR16to10;
extern const D12Effect D12Effect_RGB24;
static const D12Effect * D12Effects[] =
{
&D12Effect_HDR16to10,
&D12Effect_RGB24, // this MUST be last
NULL
};