Skip to content

Commit

Permalink
GPU perf optimization: Surface data
Browse files Browse the repository at this point in the history
See merge request lightspeedrtx/dxvk-remix-nv!921
  • Loading branch information
AlexDunn committed Aug 2, 2024
1 parent b6ad250 commit d94d63a
Show file tree
Hide file tree
Showing 19 changed files with 427 additions and 292 deletions.
2 changes: 1 addition & 1 deletion src/dxvk/rtx_render/rtx_materials.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ struct RtSurface {
writeGPUHelper(data, offset, packedHash);

writeGPUHelper(data, offset, positionOffset);
writeGPUHelper(data, offset, objectPickingValue);
writeGPUHelper(data, offset, normalOffset);
writeGPUHelper(data, offset, texcoordOffset);
writeGPUHelper(data, offset, color0Offset);
writeGPUHelper(data, offset, objectPickingValue);

writeGPUHelperExplicit<1>(data, offset, positionStride);
writeGPUHelperExplicit<1>(data, offset, normalStride);
Expand Down
3 changes: 2 additions & 1 deletion src/dxvk/shaders/rtx/algorithm/integrator_indirect.slangh
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,9 @@ void integratePathVertex(
RayInteraction rayInteraction;
Surface surface;
SurfaceInteraction surfaceInteraction;
surfaceInteraction.position = pathState.origin;
PolymorphicSurfaceMaterialInteraction polymorphicSurfaceMaterialInteraction;

surfaceInteraction.position = pathState.origin;

// Todo: Remove hack thing
HackGenericState hackState;
Expand Down
6 changes: 2 additions & 4 deletions src/dxvk/shaders/rtx/algorithm/nee_cache_light.slangh
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ struct NEECacheUtils

static Surface getSurface(int surfaceIndex)
{
SURFACE_CREATE_READ(surface0, surfaceIndex, surfaces);
Surface surface = surface0;
Surface surface = surfaces[uint(surfaceIndex)];
#if USE_SIMIPLIFIED_MODEL
// Don't override following settings because they may affect some emissive objects
// surface.isEmissive = false;
Expand Down Expand Up @@ -296,8 +295,7 @@ struct NEECacheUtils

static void calculateTriangleLightIntensity(int surfaceIndex, int primitiveIndex, out vec3 triangleCenter, out f16vec3 triangleNormal, out vec3 lightIntensity)
{
SURFACE_CREATE_READ(surface0, surfaceIndex, surfaces);
Surface surface = surface0;
const Surface surface = surfaces[uint(surfaceIndex)];
RayInteraction rayInteracton = {};
rayInteracton.frontHit = true;
rayInteracton.barycentricCoordinates = barycentricsToUint(uvToBarycentrics(vec2(1.0 / 3.0)));
Expand Down
6 changes: 2 additions & 4 deletions src/dxvk/shaders/rtx/algorithm/resolve.slangh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "rtx/algorithm/resolve.h"
#include "rtx/utility/common.slangh"
#include "rtx/utility/math.slangh"
#include "rtx/utility/buffer_helpers.slangh"
#include "rtx/utility/packing.slangh"
#include "rtx/utility/froxel.slangh"
#include "rtx/concept/ray/ray.slangh"
Expand Down Expand Up @@ -354,9 +353,8 @@ void resolveVertex(

// Create a Surface and Surface Interaction from the hit

SURFACE_CREATE_READ(tempSurface, rayInteraction.surfaceIndex, surfaces);
surface = surfaces[uint(rayInteraction.surfaceIndex)];

surface = tempSurface;
surfaceInteraction = surfaceInteractionCreate(surface, rayInteraction, ray);

// Process user clip planes and view distance
Expand Down Expand Up @@ -942,7 +940,7 @@ void resolveVertexUnordered(
surfaceInteraction.vertexColor = vertexColor;
}

SURFACE_CREATE_READ(surface, rayInteraction.surfaceIndex, surfaces);
const Surface surface = surfaces[uint(rayInteraction.surfaceIndex)];

if (isTriangle)
surfaceInteraction = surfaceInteractionCreate(surface, rayInteraction, ray);
Expand Down
6 changes: 3 additions & 3 deletions src/dxvk/shaders/rtx/algorithm/visibility.slangh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ f16vec3 handleVisibilityVertex(Ray ray, RayHitInfo rayHitInfo, uint8_t visibilit
return 1.0;
}

SURFACE_CREATE_READ(surface, surfaceIndex, surfaces);
const Surface surface = surfaces[uint(surfaceIndex)];

if (surfaceIsDecal(surface))
// Decals do not cast shadows
Expand Down Expand Up @@ -189,12 +189,12 @@ float16_t getRayPortalTransparency(
// Also note that this does not set up texture gradients properly so this will always likely sample from the lowest mip level
// which is also probably not great for performance.

Surface surface;
Surface surface = (Surface)0;
surface.spriteSheetRows = portal.spriteSheetRows;
surface.spriteSheetCols = portal.spriteSheetCols;
surface.spriteSheetFPS = portal.spriteSheetFPS;

SurfaceInteraction surfaceInteraction;
SurfaceInteraction surfaceInteraction = (SurfaceInteraction)0;
surfaceInteraction.textureCoordinates = uv * 0.5f + 0.5f;
surfaceInteraction.textureGradientX = vec2(0.0f);
surfaceInteraction.textureGradientY = vec2(0.0f);
Expand Down
Loading

0 comments on commit d94d63a

Please sign in to comment.