Skip to content

Commit

Permalink
fixes for reshade compat stuff + small initial config for pass detetcion
Browse files Browse the repository at this point in the history
now it works as expected, need to add more pass detection data but
good for now
  • Loading branch information
megai2 committed Mar 14, 2021
1 parent e758ed9 commit f59f066
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 22 deletions.
Binary file modified bin/d912pxy/shaders/iframe_mods/gw2enhanced/primary.cfg
Binary file not shown.
Binary file not shown.
5 changes: 5 additions & 0 deletions d912pxy/d912pxy_replay_extra_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,15 @@ RHA_DECL(om_render_targets, d912pxy_replay_thread_context* context)

int changed = (context->tracked.surfBind[0] != it->dsv) * 1;
context->tracked.surfBind[0] = it->dsv;
if (it->dsv)
it->dsv->setContextState(D3D12_RESOURCE_STATE_DEPTH_WRITE);

for (int i = 0; i < PXY_INNER_MAX_RENDER_TARGETS; ++i)
{
changed |= (context->tracked.surfBind[i + 1] != it->rtv[i]) * 2;
context->tracked.surfBind[i + 1] = it->rtv[i];
if (it->rtv[i])
it->rtv[i]->setContextState(D3D12_RESOURCE_STATE_RENDER_TARGET);
}


Expand Down
3 changes: 2 additions & 1 deletion d912pxy/d912pxy_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ class d912pxy_resource : public d912pxy_comhandler

private:
d912pxy_resource_typeid m_tid;
std::atomic<D3D12_RESOURCE_STATES> inContextState;
//simple atomic here will not help
D3D12_RESOURCE_STATES inContextState;

protected:
ID3D12Resource* m_res;
Expand Down
55 changes: 44 additions & 11 deletions d912pxy/v3/dx12/extras/iframe_mods/pass_detector2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ void PassDetector2::recordTarget(d912pxy_surface* surf, uint8_t bits)
//FIXME: link should do sorted insert and this will optimize to very simple code
for (int i = 1; i <= namedPasses.headIdx(); ++i)
{
if (namedPasses[i].hash == frData->hash)
if (namedPasses[i]->hash == frData->hash)
{
acctivePassName = namedPasses[i].name;
activePass = &namedPasses[i];
acctivePassName = namedPasses[i]->name;
activePass = namedPasses[i];
pt.dbgName = activePass->dbgName;
}
}
Expand All @@ -89,7 +89,10 @@ d912pxy::extras::IFrameMods::PassDetector2::~PassDetector2()
{
frData.Cleanup();
for (int i = 1; i <= namedPasses.headIdx(); ++i)
namedPasses[i].targets.clear();
{
namedPasses[i]->targets.clear();
delete namedPasses[i];
}
}

int d912pxy::extras::IFrameMods::PassDetector2::loadLinks(const wchar_t* passStrName)
Expand Down Expand Up @@ -139,15 +142,23 @@ int d912pxy::extras::IFrameMods::PassDetector2::loadLinks(const wchar_t* passStr
return ret;
}

void d912pxy::extras::IFrameMods::PassDetector2::linkName(uint64_t name, uint64_t hash, const wchar_t* dbg_name)
{
namedPasses.push(new NamedPass());
namedPasses.head()->hash = hash;
namedPasses.head()->name = name;
namedPasses.head()->dbgName = dbg_name;
}

intptr_t d912pxy::extras::IFrameMods::PassDetector2::linkTarget(uint64_t hash, const NamedTarget& tgt)
{
for (int i = 1; i <= namedPasses.headIdx(); ++i)
{
if (namedPasses[i].hash != hash)
if (namedPasses[i]->hash != hash)
continue;

namedPasses[i].targets.push(tgt);
return namedPasses[i].targets.headIdx();
namedPasses[i]->targets.push(tgt);
return namedPasses[i]->targets.headIdx();
}

return 0;
Expand All @@ -160,47 +171,65 @@ uint64_t d912pxy::extras::IFrameMods::PassDetector2::getLastFrameHash()

bool d912pxy::extras::IFrameMods::PassDetector2::copyLastSurfaceNamed(intptr_t idx, d912pxy_surface* target, ID3D12GraphicsCommandList* cl)
{
if (!activePass)
if (!activePass || (activePass->targets.headIdx() < idx))
return false;

const NamedTarget& tgt = activePass->targets[idx];

const NamedTarget& tgt = activePass->targets[idx];
return copyLastSurface(tgt.ds, tgt.converge, tgt.index, tgt.minimalPassNum, target, cl);
}

bool d912pxy::extras::IFrameMods::PassDetector2::copyLastSurface(bool ds, bool converge, int index, int minimalPassNum, d912pxy_surface* target, ID3D12GraphicsCommandList* cl)
{
#define DEBUG_TRACING(msg) LOG_DBG_DTDM3("%s %s %u-%u %p: %s", ds ? L"depth" : L"target", converge ? L"conv" : L"nconv", index, minimalPassNum, target, msg)

auto& uniqueTargets = lastFrData->uniqueTargetsArr[ds ? 1 : 0];

if (converge)
{
if (!isConvergingToLastFrame())
{
DEBUG_TRACING(L"not converging");
return false;
}
}

if (uniqueTargets.headIdx() < index)
{
DEBUG_TRACING(L"no target with index found");
return false;
}

if (c_frame_order < minimalPassNum)
{
DEBUG_TRACING(L"pass not reached");
return false;
}

d912pxy_surface* src = uniqueTargets[index];

if (!src)
{
DEBUG_TRACING(L"target is null");
return false;
}

const D3DSURFACE_DESC& tgtDesc = target->GetL0Desc();
const D3DSURFACE_DESC& srcDesc = src->GetL0Desc();

if ((tgtDesc.Width != srcDesc.Width) || (tgtDesc.Height != srcDesc.Height) || (tgtDesc.Format != srcDesc.Format))
{
DEBUG_TRACING(L"wh/format mismatch");
return false;
}

src->BCopyToWStates(target, 3, cl, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, src->getContextState());

return true;

#undef DEBUG_TRACING
}

d912pxy_surface* d912pxy::extras::IFrameMods::PassDetector2::makeBBsizedTarget(D3DFORMAT fmt)
d912pxy_surface* d912pxy::extras::IFrameMods::PassDetector2::makeBBsizedTarget(D3DFORMAT fmt, const wchar_t* dbgMarker)
{
UINT levels = 1;
d912pxy_surface* ret = d912pxy_surface::d912pxy_surface_com(
Expand All @@ -217,6 +246,10 @@ d912pxy_surface* d912pxy::extras::IFrameMods::PassDetector2::makeBBsizedTarget(D
);
ret->ConstructResource();

wchar_t buf[256];
wsprintf(buf, L"bb_sized_tgt_%s", dbgMarker);
ret->GetD12Obj()->SetName(buf);

return ret;
}

Expand Down
6 changes: 3 additions & 3 deletions d912pxy/v3/dx12/extras/iframe_mods/pass_detector2.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ namespace IFrameMods {
Trivial::PushBuffer<NamedTarget> targets;
};

Trivial::PushBuffer<NamedPass> namedPasses;
Trivial::PushBuffer<NamedPass*> namedPasses;
uint64_t newPassName = 0;
uint64_t acctivePassName = 0;
NamedPass* activePass = nullptr;
Expand All @@ -134,7 +134,7 @@ namespace IFrameMods {
int loadLinks(const wchar_t* passStrName);

int registerName() { return ++newPassName; }
void linkName(uint64_t name, uint64_t hash, const wchar_t* dbg_name) { namedPasses.push({ hash, name, dbg_name }); }
void linkName(uint64_t name, uint64_t hash, const wchar_t* dbg_name);
intptr_t linkTarget(uint64_t hash, const NamedTarget& tgt);
bool inPass(uint64_t name) { return acctivePassName == name; }
bool passChanged() { return newPass; }
Expand All @@ -149,7 +149,7 @@ namespace IFrameMods {
bool copyLastSurface(bool ds, bool converge, int index, int minimalPassNum, d912pxy_surface* target, ID3D12GraphicsCommandList* cl);
uint64_t getCurrentHash() { return frData->hash; }

d912pxy_surface* makeBBsizedTarget(D3DFORMAT fmt);
d912pxy_surface* makeBBsizedTarget(D3DFORMAT fmt, const wchar_t* dbgMarker);

bool isBBChangedThisFrame() { return bbChanged; }

Expand Down
39 changes: 33 additions & 6 deletions d912pxy/v3/dx12/extras/iframe_mods/reshade_compat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,21 @@ using namespace d912pxy::extras::IFrameMods;
const D3DFORMAT targetFormats[ReshadeCompat::TARGET_COUNT] =
{
D3DFMT_A8R8G8B8,
D3DFMT_D24X8,
(D3DFORMAT)D3DFMT_INTZ,
D3DFMT_A8R8G8B8,
D3DFMT_A8R8G8B8,
D3DFMT_A8R8G8B8
};

const wchar_t* targetDbgNames[ReshadeCompat::TARGET_COUNT] =
{
L"scene_color",
L"scene_depth",
L"scene_opaque",
L"gbuf0",
L"gbuf1"
};

ReshadeCompat::ReshadeCompat()
{
passes = new PassDetector2();
Expand All @@ -44,6 +53,7 @@ ReshadeCompat::ReshadeCompat()
resolvePass = passes->loadLinks(d912pxy_s.iframeMods.configValM(L"reshade_compat_pass_resolve").raw);
shadowPass = passes->loadLinks(d912pxy_s.iframeMods.configValM(L"reshade_compat_pass_shadow").raw);
normalPass = passes->loadLinks(d912pxy_s.iframeMods.configValM(L"reshade_compat_pass_normal").raw);
transparentPass = passes->loadLinks(d912pxy_s.iframeMods.configValM(L"reshade_compat_pass_transparent").raw);

d912pxy_s.iframeMods.pushMod(this);

Expand All @@ -62,10 +72,27 @@ void ReshadeCompat::RP_RTDSChange(d912pxy_replay_item::dt_om_render_targets* rpI
if (!passes->passChanged())
return;

if (passes->inPass(uiPass))
passes->copyLastSurfaceNamed(TARGET_COLOR+1, targets[TARGET_COLOR], rpContext->cl);

//TODO: all other stuff
if (passes->inPass(resolvePass))
{
passes->copyLastSurfaceNamed(1, targets[TARGET_GBUF1], rpContext->cl);
}
else if (passes->inPass(shadowPass))
{
passes->copyLastSurfaceNamed(1, targets[TARGET_GBUF0], rpContext->cl);
}
else if (passes->inPass(depthPass))
{
passes->copyLastSurfaceNamed(1, targets[TARGET_DEPTH], rpContext->cl);
}
else if (passes->inPass(transparentPass))
{
passes->copyLastSurfaceNamed(1, targets[TARGET_OPAQUE], rpContext->cl);
}
else if (passes->inPass(uiPass))
{
passes->copyLastSurfaceNamed(1, targets[TARGET_COLOR], rpContext->cl);
passes->copyLastSurfaceNamed(2, targets[TARGET_DEPTH], rpContext->cl);
}
}

void d912pxy::extras::IFrameMods::ReshadeCompat::RP_FrameStart()
Expand All @@ -76,7 +103,7 @@ void d912pxy::extras::IFrameMods::ReshadeCompat::RP_FrameStart()
{
if (targets[i])
targets[i]->Release();
targets[i] = passes->makeBBsizedTarget(targetFormats[i]);
targets[i] = passes->makeBBsizedTarget(targetFormats[i], targetDbgNames[i]);

if (rsadSupplyTexture)
rsadSupplyTexture(i, targets[i]->GetD12Obj());
Expand Down
2 changes: 1 addition & 1 deletion d912pxy/v3/dx12/extras/iframe_mods/reshade_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace d912pxy {
uint64_t shadowPass;
uint64_t normalPass;
uint64_t resolvePass;

uint64_t transparentPass;

union rsad_Data
{
Expand Down
1 change: 1 addition & 0 deletions d912pxy/v3/util/memory_block.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ namespace d912pxy
MemoryBlock(void* in_ptr) : MemoryArea(in_ptr, 0) {}
MemoryBlock(uintptr_t size);
~MemoryBlock();
MemoryBlock(const MemoryBlock&) = delete;

void alloc(uintptr_t size);
void realloc(uintptr_t newSize);
Expand Down

0 comments on commit f59f066

Please sign in to comment.