Skip to content

Commit 32e56f7

Browse files
Adjust ray origin offsets and continuation thresholds, also get rid of firstIndexSSBO (cause I shoved it into instance data)
1 parent 92d552d commit 32e56f7

File tree

5 files changed

+14
-18
lines changed

5 files changed

+14
-18
lines changed

examples_tests/22.RaytracedAO/Renderer.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,6 @@ Renderer::InitializationData Renderer::initSceneObjects(const SAssetBundle& mesh
336336
cullData.reserve(batchInstanceBoundTotal);
337337

338338
newInstanceDataBuffer = core::make_smart_refctd_ptr<ICPUBuffer>(sizeof(ext::MitsubaLoader::instance_data_t)*batchInstanceBoundTotal);
339-
retval.mdiFirstIndices.resize(batchInstanceBoundTotal);
340339
}
341340
// actually commit the physical memory, compute batches and set up instance data
342341
{
@@ -346,7 +345,6 @@ Renderer::InitializationData Renderer::initSceneObjects(const SAssetBundle& mesh
346345
auto* vertexPtr = reinterpret_cast<const float*>(cpump->getPackerDataStore().vertexBuffer->getPointer());
347346
auto* mdiPtr = reinterpret_cast<DrawElementsIndirectCommand_t*>(cpump->getPackerDataStore().MDIDataBuffer->getPointer());
348347
auto* newInstanceData = reinterpret_cast<ext::MitsubaLoader::instance_data_t*>(newInstanceDataBuffer->getPointer());
349-
auto batchFirstIndexIt = retval.mdiFirstIndices.begin();
350348

351349
constexpr uint32_t kIndicesPerTriangle = 3u;
352350
core::vector<CPUMeshPacker::CombinedDataOffsetTable> cdot(mdiBoundMax);
@@ -455,7 +453,6 @@ Renderer::InitializationData Renderer::initSceneObjects(const SAssetBundle& mesh
455453
}
456454

457455
newInstanceData++;
458-
*(batchFirstIndexIt++) = firstIndex;
459456
}
460457
for (auto j=thisShapeInstancesBeginIx; j!=rrInstances.size(); j++)
461458
rr->AttachShape(rrInstances[j]);
@@ -484,7 +481,6 @@ Renderer::InitializationData Renderer::initSceneObjects(const SAssetBundle& mesh
484481
);
485482
instanceDataDescPtr->buffer = {0u,cullData.size()*sizeof(ext::MitsubaLoader::instance_data_t)};
486483
instanceDataDescPtr->desc = std::move(newInstanceDataBuffer); // TODO: trim the buffer
487-
retval.mdiFirstIndices.resize(cullData.size());
488484
{
489485
auto gpump = core::make_smart_refctd_ptr<GPUMeshPacker>(m_driver,cpump.get());
490486
const auto& dataStore = gpump->getPackerDataStore();
@@ -874,7 +870,10 @@ void Renderer::init(const SAssetBundle& meshes, core::smart_refctd_ptr<ICPUBuffe
874870
auto createEmptyInteropBufferAndSetUpInfo = [&](IGPUDescriptorSet::SDescriptorInfo* info, InteropBuffer& interopBuffer, size_t size) -> void
875871
{
876872
if (static_cast<COpenGLDriver*>(m_driver)->runningInRenderdoc()) // makes Renderdoc capture the modifications done by OpenCL
873+
{
877874
interopBuffer.buffer = m_driver->createUpStreamingGPUBufferOnDedMem(size);
875+
//interopBuffer.buffer->getBoundMemory()->mapMemoryRange(IDriverMemoryAllocation::EMCAF_WRITE,{0u,size})
876+
}
878877
else
879878
interopBuffer.buffer = m_driver->createDeviceLocalGPUBufferOnDedMem(size);
880879
interopBuffer.asRRBuffer = m_rrManager->linkBuffer(interopBuffer.buffer.get(), CL_MEM_READ_ONLY);
@@ -912,7 +911,6 @@ void Renderer::init(const SAssetBundle& meshes, core::smart_refctd_ptr<ICPUBuffe
912911
core::smart_refctd_ptr<IGPUBuffer> _staticViewDataBuffer;
913912
{
914913
_staticViewDataBuffer = createFilledBufferAndSetUpInfoFromStruct(infos+0,m_staticViewData);
915-
createFilledBufferAndSetUpInfoFromVector(infos+1,initData.mdiFirstIndices);
916914
{
917915
constexpr auto ScrambleStateChannels = 2u;
918916
auto tmpBuff = m_driver->createCPUSideGPUVisibleGPUBufferOnDedMem(sizeof(uint32_t)*ScrambleStateChannels*renderPixelCount);
@@ -1369,6 +1367,7 @@ uint32_t Renderer::traceBounce(uint32_t raycount)
13691367
m_driver->copyBuffer(m_rayCountBuffer.get(),m_littleDownloadBuffer.get(),sizeof(uint32_t)*m_raytraceCommonData.rayCountWriteIx,0u,sizeof(uint32_t));
13701368
static_assert(core::isPoT(RAYCOUNT_N_BUFFERING),"Raycount Buffer needs to be PoT sized!");
13711369
glFinish(); // sync CPU to GL
1370+
//auto start = std::chrono::steady_clock::now();
13721371
const uint32_t nextTraceRaycount = *reinterpret_cast<uint32_t*>(m_littleDownloadBuffer->getBoundMemory()->getMappedPointer());
13731372
if (nextTraceRaycount==0u)
13741373
return 0u;
@@ -1396,6 +1395,9 @@ uint32_t Renderer::traceBounce(uint32_t raycount)
13961395
ocl::COpenCLHandler::ocl.pclEnqueueReleaseGLObjects(commandQueue, objCount, clObjects, 1u, &raycastDone, &released);
13971396
ocl::COpenCLHandler::ocl.pclFlush(commandQueue);
13981397
ocl::COpenCLHandler::ocl.pclWaitForEvents(1u,&released);
1398+
//const auto elapsed = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now()-start).count();
1399+
//if (elapsed>100000ull)
1400+
//printf("Path Vertex: %d took %d us\n",m_raytraceCommonData.depth,elapsed);
13991401
return nextTraceRaycount;
14001402
}
14011403
else

examples_tests/22.RaytracedAO/Renderer.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Renderer : public nbl::core::IReferenceCounted, public nbl::core::Interfac
6767

6868
struct InitializationData
6969
{
70-
InitializationData() : mdiFirstIndices(), lights(),lightCDF(),globalMeta(nullptr) {}
70+
InitializationData() : lights(),lightCDF(),globalMeta(nullptr) {}
7171
InitializationData(InitializationData&& other) : InitializationData()
7272
{
7373
operator=(std::move(other));
@@ -76,14 +76,12 @@ class Renderer : public nbl::core::IReferenceCounted, public nbl::core::Interfac
7676

7777
inline InitializationData& operator=(InitializationData&& other)
7878
{
79-
mdiFirstIndices = std::move(other.mdiFirstIndices);
8079
lights = std::move(other.lights);
8180
lightCDF = std::move(other.lightCDF);
8281
globalMeta = other.globalMeta;
8382
return *this;
8483
}
8584

86-
nbl::core::vector<uint32_t> mdiFirstIndices;
8785
nbl::core::vector<SLight> lights;
8886
union
8987
{

examples_tests/22.RaytracedAO/closestHit.comp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void main()
6565
// clear the hit success flag
6666
intersections[gl_GlobalInvocationID.x].shapeid = -1;
6767

68-
const uvec3 indices = get_triangle_indices(batchInstanceGUID,triangleID);
68+
const uvec3 indices = get_triangle_indices(batchInstanceData,triangleID);
6969

7070
// positions
7171
mat2x3 dPdBary_error; vec3 lastVxPos_error;

examples_tests/22.RaytracedAO/raygen.comp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void main()
4646

4747
//
4848
const nbl_glsl_ext_Mitsuba_Loader_instance_data_t batchInstanceData = InstData.data[batchInstanceGUID];
49-
const uvec3 indices = get_triangle_indices(batchInstanceGUID,triangleID);
49+
const uvec3 indices = get_triangle_indices(batchInstanceData,triangleID);
5050

5151
// get material while waiting for indices
5252
const nbl_glsl_MC_oriented_material_t material = nbl_glsl_MC_material_data_t_getOriented(batchInstanceData.material,frontfacing);

examples_tests/22.RaytracedAO/raytraceCommon.glsl

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ layout(set = 2, binding = 0, row_major) uniform StaticViewData
2323
{
2424
StaticViewData_t staticViewData;
2525
};
26-
layout(set = 2, binding = 1) readonly restrict buffer ExtraBatchData
27-
{
28-
uint firstIndex[];
29-
} extraBatchData;
3026
// rng
3127
layout(set = 2, binding = 2, rg32ui) uniform uimage2DArray scramblebuf;
3228
layout(set = 2, binding = 3) uniform usamplerBuffer sampleSequence;
@@ -51,9 +47,9 @@ void clear_raycount()
5147
}
5248

5349
//
54-
uvec3 get_triangle_indices(in uint batchInstanceGUID, in uint triangleID)
50+
uvec3 get_triangle_indices(in nbl_glsl_ext_Mitsuba_Loader_instance_data_t batchInstanceData, in uint triangleID)
5551
{
56-
const uint baseTriangleVertex = triangleID*3u+extraBatchData.firstIndex[batchInstanceGUID];
52+
const uint baseTriangleVertex = triangleID*3u+batchInstanceData.padding0;
5753
return uvec3(
5854
nbl_glsl_VG_fetchTriangleVertexIndex(baseTriangleVertex,0u),
5955
nbl_glsl_VG_fetchTriangleVertexIndex(baseTriangleVertex,1u),
@@ -294,15 +290,15 @@ for (uint i=1u; i!=vertex_depth; i++)
294290
// if (i==0u)
295291
// imageStore(scramblebuf,ivec3(outPixelLocation,vertex_depth_mod_2_inv),uvec4(scramble_state,0u,0u));
296292
nextThroughput[i] *= prevThroughput;
297-
if (any(greaterThan(nextThroughput[i],vec3(nbl_glsl_FLT_MIN))))
293+
if (max(max(nextThroughput[i].x,nextThroughput[i].y),nextThroughput[i].z)>exp2(-19.f)) // TODO: reverse tonemap to adjust the threshold
298294
raysToAllocate++;
299295
else
300296
maxT[i] = 0.f;
301297
}
302298
// TODO: investigate workgroup reductions here
303299
const uint baseOutputID = atomicAdd(rayCount[pc.cummon.rayCountWriteIx],raysToAllocate);
304300

305-
float ray_offset = 0.00001f; // I pulled the constant out of my @$$
301+
float ray_offset = dot(abs(normalizedN),abs(origin))*nbl_glsl_numeric_limits_float_epsilon(9u)*1.03f+nbl_glsl_numeric_limits_float_epsilon(20u); // I pulled the constants out of my @$$
306302
// TODO: in the future run backward error analysis of
307303
// dot(mat3(WorldToObj)*(origin+offset*geomNormal/length(geomNormal))+(WorldToObj-vx_pos[1]),geomNormal)
308304
// where

0 commit comments

Comments
 (0)