Skip to content

Commit

Permalink
Merge branch 'pkristof/rtxPassExtension' into 'main'
Browse files Browse the repository at this point in the history
Code format cleanup

See merge request lightspeedrtx/dxvk-remix-nv!991
  • Loading branch information
pkristof committed Sep 27, 2024
2 parents 20fd5da + ac96430 commit fb5dcc9
Show file tree
Hide file tree
Showing 21 changed files with 161 additions and 117 deletions.
2 changes: 1 addition & 1 deletion RtxOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ Tables below enumerate all the options and their defaults set by RTX Remix. Note
|rtx.instanceOverrideInstanceIdxRange|int|15||
|rtx.instanceOverrideSelectedInstancePrintMaterialHash|bool|False||
|rtx.instanceOverrideWorldOffset|float3|0, 0, 0||
|rtx.integrateIndirectMode|int|1|Indirect integration mode:<br>0: Importance Sampled\. Uses typical GI sampling and is not recommended for general use as it provides the noisiest output\. It serves as a reference integration mode for validation of the other indirect integration modes\.<br>1: ReSTIR GI\. ReSTIR GI provides improved indirect path sampling over Basic mode with better indirect diffuse and specular GI quality at increased performance cost\.<br>|
|rtx.integrateIndirectMode|int|1|Indirect integration mode:<br>0: Importance Sampled\. Importance sampled mode uses typical GI sampling and it is not recommended for general use as it provides the noisiest output\.<br> It serves as a reference integration mode for validation of other indirect integration modes\.<br>1: ReSTIR GI\. ReSTIR GI provides improved indirect path sampling over "Importance Sampled" mode with better indirect diffuse and specular GI quality at increased performance cost\.<br>|
|rtx.io.enabled|bool|False|When this option is enabled the assets will be loaded \(and optionally decompressed on GPU\) using high performance RTX IO runtime\. RTX IO must be enabled for loading compressed assets, but is not necessary for working with loose uncompressed assets\.|
|rtx.io.forceCpuDecoding|bool|False|Force CPU decoding in RTX IO\.|
|rtx.io.memoryBudgetMB|int|256||
Expand Down
7 changes: 5 additions & 2 deletions src/dxvk/imgui/dxvk_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,11 @@ namespace dxvk {
ImGui::ComboWithKey<IntegrateIndirectMode> integrateIndirectModeCombo {
"Integrate Indirect Illumination Mode",
ImGui::ComboWithKey<IntegrateIndirectMode>::ComboEntries { {
{IntegrateIndirectMode::ImportanceSampled, "Importance Sampled"},
{IntegrateIndirectMode::ReSTIRGI, "ReSTIR GI"}
{IntegrateIndirectMode::ImportanceSampled, "Importance Sampled",
"Importance Sampled. Importance sampled mode uses typical GI sampling and it is not recommended for general use as it provides the noisiest output.\n"
"It serves as a reference integration mode for validation of other indirect integration modes." },
{IntegrateIndirectMode::ReSTIRGI, "ReSTIR GI",
"ReSTIR GI provides improved indirect path sampling over \"Importance Sampled\" mode with better indirect diffuse and specular GI quality at increased performance cost."}
} }
};

Expand Down
11 changes: 7 additions & 4 deletions src/dxvk/rtx_render/rtx_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,8 +979,8 @@ namespace dxvk {
ReSTIRGISampleStealing restirGISampleStealingMode = restirGI.useSampleStealing();
// Stealing pixels requires indirect light stored in separated buffers instead of combined with direct light,
// steal samples if separated denoiser is disabled.
if (restirGISampleStealingMode == ReSTIRGISampleStealing::StealPixel && !RtxOptions::Get()->isSeparatedDenoiserEnabled())
{
if (restirGISampleStealingMode == ReSTIRGISampleStealing::StealPixel
&& !RtxOptions::Get()->isSeparatedDenoiserEnabled()) {
restirGISampleStealingMode = ReSTIRGISampleStealing::StealSample;
}
constants.enableReSTIRGI = restirGI.isActive();
Expand Down Expand Up @@ -1243,6 +1243,8 @@ namespace dxvk {

// Integrate indirect
m_common->metaPathtracerIntegrateIndirect().dispatch(this, rtOutput);

// Integrate indirect - NEE Cache pass
m_common->metaPathtracerIntegrateIndirect().dispatchNEE(this, rtOutput);
}

Expand Down Expand Up @@ -1468,8 +1470,9 @@ namespace dxvk {
void RtxContext::dispatchToneMapping(const Resources::RaytracingOutput& rtOutput, bool performSRGBConversion, const float frameTimeMilliseconds) {
ScopedCpuProfileZone();

if (m_common->metaDebugView().debugViewIdx() == DEBUG_VIEW_PRE_TONEMAP_OUTPUT)
if (m_common->metaDebugView().debugViewIdx() == DEBUG_VIEW_PRE_TONEMAP_OUTPUT) {
return;
}

// TODO: I think these are unnecessary, and/or should be automatically done within DXVK
this->spillRenderPass(false);
Expand Down Expand Up @@ -1579,7 +1582,7 @@ namespace dxvk {

if (captureScreenImage) {
takeScreenshot("rtxImageDebugView", debugView.getFinalDebugOutput()->image());
}
}
}

void RtxContext::dispatchReplaceCompositeWithDebugView(const Resources::RaytracingOutput& rtOutput) {
Expand Down
14 changes: 14 additions & 0 deletions src/dxvk/rtx_render/rtx_imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,20 @@ namespace ImGui {
return IMGUI_ADD_TOOLTIP(getKey(&rtxOption->getValue()), rtxOption->getDescription());
}

void removeComboEntry(const T& key) {
auto it = m_keyToComboIdx.find(key);

if (it == m_keyToComboIdx.end()) {
return;
}

const int comboIdx = it->second;

// Remove the corresponding elements in containers
m_comboEntries.erase(m_comboEntries.begin() + comboIdx);
m_keyToComboIdx.erase(it);
}

private:
static bool getString(void* data, int entryIdx, const char** out_text, const char** out_tooltip) {
const ComboEntries& v = *reinterpret_cast<const ComboEntries*>(data);
Expand Down
1 change: 1 addition & 0 deletions src/dxvk/rtx_render/rtx_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ namespace dxvk {
DxvkRtxdiRayQuery::enableDenoiserConfidenceRef() = true;

// ReSTIR GI
integrateIndirectModeRef() = IntegrateIndirectMode::ReSTIRGI;
DxvkReSTIRGIRayQuery::setToNRDPreset();

// Integrator
Expand Down
5 changes: 3 additions & 2 deletions src/dxvk/rtx_render/rtx_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,9 @@ namespace dxvk {
"RTXDI provides improved direct light sampling quality over traditional methods and should generally be enabled for improved direct lighting quality at the cost of some performance.");
RTX_OPTION_ENV("rtx", IntegrateIndirectMode, integrateIndirectMode, IntegrateIndirectMode::ReSTIRGI, "RTX_INTEGRATE_INDIRECT_MODE",
"Indirect integration mode:\n"
"0: Importance Sampled. Uses typical GI sampling and is not recommended for general use as it provides the noisiest output. It serves as a reference integration mode for validation of the other indirect integration modes.\n"
"1: ReSTIR GI. ReSTIR GI provides improved indirect path sampling over Basic mode with better indirect diffuse and specular GI quality at increased performance cost.\n");
"0: Importance Sampled. Importance sampled mode uses typical GI sampling and it is not recommended for general use as it provides the noisiest output.\n"
" It serves as a reference integration mode for validation of other indirect integration modes.\n"
"1: ReSTIR GI. ReSTIR GI provides improved indirect path sampling over \"Importance Sampled\" mode with better indirect diffuse and specular GI quality at increased performance cost.\n");
RTX_OPTION_ENV("rtx", UpscalerType, upscalerType, UpscalerType::DLSS, "DXVK_UPSCALER_TYPE", "Upscaling boosts performance with varying degrees of image quality tradeoff depending on the type of upscaler and the quality mode/preset.");
RTX_OPTION_ENV("rtx", bool, enableRayReconstruction, true, "DXVK_RAY_RECONSTRUCTION", "Enable ray reconstruction.");

Expand Down
3 changes: 2 additions & 1 deletion src/dxvk/rtx_render/rtx_pathtracer_gbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ namespace dxvk {
ctx->bindResourceView(GBUFFER_BINDING_TRANSMISSION_PSR_DATA_STORAGE_2, rtOutput.m_gbufferPSRData[5].view(Resources::AccessType::Write), nullptr);
ctx->bindResourceView(GBUFFER_BINDING_TRANSMISSION_PSR_DATA_STORAGE_3, rtOutput.m_gbufferPSRData[6].view(Resources::AccessType::Write), nullptr);

// Bind necessary buffers for DLSS-RR. RR uses different PSR rules compared to other users, and it's resolves are resolved in another shader.
// Bind necessary buffers for DLSS-RR.
// Note: RR uses different PSR rules compared to other uses, and its resolves are resolved in an another shader.
ctx->bindResourceView(GBUFFER_BINDING_PRIMARY_DEPTH_DLSSRR_OUTPUT, rtOutput.m_primaryDepthDLSSRR.view, nullptr);
ctx->bindResourceView(GBUFFER_BINDING_PRIMARY_NORMAL_DLSSRR_OUTPUT, rtOutput.m_primaryWorldShadingNormalDLSSRR.view, nullptr);
ctx->bindResourceView(GBUFFER_BINDING_PRIMARY_SCREEN_SPACE_MOTION_DLSSRR_OUTPUT, rtOutput.m_primaryScreenSpaceMotionVectorDLSSRR.view, nullptr);
Expand Down
2 changes: 1 addition & 1 deletion src/dxvk/rtx_render/rtx_ray_reconstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "rtx_context.h"
#include "rtx_options.h"
#include "rtx/pass/tonemap/tonemapping.h"
#include "rtx/pass/rayreconstruction/ray_reconstruction.h"
#include "rtx/pass/ray_reconstruction/ray_reconstruction.h"
#include "dxvk_device.h"
#include "rtx_dlss.h"
#include "dxvk_scoped_annotation.h"
Expand Down
5 changes: 3 additions & 2 deletions src/dxvk/rtx_render/rtx_resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,11 @@ namespace dxvk {
"Input aliased resource was created with incompatible create resource parameters");
#endif

if (format == otherImageInfo.format)
if (format == otherImageInfo.format) {
m_view = other.m_view;
else
} else {
m_view = createImageView(ctx, m_sharedResource->resource.image, format, numLayers, imageViewType);
}
}

Resources::AliasedResource& Resources::AliasedResource::operator=(Resources::AliasedResource&& other) {
Expand Down
18 changes: 12 additions & 6 deletions src/dxvk/rtx_render/rtx_resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,17 @@ namespace dxvk
using FrameBeginEvent = std::function<void(Rc<DxvkContext>& ctx, const FrameBeginContext&)>;

EventHandler(ResizeEvent&& onTargetResize, ResizeEvent&& onDownscaleResize, FrameBeginEvent&& onFrameBeginEvent) {
if(onTargetResize)
if (onTargetResize) {
onTargetResolutionResize = std::make_shared<ResizeEvent>(onTargetResize);
}

if (onDownscaleResize)
if (onDownscaleResize) {
onDownscaledResolutionResize = std::make_shared<ResizeEvent>(onDownscaleResize);
}

if (onFrameBeginEvent)
if (onFrameBeginEvent) {
onFrameBegin = std::make_shared<FrameBeginEvent>(onFrameBeginEvent);
}
}

private:
Expand Down Expand Up @@ -362,14 +365,17 @@ namespace dxvk

void addEventHandler(const EventHandler& events) {
// NOTE: Implicit conversion to weak ptr
if(events.onTargetResolutionResize)
if (events.onTargetResolutionResize) {
m_onTargetResize.push_back(events.onTargetResolutionResize);
}

if(events.onDownscaledResolutionResize)
if (events.onDownscaledResolutionResize) {
m_onDownscaleResize.push_back(events.onDownscaledResolutionResize);
}

if(events.onFrameBegin)
if (events.onFrameBegin) {
m_onFrameBegin.push_back(events.onFrameBegin);
}
}

// Message function called at the beginning of the frame, usually allocate or release resources based on each pass's status
Expand Down
5 changes: 3 additions & 2 deletions src/dxvk/rtx_render/rtx_restir_gi_rayquery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,11 @@ namespace dxvk {
ImGui::DragFloat("Boiling Filter Max Threshold", &boilingFilterMaxThresholdObject(), 0.01f, 0.0f, FLT_MAX, "%.3f", ImGuiSliderFlags_AlwaysClamp);
ImGui::DragFloat("Boiling Filter Remove Reservoir Threshold", &boilingFilterRemoveReservoirThresholdObject(), 0.01f, 0.0f, FLT_MAX, "%.3f", ImGuiSliderFlags_AlwaysClamp);
ImGui::Checkbox("Use Adaptive Temporal History", &useAdaptiveTemporalHistoryObject());
if (useAdaptiveTemporalHistory())
if (useAdaptiveTemporalHistory()) {
ImGui::DragInt("Temporal History Length (ms)", &temporalAdaptiveHistoryLengthMsObject(), 1.f, 1, 3000, "%d", ImGuiSliderFlags_AlwaysClamp);
else
} else {
ImGui::DragInt("Temporal History Length (frame)", &temporalFixedHistoryLengthObject(), 1.f, 1, 500, "%d", ImGuiSliderFlags_AlwaysClamp);
}
ImGui::DragInt("Permutation Sampling Size", &permutationSamplingSizeObject(), 0.1f, 1, 8, "%d", ImGuiSliderFlags_AlwaysClamp);
ImGui::Checkbox("Discard Enlarged Pixels", &useDiscardEnlargedPixelsObject());
ImGui::DragFloat("History Discard Strength", &historyDiscardStrengthObject(), 0.01f, 0.f, 50.f, "%.1f");
Expand Down
5 changes: 3 additions & 2 deletions src/dxvk/rtx_render/rtx_restir_gi_rayquery.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ namespace dxvk {
void showImguiSettings();

int getTemporalHistoryLength(float frameTimeMs) {
if (useAdaptiveTemporalHistory())
if (useAdaptiveTemporalHistory()) {
return static_cast<int>(std::max(temporalAdaptiveHistoryLengthMs() / frameTimeMs, 20.0f));
else
} else {
return temporalFixedHistoryLength();
}
}

void bindIntegrateIndirectPathTracingResources(RtxContext& ctx);
Expand Down
6 changes: 4 additions & 2 deletions src/dxvk/rtx_render/rtx_taa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,14 @@ namespace dxvk {

void DxvkTemporalAA::createTargetResource(Rc<DxvkContext>& ctx, const VkExtent3D& targetExtent) {
// TAA intermediate textures
for(uint32_t i=0 ; i<2 ; i++)
for (uint32_t i = 0; i < 2; i++) {
m_taaFeedbackTexture[i] = Resources::createImageResource(ctx, "TAA feedback texture", targetExtent, VK_FORMAT_R32G32B32A32_SFLOAT);
}
}

void DxvkTemporalAA::releaseTargetResource() {
for (uint32_t i = 0; i < 2; i++)
for (uint32_t i = 0; i < 2; i++) {
m_taaFeedbackTexture[i].reset();
}
}
}
106 changes: 56 additions & 50 deletions src/dxvk/shaders/rtx/algorithm/geometry_resolver.slangh
Original file line number Diff line number Diff line change
Expand Up @@ -1271,26 +1271,11 @@ void geometryResolverVertex(

return;
}

// Construct RNG

RNG randomState = createRNG(geometryResolverState.pixelCoordinate, cb.frameIdx);

// Add in Emissive contribution

const vec3 materialEmissiveRadiance = polymorphicSurfaceMaterialInteractionEvalEmissiveRadiance(polymorphicSurfaceMaterialInteraction);

// For emissive surface that has sprite sheet animation, put emissive component to particle layer to reduce ghosting
if (cb.outputParticleLayer && any(materialEmissiveRadiance > 0.0) &&
surface.spriteSheetRows * surface.spriteSheetCols > 1)
{
accumulateParticleBuffer(geometryResolverState.pixelCoordinate, materialEmissiveRadiance * geometryResolverState.attenuation);
}
else
{
geometryResolverState.radiance += materialEmissiveRadiance * geometryResolverState.attenuation;
}

// Get PSR related flags and early out of PSR sampling

const bool enablePSRR = cb.enablePSRR;
Expand Down Expand Up @@ -1332,24 +1317,42 @@ void geometryResolverVertex(
surfaceMaterialInteractionTransmissionPSRSample.performPSR;
}

// Approximate the diffuse layer contribution
// Add non-direct lighting radiance contributions at the GBuffer hit
{
// Add in Emissive contribution

// Note: Using attenuation here to factor in the "standard" attenuation from resolving beforehand. Importantly this
// code needs to come before the PSRR attenuation is factored in otherwise the reflection attenuation will improperly modulate the
// incident diffuse layer contribution.
vec3 diffuseLayerRadiance = approximateDiffuseLayerRadiance(
surfaceInteraction, geometryResolverState.portalSpace, diffuseLayerWeight);
const vec3 materialEmissiveRadiance = polymorphicSurfaceMaterialInteractionEvalEmissiveRadiance( polymorphicSurfaceMaterialInteraction);

diffuseLayerRadiance *= geometryResolverState.attenuation;
// For emissive surface that has sprite sheet animation, put emissive component to particle layer to reduce ghosting
if (cb.outputParticleLayer && any(materialEmissiveRadiance > 0.0) &&
surface.spriteSheetRows * surface.spriteSheetCols > 1)
{
accumulateParticleBuffer(geometryResolverState.pixelCoordinate, materialEmissiveRadiance * geometryResolverState.attenuation);
}
else
{
geometryResolverState.radiance += materialEmissiveRadiance * geometryResolverState.attenuation;
}

// Output diffuse component from the glass to a separate particle layer so that it won't get mixed with background noise.
if (cb.outputParticleLayer && any(diffuseLayerRadiance > 0.0))
{
accumulateParticleBuffer(geometryResolverState.pixelCoordinate, diffuseLayerRadiance);
}
else
{
geometryResolverState.radiance += diffuseLayerRadiance;
// Approximate the diffuse layer contribution

// Note: Using attenuation here to factor in the "standard" attenuation from resolving beforehand. Importantly this
// code needs to come before the PSRR attenuation is factored in otherwise the reflection attenuation will improperly modulate the
// incident diffuse layer contribution.
vec3 diffuseLayerRadiance = approximateDiffuseLayerRadiance(
surfaceInteraction, geometryResolverState.portalSpace, diffuseLayerWeight);

diffuseLayerRadiance *= geometryResolverState.attenuation;

// Output diffuse component from the glass to a separate particle layer so that it won't get mixed with background noise.
if (cb.outputParticleLayer && any(diffuseLayerRadiance > 0.0))
{
accumulateParticleBuffer(geometryResolverState.pixelCoordinate, diffuseLayerRadiance);
}
else
{
geometryResolverState.radiance += diffuseLayerRadiance;
}
}

// Set the PSTR material medium index if a medium was entered
Expand Down Expand Up @@ -1848,12 +1851,6 @@ void geometryPSRResolverVertex(
// Now apply attenuation after dealing with the miss case (where attenuation is 0)
geometryPSRResolverState.attenuation *= radianceAttenuation;

// Add in Emissive contribution

const vec3 materialEmissiveRadiance = polymorphicSurfaceMaterialInteractionEvalEmissiveRadiance(polymorphicSurfaceMaterialInteraction);

geometryPSRResolverState.radiance += materialEmissiveRadiance * geometryPSRResolverState.attenuation;

// Evaluate PSR continuation logic

SurfaceMaterialInteractionPSRSample surfaceMaterialInteractionReflectionPSRSample;
Expand All @@ -1871,22 +1868,31 @@ void geometryPSRResolverVertex(
surfaceMaterialInteractionReflectionPSRSample, surfaceMaterialInteractionTransmissionPSRSample,
diffuseLayerWeight, penetrateSurface, useReflectionPSRSample, useTransmissionPSRSample, isLastBounce);

// Approximate the diffuse layer contribution
// Add non-direct lighting radiance contributions at the GBuffer hit
{
// Add in Emissive contribution

// Note: This code needs to come before the PSR attenuation is factored in otherwise the reflection or transmission attenuation will improperly
// modulate the diffuse layer contribution.
vec3 diffuseLayerRadiance = approximateDiffuseLayerRadiance(
surfaceInteraction, geometryPSRResolverState.portalSpace, diffuseLayerWeight);
const vec3 materialEmissiveRadiance = polymorphicSurfaceMaterialInteractionEvalEmissiveRadiance(polymorphicSurfaceMaterialInteraction);

diffuseLayerRadiance *= geometryPSRResolverState.attenuation;
geometryPSRResolverState.radiance += materialEmissiveRadiance * geometryPSRResolverState.attenuation;

if (cb.outputParticleLayer)
{
accumulateParticleBuffer(geometryPSRResolverState.pixelCoordinate, diffuseLayerRadiance);
}
else
{
geometryPSRResolverState.radiance += diffuseLayerRadiance;
// Approximate the diffuse layer contribution

// Note: This code needs to come before the PSR attenuation is factored in otherwise the reflection or transmission attenuation will improperly
// modulate the diffuse layer contribution.
vec3 diffuseLayerRadiance = approximateDiffuseLayerRadiance(
surfaceInteraction, geometryPSRResolverState.portalSpace, diffuseLayerWeight);

diffuseLayerRadiance *= geometryPSRResolverState.attenuation;

if (cb.outputParticleLayer)
{
accumulateParticleBuffer(geometryPSRResolverState.pixelCoordinate, diffuseLayerRadiance);
}
else
{
geometryPSRResolverState.radiance += diffuseLayerRadiance;
}
}

// Set the material medium index if a medium was entered or exited
Expand Down
Loading

0 comments on commit fb5dcc9

Please sign in to comment.