@@ -99,6 +99,50 @@ const NrcMode g_nrcMode = NrcMode::Disabled;
99
99
100
100
#endif
101
101
102
+ #if !defined (NRC_USE_CUSTOM_BUFFER_ACCESSORS)
103
+ #define NRC_USE_CUSTOM_BUFFER_ACCESSORS 0
104
+ #endif
105
+
106
+ // Allow the integration to define its own type for a read-write structured buffer
107
+ // E.g. if you are doing a Pirate Engine integration, the correct syntax is
108
+ //
109
+ // Tharr be RW Structure Buffer <T> arrrrr
110
+ //
111
+ // So you would do
112
+ //
113
+ // #define NRC_RW_STRUCTURED_BUFFER(T) Tharr be RW Structure Buffer <T> arrrrr
114
+ //
115
+ #if ENABLE_NRC && !defined (NRC_RW_STRUCTURED_BUFFER)
116
+ #define NRC_RW_STRUCTURED_BUFFER (T) RWStructuredBuffer <T>
117
+ #endif
118
+
119
+ // Allow engine to override declaring buffers in the `NrcBuffers` struct as part
120
+ // of the `NrcContext` in the case that buffers within structs is not supported.
121
+ // In order to do this, the engine must first
122
+ //
123
+ // #define NRC_USE_CUSTOM_BUFFER_ACCESSORS 1
124
+ //
125
+ // and then it must declare the following macros to provide a read-write
126
+ // object that can be indexed with the square bracket operator
127
+ //
128
+ // NRC_BUFFER_QUERY_PATH_INFO
129
+ // NRC_BUFFER_TRAINING_PATH_INFO
130
+ // NRC_BUFFER_TRAINING_PATH_VERTICES
131
+ // NRC_BUFFER_QUERY_RADIANCE_PARAMS
132
+ // NRC_BUFFER_QUERY_COUNTERS_DATA
133
+ //
134
+ #if ENABLE_NRC && !NRC_USE_CUSTOM_BUFFER_ACCESSORS
135
+ #if defined (NRC_BUFFER_QUERY_PATH_INFO) || defined (NRC_BUFFER_TRAINING_PATH_INFO) || defined (NRC_BUFFER_TRAINING_PATH_VERTICES) || defined (NRC_BUFFER_QUERY_RADIANCE_PARAMS) || defined (NRC_BUFFER_QUERY_COUNTERS_DATA) || defined (NRC_BUFFER_DEBUG_TRAINING_PATH_INFO)
136
+ #error "If you enable any NRC_BUFFER macros, then please #define NRC_USE_CUSTOM_BUFFER_ACCESSORS 1"
137
+ #endif
138
+ // Define the standard NRC buffer accessor macros
139
+ #define NRC_BUFFER_QUERY_PATH_INFO context.buffers.queryPathInfo
140
+ #define NRC_BUFFER_TRAINING_PATH_INFO context.buffers.trainingPathInfo
141
+ #define NRC_BUFFER_TRAINING_PATH_VERTICES context.buffers.trainingPathVertices
142
+ #define NRC_BUFFER_QUERY_RADIANCE_PARAMS context.buffers.queryRadianceParams
143
+ #define NRC_BUFFER_QUERY_COUNTERS_DATA context.buffers.countersData
144
+ #endif
145
+
102
146
// Validate defines
103
147
#if !defined (ENABLE_NRC)
104
148
#error "Expected ENABLE_NRC to be defined to something"
@@ -338,7 +382,7 @@ NrcProgressState NrcUpdateOnHit(
338
382
// Finalize the previous vertex with the radiance and throughput that the path tracer accumulated
339
383
// during its previous iteration
340
384
const uint previousTrainingPathVertexIndex = trainingPathVertexIndex - 1 ;
341
- context.buffers.trainingPathVertices [previousTrainingPathVertexIndex] = NrcUpdateTrainingPathVertex (context.buffers.trainingPathVertices [previousTrainingPathVertexIndex], radiance, throughput);
385
+ NRC_BUFFER_TRAINING_PATH_VERTICES [previousTrainingPathVertexIndex] = NrcUpdateTrainingPathVertex (NRC_BUFFER_TRAINING_PATH_VERTICES [previousTrainingPathVertexIndex], radiance, throughput);
342
386
}
343
387
344
388
// Always update vertex counts. The pathState vertexCount variable mostly mirrors 'bounce' variable,
@@ -353,7 +397,7 @@ NrcProgressState NrcUpdateOnHit(
353
397
radiance = 0 ..xxx;
354
398
355
399
// Store path vertex
356
- context.buffers.trainingPathVertices [trainingPathVertexIndex] = NrcInitializePackedPathVertex (
400
+ NRC_BUFFER_TRAINING_PATH_VERTICES [trainingPathVertexIndex] = NrcInitializePackedPathVertex (
357
401
surfaceAttributes.roughness, surfaceAttributes.shadingNormal, surfaceAttributes.viewVector, surfaceAttributes.diffuseReflectance, surfaceAttributes.specularF0, surfaceAttributes.encodedPosition);
358
402
359
403
bool terminate = (bounce == context.constants.maxPathVertices - 1 ) || //< Is this path at last vertex already? If yes, we can terminate.
@@ -395,7 +439,7 @@ NrcProgressState NrcUpdateOnHit(
395
439
prefixThroughput = max (0.0f , NrcSanitizeNansInfs (prefixThroughput));
396
440
pathState.packedPrefixThroughput = NrcEncodeLogLuvHdr (prefixThroughput);
397
441
398
- pathState.queryBufferIndex = NrcIncrementCounter (context.buffers.countersData , NrcCounter::Queries);
442
+ pathState.queryBufferIndex = NrcIncrementCounter (NRC_BUFFER_QUERY_COUNTERS_DATA , NrcCounter::Queries);
399
443
400
444
NrcRadianceParams params;
401
445
params.encodedPosition = surfaceAttributes.encodedPosition;
@@ -405,7 +449,7 @@ NrcProgressState NrcUpdateOnHit(
405
449
params.albedo = surfaceAttributes.diffuseReflectance;
406
450
params.specular = surfaceAttributes.specularF0;
407
451
408
- context.buffers.queryRadianceParams [pathState.queryBufferIndex] = params;
452
+ NRC_BUFFER_QUERY_RADIANCE_PARAMS [pathState.queryBufferIndex] = params;
409
453
410
454
// Terminate now if the cache already includes direct reflected radiance.
411
455
// Otherwise, we will terminate later, after NEE and the scatter ray has been computed.
@@ -475,7 +519,7 @@ void NrcWriteFinalPathInfo(in NrcContext context,
475
519
const uint vertexIndex = vertexCount - 1 ;
476
520
const uint arrayIndex = NrcCalculateTrainingPathVertexIndex (
477
521
context.constants.trainingDimensions, context.pixelIndex, vertexIndex, context.constants.maxPathVertices);
478
- context.buffers.trainingPathVertices [arrayIndex] = NrcUpdateTrainingPathVertex (context.buffers.trainingPathVertices [arrayIndex], radiance, throughput);
522
+ NRC_BUFFER_TRAINING_PATH_VERTICES [arrayIndex] = NrcUpdateTrainingPathVertex (NRC_BUFFER_TRAINING_PATH_VERTICES [arrayIndex], radiance, throughput);
479
523
480
524
// Create self-training records for _all_ training paths, including unbiased ones.
481
525
// Without self-training, each training vertex position within the path would matter.
@@ -485,10 +529,10 @@ void NrcWriteFinalPathInfo(in NrcContext context,
485
529
// this complicates the task of the network.
486
530
if (!NrcGetFlag (pathState, nrcPathFlagHasExitedScene) && (context.constants.maxPathVertices > 1 )) // && !NrcGetFlag(pathState, nrcPathFlagIsUnbiased))
487
531
{
488
- NrcPathVertex vertex = NrcUnpackPathVertex (context.buffers.trainingPathVertices [arrayIndex], radiance, throughput);
489
- pathState.queryBufferIndex = NrcIncrementCounter (context.buffers.countersData , NrcCounter::Queries);
532
+ NrcPathVertex vertex = NrcUnpackPathVertex (NRC_BUFFER_TRAINING_PATH_VERTICES [arrayIndex], radiance, throughput);
533
+ pathState.queryBufferIndex = NrcIncrementCounter (NRC_BUFFER_QUERY_COUNTERS_DATA , NrcCounter::Queries);
490
534
491
- context.buffers.queryRadianceParams [pathState.queryBufferIndex] = NrcCreateRadianceParams (vertex);
535
+ NRC_BUFFER_QUERY_RADIANCE_PARAMS [pathState.queryBufferIndex] = NrcCreateRadianceParams (vertex);
492
536
}
493
537
}
494
538
@@ -498,7 +542,7 @@ void NrcWriteFinalPathInfo(in NrcContext context,
498
542
unpackedPathInfo.queryBufferIndex = pathState.queryBufferIndex;
499
543
500
544
const uint trainingPathIndex = NrcCalculateTrainingPathIndex (context.constants.trainingDimensions, context.pixelIndex);
501
- context.buffers.trainingPathInfo [trainingPathIndex] = NrcPackTrainingPathInfo (unpackedPathInfo);
545
+ NRC_BUFFER_TRAINING_PATH_INFO [trainingPathIndex] = NrcPackTrainingPathInfo (unpackedPathInfo);
502
546
503
547
}
504
548
else
@@ -515,7 +559,7 @@ void NrcWriteFinalPathInfo(in NrcContext context,
515
559
packedQueryPathInfo.prefixThroughput = pathState.packedPrefixThroughput;
516
560
packedQueryPathInfo.queryBufferIndex = pathState.queryBufferIndex;
517
561
518
- context.buffers.queryPathInfo [queryPathIndex] = packedQueryPathInfo;
562
+ NRC_BUFFER_QUERY_PATH_INFO [queryPathIndex] = packedQueryPathInfo;
519
563
}
520
564
}
521
565
0 commit comments