Skip to content

Commit

Permalink
Version 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
RavenSystem committed Dec 26, 2023
1 parent 18889ed commit b215020
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 157 deletions.
180 changes: 50 additions & 130 deletions src/d3d11/d3d11_post_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,102 +700,75 @@ namespace vrperfkit {
}


void D3D11PostProcessor::CreateDynamicProfileQueries() {
for (auto &profileQuery : dynamicProfileQueries) {
D3D11_QUERY_DESC qd;
qd.Query = D3D11_QUERY_TIMESTAMP;
qd.MiscFlags = 0;
device->CreateQuery(&qd, profileQuery.queryStart.ReleaseAndGetAddressOf());
device->CreateQuery(&qd, profileQuery.queryEnd.ReleaseAndGetAddressOf());
qd.Query = D3D11_QUERY_TIMESTAMP_DISJOINT;
device->CreateQuery(&qd, profileQuery.queryDisjoint.ReleaseAndGetAddressOf());
}
}

void D3D11PostProcessor::StartDynamicProfiling() {
++DynamicSleepCount;
if (DynamicSleepCount < g_config.dynamicFramesCheck) {
++dynamicSleepCount;
if (dynamicSleepCount < g_config.dynamicFramesCheck) {
return;
}

is_DynamicProfiling = true;

DynamicSleepCount = 0;
dynamicSleepCount = 0;

if (dynamicProfileQueries[0].queryStart == nullptr) {
CreateDynamicProfileQueries();
}

context->Begin(dynamicProfileQueries[DynamicCurrentQuery].queryDisjoint.Get());
context->End(dynamicProfileQueries[DynamicCurrentQuery].queryStart.Get());
GetSystemTimePreciseAsFileTime(&ft);
dynamicTimeUs = ft.dwLowDateTime;
}

void D3D11PostProcessor::EndDynamicProfiling() {
if (is_DynamicProfiling) {
context->End(dynamicProfileQueries[DynamicCurrentQuery].queryEnd.Get());
context->End(dynamicProfileQueries[DynamicCurrentQuery].queryDisjoint.Get());
GetSystemTimePreciseAsFileTime(&ft);
const unsigned int end = ft.dwLowDateTime;

float frameTime = (end - dynamicTimeUs) / 10000000.f; // (1000 * 1000 * 10) FrameTime in seconds

DynamicCurrentQuery = (DynamicCurrentQuery + 1) % DYNAMIC_QUERY_COUNT;
while (context->GetData(dynamicProfileQueries[0].queryDisjoint.Get(), nullptr, 0, 0) == S_FALSE) {
Sleep(1);
}
D3D11_QUERY_DATA_TIMESTAMP_DISJOINT disjoint;
HRESULT result = context->GetData(dynamicProfileQueries[DynamicCurrentQuery].queryDisjoint.Get(), &disjoint, sizeof(disjoint), 0);
if (result == S_OK && !disjoint.Disjoint) {
UINT64 begin, end;
context->GetData(dynamicProfileQueries[DynamicCurrentQuery].queryStart.Get(), &begin, sizeof(UINT64), 0);
context->GetData(dynamicProfileQueries[DynamicCurrentQuery].queryEnd.Get(), &end, sizeof(UINT64), 0);
float frameTime = (end - begin) / float(disjoint.Frequency); // FrameTime in seconds

//LOG_INFO << "frameTime: " << std::setprecision(8) << frameTime;

// HRM
if (g_config.hiddenMask.dynamic) {
if (frameTime > g_config.hiddenMask.targetFrameTime) {
if (g_config.hiddenMask.dynamicChangeRadius) {
if ((edgeRadius - g_config.hiddenMask.decreaseRadiusStep) >= g_config.hiddenMask.minRadius) {
edgeRadius -= g_config.hiddenMask.decreaseRadiusStep;
}
} else {
hiddenMaskApply = true;
//LOG_INFO << "frameTime: " << std::setprecision(8) << frameTime;

// HRM
if (g_config.hiddenMask.dynamic) {
if (frameTime > g_config.hiddenMask.targetFrameTime) {
if (g_config.hiddenMask.dynamicChangeRadius) {
if ((edgeRadius - g_config.hiddenMask.decreaseRadiusStep) >= g_config.hiddenMask.minRadius) {
edgeRadius -= g_config.hiddenMask.decreaseRadiusStep;
}
} else if (frameTime < g_config.hiddenMask.marginFrameTime) {
if (g_config.hiddenMask.dynamicChangeRadius) {
if ((edgeRadius + g_config.hiddenMask.increaseRadiusStep) <= g_config.hiddenMask.maxRadius) {
edgeRadius += g_config.hiddenMask.increaseRadiusStep;
}
} else {
hiddenMaskApply = false;
} else {
hiddenMaskApply = true;
}
} else if (frameTime < g_config.hiddenMask.marginFrameTime) {
if (g_config.hiddenMask.dynamicChangeRadius) {
if ((edgeRadius + g_config.hiddenMask.increaseRadiusStep) <= g_config.hiddenMask.maxRadius) {
edgeRadius += g_config.hiddenMask.increaseRadiusStep;
}
} else {
hiddenMaskApply = false;
}
}
}

// FFR
if (g_config.ffr.dynamic) {
if (frameTime > g_config.ffr.targetFrameTime) {
if (g_config.ffr.dynamicChangeRadius) {
if ((g_config.ffr.innerRadius - g_config.ffr.decreaseRadiusStep) >= g_config.ffr.minRadius) {
g_config.ffr.innerRadius -= g_config.ffr.decreaseRadiusStep;
g_config.ffr.midRadius -= g_config.ffr.decreaseRadiusStep;
g_config.ffr.outerRadius -= g_config.ffr.decreaseRadiusStep;
g_config.ffr.radiusChanged[0] = true;
g_config.ffr.radiusChanged[1] = true;
}
} else {
g_config.ffr.apply = true;
// FFR
if (g_config.ffr.dynamic) {
if (frameTime > g_config.ffr.targetFrameTime) {
if (g_config.ffr.dynamicChangeRadius) {
if ((g_config.ffr.innerRadius - g_config.ffr.decreaseRadiusStep) >= g_config.ffr.minRadius) {
g_config.ffr.innerRadius -= g_config.ffr.decreaseRadiusStep;
g_config.ffr.midRadius -= g_config.ffr.decreaseRadiusStep;
g_config.ffr.outerRadius -= g_config.ffr.decreaseRadiusStep;
g_config.ffr.radiusChanged[0] = true;
g_config.ffr.radiusChanged[1] = true;
}
} else if (frameTime < g_config.ffr.marginFrameTime) {
if (g_config.ffr.dynamicChangeRadius) {
if ((g_config.ffr.innerRadius + g_config.ffr.increaseRadiusStep) <= g_config.ffr.maxRadius) {
g_config.ffr.innerRadius += g_config.ffr.increaseRadiusStep;
g_config.ffr.midRadius += g_config.ffr.increaseRadiusStep;
g_config.ffr.outerRadius += g_config.ffr.increaseRadiusStep;
g_config.ffr.radiusChanged[0] = true;
g_config.ffr.radiusChanged[1] = true;
}
} else {
g_config.ffr.apply = false;
} else {
g_config.ffr.apply = true;
}
} else if (frameTime < g_config.ffr.marginFrameTime) {
if (g_config.ffr.dynamicChangeRadius) {
if ((g_config.ffr.innerRadius + g_config.ffr.increaseRadiusStep) <= g_config.ffr.maxRadius) {
g_config.ffr.innerRadius += g_config.ffr.increaseRadiusStep;
g_config.ffr.midRadius += g_config.ffr.increaseRadiusStep;
g_config.ffr.outerRadius += g_config.ffr.increaseRadiusStep;
g_config.ffr.radiusChanged[0] = true;
g_config.ffr.radiusChanged[1] = true;
}
} else {
g_config.ffr.apply = false;
}
}
}
Expand All @@ -805,57 +778,4 @@ namespace vrperfkit {

StartDynamicProfiling();
}


/*
void D3D11PostProcessor::CreateProfileQueries() {
for (auto &profileQuery : profileQueries) {
D3D11_QUERY_DESC qd;
qd.Query = D3D11_QUERY_TIMESTAMP;
qd.MiscFlags = 0;
device->CreateQuery(&qd, profileQuery.queryStart.ReleaseAndGetAddressOf());
device->CreateQuery(&qd, profileQuery.queryEnd.ReleaseAndGetAddressOf());
qd.Query = D3D11_QUERY_TIMESTAMP_DISJOINT;
device->CreateQuery(&qd, profileQuery.queryDisjoint.ReleaseAndGetAddressOf());
}
}
void D3D11PostProcessor::StartProfiling() {
if (profileQueries[0].queryStart == nullptr) {
CreateProfileQueries();
}
context->Begin(profileQueries[currentQuery].queryDisjoint.Get());
context->End(profileQueries[currentQuery].queryStart.Get());
}
void D3D11PostProcessor::EndProfiling() {
context->End(profileQueries[currentQuery].queryEnd.Get());
context->End(profileQueries[currentQuery].queryDisjoint.Get());
currentQuery = (currentQuery + 1) % QUERY_COUNT;
while (context->GetData(profileQueries[currentQuery].queryDisjoint.Get(), nullptr, 0, 0) == S_FALSE) {
Sleep(1);
}
D3D11_QUERY_DATA_TIMESTAMP_DISJOINT disjoint;
HRESULT result = context->GetData(profileQueries[currentQuery].queryDisjoint.Get(), &disjoint, sizeof(disjoint), 0);
if (result == S_OK && !disjoint.Disjoint) {
UINT64 begin, end;
context->GetData(profileQueries[currentQuery].queryStart.Get(), &begin, sizeof(UINT64), 0);
context->GetData(profileQueries[currentQuery].queryEnd.Get(), &end, sizeof(UINT64), 0);
float duration = (end - begin) / float(disjoint.Frequency);
summedGpuTime += duration;
++countedQueries;
if (countedQueries >= 500) {
float avgTimeMs = 1000.f / countedQueries * summedGpuTime;
// Queries are done per eye, but we want the average for both eyes per frame
avgTimeMs *= 2;
LOG_INFO << "Average GPU processing time for post-processing: " << avgTimeMs << " ms";
countedQueries = 0;
summedGpuTime = 0.f;
}
}
}
*/
}
26 changes: 3 additions & 23 deletions src/d3d11/d3d11_post_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,9 @@ namespace vrperfkit {
ComPtr<ID3D11Query> queryStart;
ComPtr<ID3D11Query> queryEnd;
};
static const int DYNAMIC_QUERY_COUNT = 1;
int DynamicSleepCount = 0;
DynamicProfileQuery dynamicProfileQueries[DYNAMIC_QUERY_COUNT];
int DynamicCurrentQuery = 0;
float DynamicSummedGpuTime = 0.0f;
int DynamicCountedQueries = 0;
FILETIME ft;
unsigned int dynamicTimeUs = 0;
int dynamicSleepCount = 0;
bool is_DynamicProfiling = false;
bool enableDynamic = false;
bool hiddenMaskApply = false;
Expand Down Expand Up @@ -113,22 +110,5 @@ namespace vrperfkit {
void D3D11PostProcessor::PrepareRdmResources(DXGI_FORMAT format);
void D3D11PostProcessor::ApplyRadialDensityMask(ID3D11Texture2D *depthStencilTex, float depth, uint8_t stencil);
void D3D11PostProcessor::ReconstructRdmRender(const D3D11PostProcessInput &input);

/*
struct ProfileQuery {
ComPtr<ID3D11Query> queryDisjoint;
ComPtr<ID3D11Query> queryStart;
ComPtr<ID3D11Query> queryEnd;
};
static const int QUERY_COUNT = 6;
ProfileQuery profileQueries[QUERY_COUNT];
int currentQuery = 0;
float summedGpuTime = 0.0f;
int countedQueries = 0;
void CreateProfileQueries();
void StartProfiling();
void EndProfiling();
*/
};
}
2 changes: 1 addition & 1 deletion src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ namespace {

vrperfkit::OpenLogFile(vrperfkit::g_basePath / "vrperfkit_RSF.log");
LOG_INFO << "===============================";
LOG_INFO << "VR Performance Toolkit RSF v3.1";
LOG_INFO << "VR Performance Toolkit RSF v3.2";
LOG_INFO << "===============================\n";

vrperfkit::LoadConfig(vrperfkit::g_basePath / "vrperfkit_RSF.yml");
Expand Down
6 changes: 3 additions & 3 deletions vrperfkit_RSF.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# =============================== #
# VR Performance Toolkit RSF v3.1 #
# VR Performance Toolkit RSF v3.2 #
# =============================== #

# dxgi.dll: If game uses its own dxgi.dll or other post-processor library, like
Expand Down Expand Up @@ -76,7 +76,7 @@ fixedFoveated:
# FPS to start recovering decrasing radius.
marginFPS: 65.0
# Change default dynamic behavior: FFR is always enabled but dynamic mode changes radius dinamically
dynamicChangeRadius: false
dynamicChangeRadius: true
# Minimal radius: This is the minimal radius applied to innerRadius when dynamic is enabled
minRadius: 0.30
# Decreased radius amount applied for each frametime check when needed
Expand Down Expand Up @@ -141,7 +141,7 @@ hiddenMask:
# FPS to start recovering decrasing radius.
marginFPS: 60.0
# Change default dynamic behavior: HRM is always enabled but dynamic mode changes radius dinamically
dynamicChangeRadius: false
dynamicChangeRadius: true
# Minimal radius: This is the minimal radius applied when dynamic is enabled
minRadius: 0.85
# Decreased radius amount applied for each frametime check when needed
Expand Down

0 comments on commit b215020

Please sign in to comment.