Skip to content

Commit

Permalink
Merge branch 'raytraceArgsCleanup' into 'main'
Browse files Browse the repository at this point in the history
Moving structs to the top of RayTrace args to avoid padding errors.

See merge request lightspeedrtx/dxvk-remix-nv!986
  • Loading branch information
MarkEHenderson committed Sep 18, 2024
2 parents 7bd91b0 + 3848ac3 commit e614f71
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
2 changes: 2 additions & 0 deletions src/dxvk/shaders/rtx/pass/gbuffer/gbuffer_bindings.slangh
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ uniform struct AliasedData0
RWTexture2D<float4> ReflectionPSRData0; // Output/Input
} aliasedData0;

// NOTE: these are split into 2x32 textures because they are all re-used for other data after the PSR pass is complete.
// See rtx_resources.cpp's use of `m_gbufferPSRData` for details.
layout(rg32ui, binding = GBUFFER_BINDING_REFLECTION_PSR_DATA_STORAGE_1)
RWTexture2D<uint2> ReflectionPSRData1; // Output/Input

Expand Down
54 changes: 30 additions & 24 deletions src/dxvk/shaders/rtx/pass/raytrace_args.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,37 @@ struct DomeLightArgs {

// Constant buffer
struct RaytraceArgs {
// NOTE: this class should be kept as all structs, then all non-structs. This is because the padding rules are different between C++ and shaders.
Camera camera;

// Note: Primary combined variant used in place of the primary direct denoiser when seperated direct/indirect
// lighting is not used.
NrdArgs primaryDirectNrd;
NrdArgs primaryIndirectNrd;
NrdArgs secondaryCombinedNrd;

// Note: Not tightly packed, meaning these indices will align with the Ray Portal Index in the
// Surface Material. Do note however due to elements being potentially "empty" each Ray Portal Hit Info
// must be checked to be empty or not before usage. Additionally both Ray Portals in a pair will match
// in state, either being present or not.
// The first `maxRayPortalCount` portals are for this frame, the second `maxRayPortalCount` are for the previous frame.
RayPortalHitInfo rayPortalHitInfos[maxRayPortalCount * 2];

VolumeArgs volumeArgs;
OpaqueMaterialArgs opaqueMaterialArgs;
TranslucentMaterialArgs translucentMaterialArgs;
ViewDistanceArgs viewDistanceArgs;

LightRangeInfo lightRanges[lightTypeCount];

TerrainArgs terrainArgs;
NeeCacheArgs neeCacheArgs;
DomeLightArgs domeLightArgs;

Camera renderTargetCamera;

// ------------------------- Structs above this line, non structs below this line -----------------------------------

uint frameIdx;
float ambientIntensity;
uint16_t lightCount;
Expand Down Expand Up @@ -159,32 +188,9 @@ struct RaytraceArgs {
uint debugView;
float vertexColorStrength;

// Note: Primary combined variant used in place of the primary direct denoiser when seperated direct/indirect
// lighting is not used.
NrdArgs primaryDirectNrd;
NrdArgs primaryIndirectNrd;
NrdArgs secondaryCombinedNrd;

vec4 debugKnob; // For temporary tuning in shaders, has a dedicated UI widget.

// Note: Not tightly packed, meaning these indices will align with the Ray Portal Index in the
// Surface Material. Do note however due to elements being potentially "empty" each Ray Portal Hit Info
// must be checked to be empty or not before usage. Additionally both Ray Portals in a pair will match
// in state, either being present or not.
// The first `maxRayPortalCount` portals are for this frame, the second `maxRayPortalCount` are for the previous frame.
RayPortalHitInfo rayPortalHitInfos[maxRayPortalCount * 2];

VolumeArgs volumeArgs;
OpaqueMaterialArgs opaqueMaterialArgs;
TranslucentMaterialArgs translucentMaterialArgs;
ViewDistanceArgs viewDistanceArgs;

LightRangeInfo lightRanges[lightTypeCount];

TerrainArgs terrainArgs;
NeeCacheArgs neeCacheArgs;
DomeLightArgs domeLightArgs;

// Values to use on a ray miss
vec3 clearColorNormal;
float clearColorDepth;
Expand Down Expand Up @@ -344,5 +350,5 @@ struct RaytraceArgs {
uint forceFirstHitInGBufferPass;

uint enableRaytracedRenderTarget;
Camera renderTargetCamera;
// NOTE: Add structs to the top section of RaytraceArgs, not the bottom.
};

0 comments on commit e614f71

Please sign in to comment.