Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Hineven committed May 18, 2024
1 parent feee415 commit 6548155
Show file tree
Hide file tree
Showing 11 changed files with 619 additions and 679 deletions.
164 changes: 106 additions & 58 deletions src/core/src/render_techniques/migi/migi.comp

Large diffs are not rendered by default.

395 changes: 175 additions & 220 deletions src/core/src/render_techniques/migi/migi.cpp

Large diffs are not rendered by default.

44 changes: 33 additions & 11 deletions src/core/src/render_techniques/migi/migi.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,27 @@ class MIGI : public RenderTechnique
struct MIGIResources
{

// Screen coverage of the cache, used for basis spawn
// fp16x2
GfxTexture cache_coverage {};
// Probe header, uint32 per probe
GfxTexture probe_header_packed [2];
// Probe screen position, 2xuint16 packed in uint32
GfxTexture probe_screen_position [2];
// Probe linear depth 1xfloat32
GfxTexture probe_linear_depth [2];
// Probe world position 3xfloat32
GfxTexture probe_world_position [2];
// Probe world normal 2xunorm16
GfxTexture probe_normal [2];

// Probe irradiance 4xfloat16
GfxTexture probe_irradiance [2];

// Tile adaptive probe count uint16
GfxTexture tile_adaptive_probe_count [2];
// Tile adaptive probe index uint16
GfxTexture tile_adaptive_probe_index [2];

// Update error used to guide update ray spawnning
// fp16x2 with mipmaps up to the tile size (1/8 res), reprojection is done across frames
// fp16x2
GfxTexture update_error_splat [2]{};

// Hierarchical z-buffer
Expand Down Expand Up @@ -103,6 +118,7 @@ class MIGI : public RenderTechnique
} buf_{};

bool initResources (const CapsaicinInternal &capsaicin);
void releaseResources () ;

struct MIGIKernels {

Expand All @@ -111,6 +127,8 @@ class MIGI : public RenderTechnique
GfxKernel PrecomputeHiZ_min {};
GfxKernel PrecomputeHiZ_max {};

GfxKernel PurgeTiles {};
GfxKernel ClearCounters {};
GfxKernel SSRC_ClearCounters {};
GfxKernel SSRC_AllocateUniformProbes {};
GfxKernel SSRC_AllocateAdaptiveProbes[SSRC_MAX_ADAPTIVE_PROBE_LAYERS] {};
Expand Down Expand Up @@ -139,7 +157,11 @@ class MIGI : public RenderTechnique

} kernels_;

// Called before initResources
bool initKernels (const CapsaicinInternal & capsaicin);
// Called after initResources
bool initGraphicsKernels (const CapsaicinInternal & capsaicin);
void releaseKernels () ;

void clearHashGridCache () ;

Expand All @@ -162,25 +184,25 @@ class MIGI : public RenderTechnique

GfxSbt sbt_ {};

// If the render dimensions have changed.
bool need_resize_ {true};
// If the hash grid cache debug view mode changed.
bool need_reload_hash_grid_cache_debug_view_ {true};
// If the kernel needs to be reloaded.
// Note: the kernels is loaded upon initialization, so we do not need to set it to true.
bool need_reload_kernel_ {false};
// If the render resources should be reallocated.
bool need_reload_memory_ {false};
// If the screen space cache needs to be reset.
mutable bool need_reset_screen_space_cache_ {true};
// If the hash grid cache needs to be reset.
bool need_reset_hash_grid_cache_ {true};
// If the reservoirs need to be reset.
bool need_reset_world_space_reservoirs_ {true};
// If the screen space cache needs to be reset.
mutable bool need_reset_screen_space_cache_ {true};

bool readback_pending_ [kGfxConstant_BackBufferCount] {};
MIGIReadBackValues readback_values_;

uint32_t internal_frame_index_ {};

MIGI_Constants previous_constants_ {};
};

}

#endif // CAPSAICIN_MIGI_H
12 changes: 4 additions & 8 deletions src/core/src/render_techniques/migi/migi_common.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ struct ProbeHeader {
// Screen pixel position of the probe
int2 ScreenPosition;
int BasisOffset;
// 0: 1, 1: 2, 2: 4, 3: 8, no larger than 8
// 0: 0, 1: 1, 2: 2, 3: 4, 4: 8, no larger than 8
int Class;
bool bValid;
float LinearDepth;
Expand Down Expand Up @@ -160,7 +160,7 @@ struct MIGI_Constants {
// Current NDC -> Prev NDC
float4x4 Reprojection;
// Prev NDC -> Current NDC
float4x4 ForwardProjection;
float4x4 ForwardReprojection;

float3 PreviousCameraPosition;

Expand All @@ -180,8 +180,6 @@ struct MIGI_Constants {

// Budget for update rays
int UpdateRayBudget;
// Pad the fraction for ray allocation among probes, 0: error propotional, 1: avg.
float UpdateRayFractionPadding;

// SSRC parameters
// Maximum number of adaptive probes to allocate
Expand All @@ -201,10 +199,6 @@ struct MIGI_Constants {
uint DebugVisualizeChannel;
uint DebugVisualizeIncidentRadianceNumPoints;

// Replace FrameSeed under certain conditions
uint DebugFreezeFrameSeed;
uint DebugFreezeFrameSeedValue;

float DebugTonemapExposure;
uint2 DebugCursorPixelCoords;

Expand All @@ -229,6 +223,8 @@ static_assert((1 << SSRC_TILE_SIZE_L2) == SSRC_TILE_SIZE, "SSRC_TILE_SIZE != 1<<
#define SSRC_MAX_NUM_BASIS_PER_PROBE 8
#define SSRC_MAX_NUM_UPDATE_RAY_PER_PROBE 128

#define SSRC_MAX_ADAPTIVE_PROBE_LAYERS 2

#ifdef __cplusplus
}// namespace Capsaicin
#endif
Expand Down
36 changes: 6 additions & 30 deletions src/core/src/render_techniques/migi/migi_fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,12 @@ struct MIGIRenderOptions {

bool debug_freeze_frame_seed {false};

bool reset_screen_space_cache {false};
bool reset_screen_space_cache {false};

uint32_t SSRC_max_update_ray_count {4 * 1024 * 1024};
// Maximum number of basis active in the screen space radiance cache
uint32_t SSRC_max_basis_count {256 * 1024};
// Min coverage for basis spawn
float SSRC_basis_spawn_coverage_threshold {3.f};
// Radius control for basis injection
float SSRC_min_weight_E {0.08f};
// Default initial W radius for newly generated basis
float SSRC_initial_W_radius {9.f};
// Resolution of the disk when doing rasterization for tile index injection
uint32_t SSRC_CR_disk_vertex_count {12};

// Ray budget for each frame
uint32_t SSRC_update_ray_budget {2 * 1024 * 1024};
// Used to pad W for cache coverage computation to prevent over allocation on surfaces parallel to the view direction
float SSRC_W_coverage_padding {0.05f};

// Used to adjust the impact of importance sampling on ray allocation among tiles. 1: avg, 0: importance
float SSRC_tile_fraction_padding {0.2f};
uint32_t SSRC_max_adaptive_probe_count {32 * 1024};
uint32_t SSRC_max_basis_count {4 * 1024 * 1024};
uint32_t SSRC_max_probe_count {};

struct {
uint32_t num_buckets_l2 {12}; // 1<<12 = 4096
Expand All @@ -72,24 +57,15 @@ struct MIGIRenderOptions {
// If we disable importance sampling when generate update rays.
// When enabled, rays are uniformly sampled in the hemisphere.
bool no_importance_sampling = true;
// If we use fixed step size in gradient descent.
bool fixed_step_size = false;
// Whether to place adaptive probes
bool no_adaptive_probes = false;
// Whether to render indirect lighting (using the hash grid cache)
bool enable_indirect = true;
// Whether to freeze the allocation and deallocation of basis for visualization
bool freeze_basis_allocation {false};
// Guess the initial W (basis radius) when generating new basis
bool nonuniform_initial_w {false};

float cache_update_learing_rate = 0.02f;
bool cache_update_SG_color {true};
bool cache_update_SG_direction {false};
bool cache_update_SG_lambda {false};
bool cache_update_W_alpha {false};
bool cache_update_W_lambda {false};

// Whether to shade with geometry normals only
bool shading_with_geometry_normal {false};

std::string active_debug_view {};
bool debug_view_switched {false};
Expand Down
4 changes: 0 additions & 4 deletions src/core/src/render_techniques/migi/migi_inc.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,4 @@ ConstantBuffer<MIGI_Constants> MI;
RWStructuredBuffer<float3> g_RWDebugCursorWorldPosBuffer;
RWStructuredBuffer<float3> g_RWDebugVisualizeIncidentRadianceBuffer;


// Varying parameters for multiple invocations of the same kernel
int g_AdaptiveProbeDownsampleFactor;

#endif // MIGI_SHARED_PARAMETERS_HLSL
Loading

0 comments on commit 6548155

Please sign in to comment.