engine: presets E/F AutoExposure, the game's exposure fields and NGX's jitter order

NGX's CNN takes this frame's exposure scale and pre-exposure in both translated kernels (input words 244-256,
reconstruction 592-604) and the previous frame's exposure as the input kernel's texture 352
(cuda_copy_exposure_kernel's half surface). The runtime left all of it at the model dump's values, so HDR games
with a pre-exposure other than 1 or a changing exposure measured 18-39 dB against NGX; now 54-64 dB.

AutoExposure (flag 0x40), which the shim refused for E/F: NGX runs K's log-mean measurement on M's grid every
second frame. exposure_k.comp MODE 3 writes it to the 1x1 image the kernels sample; sr/exposure_copy_e.comp
keeps the previous exposure. 60-66 dB over eleven frames at 960x540 -> 1920x1080, pre-exposure 19-21.

The reconstruction's jitter words 544-556 are (y, x); the runtime wrote (-x, -y), which matches only the
harness's first three jitters, so every later frame of a game's jitter sequence measured 26-28 dB. Twelve-frame
captures now measure 60-66 dB HDR and LDR; on the Steam Deck through the shim 51-67 dB against ZLUDA.

The D3D12 harness takes per-frame lists in D4R_HARNESS_PRE_EXPOSURE / _EXPOSURE_SCALE; d4r-e takes the
AutoExposure flag, per-frame exposure values and the game's exposure texture. E/F models need rebuilding
(the install's model cache key changes); older models keep the old binding and refuse AutoExposure.
This commit is contained in:
woutermans committed 2026-10-19 02:42:48 +02:00
1 parent 916b0d1467
commit 3f66081add
12 files changed
+249 -47

No files matched your search

+17 -4
View File
@@ -2012,12 +2012,25 @@ int main(int argc, char** argv)
}
else if (temporal)
d4r_ngx_set_int(parameters, "Reset", forceReset || frame == 1 ? 1 : 0);
// D4R_HARNESS_PRE_EXPOSURE / D4R_HARNESS_EXPOSURE_SCALE: non-neutral values on every frame, as games
// with their own exposure pipeline pass them.
// D4R_HARNESS_PRE_EXPOSURE / D4R_HARNESS_EXPOSURE_SCALE: non-neutral values, as games with their own
// exposure pipeline pass them. A comma list gives one value per frame (the last repeats).
auto scheduled = [frame](const char* list) {
float value = 1.0f;
const char* cursor = list;
for (int index = 1; index <= frame; ++index)
{
char* end = nullptr;
value = std::strtof(cursor, &end);
if (*end != ',')
break;
cursor = end + 1;
}
return value;
};
if (const char* value = std::getenv("D4R_HARNESS_PRE_EXPOSURE"))
d4r_ngx_set_float(parameters, "DLSS.Pre.Exposure", static_cast<float>(std::atof(value)));
d4r_ngx_set_float(parameters, "DLSS.Pre.Exposure", scheduled(value));
if (const char* value = std::getenv("D4R_HARNESS_EXPOSURE_SCALE"))
d4r_ngx_set_float(parameters, "DLSS.Exposure.Scale", static_cast<float>(std::atof(value)));
d4r_ngx_set_float(parameters, "DLSS.Exposure.Scale", scheduled(value));
// D4R_HARNESS_NGX_FLOATS="Name=value,Name=value": float evaluation parameters set on every frame after the
// defaults (e.g. MV.Scale.X=2,FrameTimeDeltaInMsec=8), to see how NGX passes them on.
if (const char* list = std::getenv("D4R_HARNESS_NGX_FLOATS"))
+20 -7
View File
@@ -10332,8 +10332,14 @@ static bool engine_evaluate_e(Feature& feature, ID3D12GraphicsCommandList* list,
return refuse(slot ? "no preset F model (engine\\f)" : "no preset E model (engine\\e)");
// NVSDK_NGX_DLSS_Feature_Flags: IsHDR 1, MVLowRes 2, MVJittered 4, DepthInverted 8, AutoExposure 0x40.
const bool hdr = (feature.flags & 0x1) != 0, lowRes = (feature.flags & 0x2) != 0;
if ((feature.flags & 0x40) != 0)
return refuse("auto exposure is not implemented for preset E/F");
// AutoExposure: NGX measures the exposure from the colour (HDR only; an LDR feature has no exposure at all)
const bool autoExposure = hdr && (feature.flags & 0x40) != 0;
if (autoExposure && !model->hasAutoExposure())
return refuse("auto exposure needs a model built by this d4r version (run d4r/tools/build-engine-models.sh)");
if (hdr && !(std::isfinite(p.preExposure) && p.preExposure > 0.0f))
return refuse("the pre-exposure is not a positive number");
if (hdr && !(std::isfinite(p.exposureScale) && p.exposureScale > 0.0f))
return refuse("the exposure scale is not a positive number");
if (color == output || depth == output || motion == output)
return refuse("input/output texture aliasing is not supported");
if (p.renderWidth > feature.outWidth || p.renderHeight > feature.outHeight)
@@ -10344,8 +10350,9 @@ static bool engine_evaluate_e(Feature& feature, ID3D12GraphicsCommandList* list,
const auto depthState = static_cast<D3D12_RESOURCE_STATES>(env_uint("D4R_SHIM_DEPTH_STATE", 0x40));
const auto outputState = static_cast<D3D12_RESOURCE_STATES>(env_uint("D4R_SHIM_OUTPUT_STATE", 0x8));
const uint32_t mw = lowRes ? p.renderWidth : feature.outWidth, mh = lowRes ? p.renderHeight : feature.outHeight;
// HDR: the game's exposure texture is NGX's exposure (its copy kernel moves texel 0 into the 1x1 the kernels read)
const bool gameExposure = hdr && exposure != nullptr;
// HDR: the game's exposure texture is NGX's exposure (its copy kernel moves texel 0 into the 1x1 the kernels read);
// with AutoExposure NGX measures instead and does not read it
const bool gameExposure = hdr && !autoExposure && exposure != nullptr;
Source sources[5] = {
{color, &game.color, p.colorBaseX, p.colorBaseY, p.renderWidth, p.renderHeight, inputState, D3D12_RESOURCE_STATE_COPY_SOURCE},
{depth, &game.depth, p.depthBaseX, p.depthBaseY, p.renderWidth, p.renderHeight, depthState, D3D12_RESOURCE_STATE_COPY_SOURCE},
@@ -10390,6 +10397,11 @@ static bool engine_evaluate_e(Feature& feature, ID3D12GraphicsCommandList* list,
game.jitter[1] = p.jitterY;
game.motionScale[0] = p.mvScaleX;
game.motionScale[1] = p.mvScaleY;
if (hdr)
{
game.preExposure = p.preExposure;
game.exposureScale = p.exposureScale;
}
const bool resized = feature.engineE != nullptr &&
(p.renderWidth != feature.engineERenderWidth || p.renderHeight != feature.engineERenderHeight);
game.reset = p.reset != 0 || feature.engineE == nullptr || resized;
@@ -10399,12 +10411,13 @@ static bool engine_evaluate_e(Feature& feature, ID3D12GraphicsCommandList* list,
{
feature.engineE.reset();
feature.engineE = std::make_unique<d4r::GameUpscalerE>(*model, g_vk.physical, g_vk.device, feature.outWidth,
feature.outHeight, p.renderWidth, p.renderHeight, hdr, lowRes);
feature.outHeight, p.renderWidth, p.renderHeight, hdr, lowRes,
autoExposure);
feature.engineERenderWidth = p.renderWidth;
feature.engineERenderHeight = p.renderHeight;
logf("engine backend (%s): feature %u runs preset %s in the game's command list (%ux%u -> %ux%u, %s, %s motion)",
logf("engine backend (%s): feature %u runs preset %s in the game's command list (%ux%u -> %ux%u, %s, %s motion%s)",
name, feature.handle.Id, name, p.renderWidth, p.renderHeight, feature.outWidth, feature.outHeight,
hdr ? "HDR" : "LDR", lowRes ? "render-size" : "output-size");
hdr ? "HDR" : "LDR", lowRes ? "render-size" : "output-size", autoExposure ? ", auto exposure" : "");
}
}
catch (const std::exception& error)