mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-12-22 13:33:40 +00:00
[host] d12: make effects fully self-contained
This commit is contained in:
parent
2d41cda640
commit
97d91a32c8
@ -32,7 +32,7 @@
|
||||
#include "com_ref.h"
|
||||
|
||||
#include "backend.h"
|
||||
#include "effect.h"
|
||||
#include "effects.h"
|
||||
#include "command_group.h"
|
||||
|
||||
#include <dxgi.h>
|
||||
@ -80,8 +80,6 @@ struct D12Interface
|
||||
// options
|
||||
bool debug;
|
||||
bool trackDamage;
|
||||
bool allowRGB24;
|
||||
bool hdr16to10;
|
||||
|
||||
unsigned frameBufferCount;
|
||||
// must be last
|
||||
@ -152,22 +150,6 @@ static void d12_initOptions(void)
|
||||
.type = OPTION_TYPE_BOOL,
|
||||
.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",
|
||||
.name = "debug",
|
||||
@ -179,6 +161,9 @@ static void d12_initOptions(void)
|
||||
};
|
||||
|
||||
option_register(options);
|
||||
|
||||
for(const D12Effect ** effect = D12Effects; *effect; ++effect)
|
||||
d12_effectInitOptions(*effect);
|
||||
}
|
||||
|
||||
static bool d12_create(
|
||||
@ -196,14 +181,10 @@ static bool d12_create(
|
||||
|
||||
this->debug = option_get_bool("d12", "debug" );
|
||||
this->trackDamage = option_get_bool("d12", "trackDamage" );
|
||||
this->allowRGB24 = option_get_bool("d12", "allowRGB24" );
|
||||
this->hdr16to10 = option_get_bool("d12", "HDR16to10" );
|
||||
|
||||
DEBUG_INFO(
|
||||
"debug:%d trackDamage:%d allowRGB24:%d",
|
||||
this->debug,
|
||||
this->trackDamage,
|
||||
this->allowRGB24);
|
||||
"debug:%d trackDamage:%d",
|
||||
this->debug, this->trackDamage);
|
||||
|
||||
this->d3d12 = LoadLibrary("d3d12.dll");
|
||||
if (!this->d3d12)
|
||||
@ -385,24 +366,25 @@ retryCreateCommandQueue:
|
||||
|
||||
// create the vector of effects
|
||||
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,
|
||||
&this->displayPathInfo))
|
||||
goto exit;
|
||||
vector_push(&this->effects, &effect);
|
||||
}
|
||||
D12Effect * instance;
|
||||
switch(d12_effectCreate(*effect, &instance, *device, &this->displayPathInfo))
|
||||
{
|
||||
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
|
||||
NOTE: THIS MUST BE THE LAST EFFECT */
|
||||
if (this->allowRGB24)
|
||||
{
|
||||
if (!d12_effectCreate(&D12Effect_RGB24, &effect, *device,
|
||||
&this->displayPathInfo))
|
||||
goto exit;
|
||||
vector_push(&this->effects, &effect);
|
||||
case D12_EFFECT_STATUS_BYPASS:
|
||||
continue;
|
||||
|
||||
case D12_EFFECT_STATUS_ERROR:
|
||||
DEBUG_ERROR("Failed to create effect: %s", (*effect)->name);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
comRef_toGlobal(this->factory , factory );
|
||||
@ -545,6 +527,7 @@ static CaptureResult d12_waitFrame(unsigned frameBufferIndex,
|
||||
this->effectsActive = true;
|
||||
curFormat = dstFormat;
|
||||
effect->enabled = true;
|
||||
DEBUG_INFO("D12 Effect Active: %s", effect->name);
|
||||
break;
|
||||
|
||||
case D12_EFFECT_STATUS_ERROR:
|
||||
|
@ -42,7 +42,9 @@ struct D12Effect
|
||||
|
||||
bool enabled;
|
||||
|
||||
bool (*create)(D12Effect ** instance, ID3D12Device3 * device,
|
||||
void (*initOptions)(void);
|
||||
|
||||
D12EffectStatus (*create)(D12Effect ** instance, ID3D12Device3 * device,
|
||||
const DISPLAYCONFIG_PATH_INFO * displayPathInfo);
|
||||
|
||||
void (*free)(D12Effect ** instance);
|
||||
@ -61,14 +63,18 @@ struct D12Effect
|
||||
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,
|
||||
const DISPLAYCONFIG_PATH_INFO * displayPathInfo)
|
||||
{
|
||||
if (!effect->create(instance, device, displayPathInfo))
|
||||
return false;
|
||||
memcpy(*instance, effect, sizeof(*effect));
|
||||
return true;
|
||||
*instance = NULL;
|
||||
D12EffectStatus status = effect->create(instance, device, displayPathInfo);
|
||||
if (status == D12_EFFECT_STATUS_OK)
|
||||
memcpy(*instance, effect, sizeof(*effect));
|
||||
return status;
|
||||
}
|
||||
|
||||
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,
|
||||
dirtyRects, nbDirtyRects); }
|
||||
|
||||
// effect defines
|
||||
|
||||
extern const D12Effect D12Effect_RGB24;
|
||||
extern const D12Effect D12Effect_HDR16to10;
|
||||
|
||||
#endif
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "common/windebug.h"
|
||||
#include "common/array.h"
|
||||
#include "common/display.h"
|
||||
#include "common/option.h"
|
||||
|
||||
#include <d3dcompiler.h>
|
||||
|
||||
@ -34,17 +35,38 @@ HDR16to10Inst;
|
||||
|
||||
#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)
|
||||
{
|
||||
if (!option_get_bool("d12", "HDR16to10"))
|
||||
return D12_EFFECT_STATUS_BYPASS;
|
||||
|
||||
HDR16to10Inst * this = calloc(1, sizeof(*this));
|
||||
if (!this)
|
||||
{
|
||||
DEBUG_ERROR("out of memory");
|
||||
return false;
|
||||
return D12_EFFECT_STATUS_ERROR;
|
||||
}
|
||||
|
||||
bool result = false;
|
||||
bool result = D12_EFFECT_STATUS_ERROR;
|
||||
HRESULT hr;
|
||||
comRef_scopePush(10);
|
||||
|
||||
@ -241,12 +263,11 @@ static bool d12_effect_hdr16to10Create(D12Effect ** instance,
|
||||
comRef_toGlobal(this->descHeap , descHeap );
|
||||
comRef_toGlobal(this->constBuffer , constBuffer );
|
||||
|
||||
result = true;
|
||||
result = D12_EFFECT_STATUS_OK;
|
||||
*instance = &this->base;
|
||||
|
||||
exit:
|
||||
if (result)
|
||||
*instance = &this->base;
|
||||
else
|
||||
if (!*instance)
|
||||
free(this);
|
||||
|
||||
comRef_scopePop();
|
||||
@ -446,9 +467,10 @@ static ID3D12Resource * d12_effect_hdr16to10Run(D12Effect * effect,
|
||||
|
||||
const D12Effect D12Effect_HDR16to10 =
|
||||
{
|
||||
.name = "HDR16to10",
|
||||
.create = d12_effect_hdr16to10Create,
|
||||
.free = d12_effect_hdr16to10Free,
|
||||
.setFormat = d12_effect_hdr16to10SetFormat,
|
||||
.run = d12_effect_hdr16to10Run
|
||||
.name = "HDR16to10",
|
||||
.initOptions = d12_effect_hdr16to10InitOptions,
|
||||
.create = d12_effect_hdr16to10Create,
|
||||
.free = d12_effect_hdr16to10Free,
|
||||
.setFormat = d12_effect_hdr16to10SetFormat,
|
||||
.run = d12_effect_hdr16to10Run
|
||||
};
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "common/debug.h"
|
||||
#include "common/windebug.h"
|
||||
#include "common/array.h"
|
||||
#include "common/option.h"
|
||||
|
||||
#include <d3dcompiler.h>
|
||||
|
||||
@ -25,17 +26,38 @@ TestInstance;
|
||||
|
||||
#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)
|
||||
{
|
||||
if (!option_get_bool("d12", "allowRGB24"))
|
||||
return D12_EFFECT_STATUS_BYPASS;
|
||||
|
||||
TestInstance * this = calloc(1, sizeof(*this));
|
||||
if (!this)
|
||||
{
|
||||
DEBUG_ERROR("out of memory");
|
||||
return false;
|
||||
return D12_EFFECT_STATUS_ERROR;
|
||||
}
|
||||
|
||||
bool result = false;
|
||||
D12EffectStatus result = D12_EFFECT_STATUS_ERROR;
|
||||
HRESULT hr;
|
||||
comRef_scopePush(10);
|
||||
|
||||
@ -195,12 +217,11 @@ static bool d12_effect_rgb24Create(D12Effect ** instance, ID3D12Device3 * device
|
||||
comRef_toGlobal(this->pso , pso );
|
||||
comRef_toGlobal(this->descHeap , descHeap );
|
||||
|
||||
result = true;
|
||||
result = D12_EFFECT_STATUS_OK;
|
||||
*instance = &this->base;
|
||||
|
||||
exit:
|
||||
if (result)
|
||||
*instance = &this->base;
|
||||
else
|
||||
if (!*instance)
|
||||
free(this);
|
||||
|
||||
comRef_scopePop();
|
||||
@ -381,9 +402,10 @@ static ID3D12Resource * d12_effect_rgb24Run(D12Effect * effect,
|
||||
|
||||
const D12Effect D12Effect_RGB24 =
|
||||
{
|
||||
.name = "RGB24",
|
||||
.create = d12_effect_rgb24Create,
|
||||
.free = d12_effect_rgb24Free,
|
||||
.setFormat = d12_effect_rgb24SetFormat,
|
||||
.run = d12_effect_rgb24Run
|
||||
.name = "RGB24",
|
||||
.initOptions = d12_effect_rgb24InitOptions,
|
||||
.create = d12_effect_rgb24Create,
|
||||
.free = d12_effect_rgb24Free,
|
||||
.setFormat = d12_effect_rgb24SetFormat,
|
||||
.run = d12_effect_rgb24Run
|
||||
};
|
||||
|
32
host/platform/Windows/capture/D12/effects.h
Normal file
32
host/platform/Windows/capture/D12/effects.h
Normal 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
|
||||
};
|
Loading…
Reference in New Issue
Block a user