Skip to content

Commit

Permalink
Merge branch 'pomNullCheck' into 'main'
Browse files Browse the repository at this point in the history
REMIX-3574 run full safety checks before running POM

See merge request lightspeedrtx/dxvk-remix-nv!1055
  • Loading branch information
MarkEHenderson committed Oct 8, 2024
2 parents af6c832 + 2f79138 commit 34cc21a
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 29 deletions.
5 changes: 4 additions & 1 deletion src/dxvk/rtx_render/rtx_debug_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,10 @@ namespace dxvk {
{DEBUG_VIEW_SCROLLING_LINE, "Scrolling Line"},
{DEBUG_VIEW_POM_ITERATIONS, "POM Iterations"},
{DEBUG_VIEW_POM_DIRECT_HIT_POS, "POM Direct Hit Position (Tangent Space)"},
{DEBUG_VIEW_HEIGHT_MAP, "Height Map Value"},
{DEBUG_VIEW_HEIGHT_MAP, "Height Map Value",
"Valid values will be greyscale."
"\nBlue, Green, or Red pixels indicate errors happened"
"\nwhen passing POM state between passes."},
{DEBUG_VIEW_RAYTRACED_RENDER_TARGET_GEOMETRY, "Raytraced Render Target Geometry" },
{DEBUG_VIEW_RAYTRACED_RENDER_TARGET_DIRECT, "Hit Raytraced Render Target in Direct"},
{DEBUG_VIEW_RAYTRACED_RENDER_TARGET_INDIRECT, "Hit Raytraced Render Target in Indirect"},
Expand Down
63 changes: 50 additions & 13 deletions src/dxvk/shaders/rtx/algorithm/integrator_indirect.slangh
Original file line number Diff line number Diff line change
Expand Up @@ -994,20 +994,57 @@ void integrateIndirectPath(
if (pathState.continuePath && cb.pomEnableIndirectLighting && geometryFlags.pomOpaqueSurfaceEncountered)
{
uint16_t primarySurfaceIndex = uint16_t(SharedSurfaceIndex[pixelCoordinate]);
const MemoryPolymorphicSurfaceMaterial memoryPolymorphicSurfaceMaterial = surfaceMaterials[primarySurfaceIndex];
OpaqueSurfaceMaterial opaqueSurfaceMaterial = opaqueSurfaceMaterialCreate(primarySurfaceIndex, memoryPolymorphicSurfaceMaterial);

MinimalSurfaceInteraction minimalSurfaceInteraction = minimalSurfaceInteractionReadFromGBuffer(
pixelCoordinate, indirectPathTextures.PrimaryWorldPositionWorldTriangleNormal);

const float pomThroughput = opaqueSurfaceMaterialInteractionCalcHeightThroughput(
minimalSurfaceInteraction, pathState.direction, opaqueSurfaceMaterial.heightTextureIndex,
opaqueSurfaceMaterial.samplerIndex, SharedTextureCoord[pixelCoordinate], opaqueSurfaceMaterial.displaceIn
);

if (cb.debugView == DEBUG_VIEW_HEIGHT_MAP)
{
if (primarySurfaceIndex != BINDING_INDEX_INVALID)
{
const MemoryPolymorphicSurfaceMaterial memoryPolymorphicSurfaceMaterial = surfaceMaterials[primarySurfaceIndex];
const uint8_t polymorphicType = memoryPolymorphicSurfaceMaterialGetTypeHelper(memoryPolymorphicSurfaceMaterial);
if (polymorphicType == surfaceMaterialTypeOpaque)
{
OpaqueSurfaceMaterial opaqueSurfaceMaterial = opaqueSurfaceMaterialCreate(primarySurfaceIndex, memoryPolymorphicSurfaceMaterial);

if (opaqueSurfaceMaterial.heightTextureIndex == BINDING_INDEX_INVALID)
{
storeInDebugView(getDispatchRaysIndex().xy, float3(0.5f, 0.f, 0.f));
}
}
else
{
storeInDebugView(getDispatchRaysIndex().xy, float3(0.f, 0.5f, 0.f));
}
}
else
{
storeInDebugView(getDispatchRaysIndex().xy, float3(0.f, 0.f, 0.5f));
}
}

accumulateThroughput(pathState, pomThroughput);
pathState.continuePath = any(pathState.throughput > 0.001h);
pathState.continueResolving = pathState.continuePath;
if (primarySurfaceIndex != BINDING_INDEX_INVALID)
{
const MemoryPolymorphicSurfaceMaterial memoryPolymorphicSurfaceMaterial = surfaceMaterials[primarySurfaceIndex];
const uint8_t polymorphicType = memoryPolymorphicSurfaceMaterialGetTypeHelper(memoryPolymorphicSurfaceMaterial);
if (polymorphicType == surfaceMaterialTypeOpaque)
{
OpaqueSurfaceMaterial opaqueSurfaceMaterial = opaqueSurfaceMaterialCreate(primarySurfaceIndex, memoryPolymorphicSurfaceMaterial);

if (opaqueSurfaceMaterial.heightTextureIndex != BINDING_INDEX_INVALID)
{
MinimalSurfaceInteraction minimalSurfaceInteraction = minimalSurfaceInteractionReadFromGBuffer(
pixelCoordinate, indirectPathTextures.PrimaryWorldPositionWorldTriangleNormal);

const float pomThroughput = opaqueSurfaceMaterialInteractionCalcHeightThroughput(
minimalSurfaceInteraction, pathState.direction, opaqueSurfaceMaterial.heightTextureIndex,
opaqueSurfaceMaterial.samplerIndex, SharedTextureCoord[pixelCoordinate], opaqueSurfaceMaterial.displaceIn
);

accumulateThroughput(pathState, pomThroughput);
pathState.continuePath = any(pathState.throughput > 0.001h);
pathState.continueResolving = pathState.continuePath;
}
}
}
}
#endif
}
Expand Down
66 changes: 51 additions & 15 deletions src/dxvk/shaders/rtx/algorithm/visibility.slangh
Original file line number Diff line number Diff line change
Expand Up @@ -454,23 +454,59 @@ VisibilityResult traceVisibilityRay<let VisibilityMode : uint>(
float pomAttenuation = 1.0f;
if ((VisibilityMode & visibilityModeEnablePom) && cb.pomMode != DisplacementMode::Off && pomOpaqueSurfaceEncountered)
{
const MemoryPolymorphicSurfaceMaterial memoryPolymorphicSurfaceMaterial = surfaceMaterials[primarySurfaceIndex];
OpaqueSurfaceMaterial opaqueSurfaceMaterial = opaqueSurfaceMaterialCreate(primarySurfaceIndex, memoryPolymorphicSurfaceMaterial);

pomAttenuation = opaqueSurfaceMaterialInteractionCalcHeightThroughput(
minimalSurfaceInteraction, visibilityRay.direction, opaqueSurfaceMaterial.heightTextureIndex,
opaqueSurfaceMaterial.samplerIndex, texCoords, opaqueSurfaceMaterial.displaceIn
);
if (cb.debugView == DEBUG_VIEW_HEIGHT_MAP)
{
if (primarySurfaceIndex != BINDING_INDEX_INVALID)
{
const MemoryPolymorphicSurfaceMaterial memoryPolymorphicSurfaceMaterial = surfaceMaterials[primarySurfaceIndex];
const uint8_t polymorphicType = memoryPolymorphicSurfaceMaterialGetTypeHelper(memoryPolymorphicSurfaceMaterial);
if (polymorphicType == surfaceMaterialTypeOpaque)
{
OpaqueSurfaceMaterial opaqueSurfaceMaterial = opaqueSurfaceMaterialCreate(primarySurfaceIndex, memoryPolymorphicSurfaceMaterial);

if (opaqueSurfaceMaterial.heightTextureIndex == BINDING_INDEX_INVALID)
{
storeInDebugView(getDispatchRaysIndex().xy, float3(0.5f, 0.f, 0.f));
}
}
else
{
storeInDebugView(getDispatchRaysIndex().xy, float3(0.f, 0.5f, 0.f));
}
}
else
{
storeInDebugView(getDispatchRaysIndex().xy, float3(0.f, 0.f, 0.5f));
}
}

if (pomAttenuation <= 0.001f)
if (primarySurfaceIndex != BINDING_INDEX_INVALID)
{
VisibilityResult result;
result.attenuation = pomAttenuation;
result.hasOpaqueHit = true;
result.rayDirection = visibilityRay.direction;
result.hitDistance = visibilityRay.tMax; // TODO should refactor POM code to return?
result.hasPOMHit = true;
return result;
const MemoryPolymorphicSurfaceMaterial memoryPolymorphicSurfaceMaterial = surfaceMaterials[primarySurfaceIndex];
const uint8_t polymorphicType = memoryPolymorphicSurfaceMaterialGetTypeHelper(memoryPolymorphicSurfaceMaterial);
if (polymorphicType == surfaceMaterialTypeOpaque)
{
OpaqueSurfaceMaterial opaqueSurfaceMaterial = opaqueSurfaceMaterialCreate(primarySurfaceIndex, memoryPolymorphicSurfaceMaterial);

if (opaqueSurfaceMaterial.heightTextureIndex != BINDING_INDEX_INVALID)
{
pomAttenuation = opaqueSurfaceMaterialInteractionCalcHeightThroughput(
minimalSurfaceInteraction, visibilityRay.direction, opaqueSurfaceMaterial.heightTextureIndex,
opaqueSurfaceMaterial.samplerIndex, texCoords, opaqueSurfaceMaterial.displaceIn
);

if (pomAttenuation <= 0.001f)
{
VisibilityResult result;
result.attenuation = pomAttenuation;
result.hasOpaqueHit = true;
result.rayDirection = visibilityRay.direction;
result.hitDistance = visibilityRay.tMax; // TODO should refactor POM code to return?
result.hasPOMHit = true;
return result;
}
}
}
}
}
#endif
Expand Down

0 comments on commit 34cc21a

Please sign in to comment.