@@ -251,11 +251,11 @@ class ExampleOcclusionCulling : public entry::AppI
251
251
252
252
debug_coverage = bgfx::createTexture2D (Rasterizer::g_total_width, Rasterizer::g_total_height, false , 1 , bgfx::TextureFormat::R8);
253
253
254
- Rasterizer::Init ();
255
-
256
254
m_Scheduler.Initialize (std::thread::hardware_concurrency ()-1 );
257
255
int workersCount = (int )m_Scheduler.GetNumTaskThreads ();
258
256
printf (" Scheduler started, %d workers\n " , workersCount);
257
+
258
+ m_Rasterizer.Init (workersCount);
259
259
}
260
260
261
261
int shutdown () override
@@ -287,7 +287,7 @@ class ExampleOcclusionCulling : public entry::AppI
287
287
if (m_Visibility[i] == 0 )
288
288
continue ;
289
289
290
- encoder->setTransform (m_Transforms [i].data () );
290
+ encoder->setTransform (( float *)&m_Objects [i].transform );
291
291
encoder->setVertexBuffer (0 , m_vbh);
292
292
encoder->setIndexBuffer (m_ibh);
293
293
@@ -325,20 +325,7 @@ class ExampleOcclusionCulling : public entry::AppI
325
325
326
326
void ExecuteRange (enki::TaskSetPartition range, uint32_t thread_index) override
327
327
{
328
- vec4_t box_min = {-1 .f , -1 .f , -1 .f , 1 .f };
329
- vec4_t box_max = {+1 .f , +1 .f , +1 .f , 1 .f };
330
- for (uint32_t index = range.start , wrapped_index = 0 ; index < range.end ; ++index)
331
- {
332
- bool occludee = index >= m_parent->m_Visibility .size ();
333
- wrapped_index = occludee ? index - (uint32_t )m_parent->m_Visibility .size () : index;
334
- if (occludee)
335
- m_parent->m_Visibility [wrapped_index] = 0 ;
336
- m_parent->m_Rasterizer .push_object (MatrixSet (m_parent->m_Transforms [wrapped_index].data ()),
337
- box_min, box_max,
338
- s_cubeIndices, sizeof (s_cubeIndices) / sizeof (s_cubeIndices[0 ]),
339
- s_cubeVerticesSIMD, sizeof (s_cubeVerticesSIMD) / sizeof (s_cubeVerticesSIMD[0 ]),
340
- occludee ? &m_parent->m_Visibility [wrapped_index] : nullptr );
341
- }
328
+ m_parent->m_Rasterizer .push_objects (m_parent->m_Objects .data () + range.start , range.end - range.start , thread_index);
342
329
}
343
330
344
331
ExampleOcclusionCulling* m_parent = nullptr ;
@@ -350,19 +337,17 @@ class ExampleOcclusionCulling : public entry::AppI
350
337
: m_parent(parent)
351
338
{
352
339
this ->m_SetSize = Rasterizer::g_width*Rasterizer::g_height;
353
- m_sort.resize (this ->m_SetSize );
354
340
}
355
341
356
342
void ExecuteRange (enki::TaskSetPartition range, uint32_t thread_index) override
357
343
{
358
344
for (uint32_t index = range.start ; index < range.end ; ++index)
359
345
{
360
- m_parent->m_Rasterizer .sort_triangles (index, m_sort[index] );
346
+ m_parent->m_Rasterizer .sort_triangles (index, thread_index );
361
347
}
362
348
}
363
349
364
350
ExampleOcclusionCulling* m_parent = nullptr ;
365
- stl::vector<stl::vector<uint64_t >> m_sort;
366
351
};
367
352
368
353
struct DrawTask : enki::ITaskSet
@@ -373,7 +358,7 @@ class ExampleOcclusionCulling : public entry::AppI
373
358
this ->m_SetSize = Rasterizer::g_width*Rasterizer::g_height;
374
359
}
375
360
376
- void ExecuteRange (enki::TaskSetPartition range, uint32_t thread_index ) override
361
+ void ExecuteRange (enki::TaskSetPartition range, uint32_t ) override
377
362
{
378
363
for (uint32_t index = range.start ; index < range.end ; ++index)
379
364
{
@@ -467,9 +452,9 @@ class ExampleOcclusionCulling : public entry::AppI
467
452
{
468
453
for (auto & t : tiles)
469
454
{
470
- if (ImGui::TreeNode (std::to_string (t.m_x + t.m_y *Rasterizer::g_width).c_str (), " Tile %d (%d/%d) %s" , t.m_x , (uint32_t )t.m_triangle_count , t.m_triangles_drawn_total , t.m_mask == ~0u ? " full" : " " ))
455
+ if (ImGui::TreeNode (std::to_string (t.m_x + t.m_y *Rasterizer::g_width).c_str (), " Tile %d (%d/%d) %s" , t.m_x , /* (uint32_t)t.m_triangle_count*/ 0 , t.m_triangles_drawn_total , t.m_mask == ~0u ? " full" : " " ))
471
456
{
472
- ImGui::Text (" total sorted triangles %d" , (uint32_t )t.m_triangles .size ());
457
+ ImGui::Text (" total sorted triangles %d" , /* (uint32_t)t.m_triangles.size()*/ 0 );
473
458
ImGui::Text (" total drawn triangles %d" , t.m_triangles_drawn_total );
474
459
ImGui::Text (" total drawn occluder triangles %d" , t.m_triangles_drawn_occluder_total );
475
460
ImGui::Text (" total drawn occludee triangles %d" , t.m_triangles_drawn_occludee_total );
@@ -528,8 +513,9 @@ class ExampleOcclusionCulling : public entry::AppI
528
513
pos[1 ] = -step*m_dim / 2 .0f ;
529
514
pos[2 ] = -15.0 ;
530
515
531
- m_Transforms.resize (m_dim*m_dim*m_dim);
532
- m_Visibility.resize (m_dim*m_dim*m_dim);
516
+ uint32_t max_drawcalls = m_dim*m_dim*m_dim;
517
+ m_Objects.resize (max_drawcalls*2 );
518
+ m_Visibility.resize (max_drawcalls);
533
519
for (uint32_t zz = 0 ; zz < uint32_t (m_dim); ++zz)
534
520
{
535
521
for (uint32_t yy = 0 ; yy < uint32_t (m_dim); ++yy)
@@ -550,8 +536,24 @@ class ExampleOcclusionCulling : public entry::AppI
550
536
mtx[13 ] = pos[1 ] + float (yy)*step;
551
537
mtx[14 ] = pos[2 ] + float (zz)*step;
552
538
553
- m_Transforms[xx + yy*m_dim + zz*m_dim*m_dim].resize (16 );
554
- memcpy (m_Transforms[xx + yy*m_dim + zz*m_dim*m_dim].data (), mtx, sizeof (mtx));
539
+ uint32_t idx = xx + yy*m_dim + zz*m_dim*m_dim;
540
+ m_Objects[idx].transform = MatrixSet (mtx);
541
+ m_Objects[idx].indices = s_cubeIndices;
542
+ m_Objects[idx].index_count = sizeof (s_cubeIndices) / sizeof (s_cubeIndices[0 ]);
543
+ m_Objects[idx].vertices = s_cubeVerticesSIMD;
544
+ m_Objects[idx].vertex_count = sizeof (s_cubeVerticesSIMD) / sizeof (s_cubeVerticesSIMD[0 ]);
545
+ m_Objects[idx].visibility = &m_Visibility[xx + yy*m_dim + zz*m_dim*m_dim];
546
+ m_Objects[idx].bound_min = {-1 .f , -1 .f , -1 .f , 1 .f };
547
+ m_Objects[idx].bound_max = {1 .f , 1 .f , 1 .f , 1 .f };
548
+
549
+ m_Objects[idx+max_drawcalls].transform = MatrixSet (mtx);
550
+ m_Objects[idx+max_drawcalls].indices = s_cubeIndices;
551
+ m_Objects[idx+max_drawcalls].index_count = sizeof (s_cubeIndices) / sizeof (s_cubeIndices[0 ]);
552
+ m_Objects[idx+max_drawcalls].vertices = s_cubeVerticesSIMD;
553
+ m_Objects[idx+max_drawcalls].vertex_count = sizeof (s_cubeVerticesSIMD) / sizeof (s_cubeVerticesSIMD[0 ]);
554
+ m_Objects[idx+max_drawcalls].visibility = nullptr ;
555
+ m_Objects[idx+max_drawcalls].bound_min = {-1 .f , -1 .f , -1 .f , 1 .f };
556
+ m_Objects[idx+max_drawcalls].bound_max = {1 .f , 1 .f , 1 .f , 1 .f };
555
557
}
556
558
}
557
559
}
@@ -561,43 +563,18 @@ class ExampleOcclusionCulling : public entry::AppI
561
563
m_Rasterizer.begin (view_mat * proj_mat * MatrixScaling (0 .5f , -0 .5f , 1 .0f ) * MatrixTranslation (Vector4 ( .5f , 0 .5f , 0 .0f , 1 .0f )) * MatrixScaling ( (float )Rasterizer::g_total_width, (float )Rasterizer::g_total_height, 1 .0f ));
562
564
if (m_Occlusion)
563
565
{
564
- vec4_t box_min = {-1 .f , -1 .f , -1 .f , 1 .f };
565
- vec4_t box_max = {+1 .f , +1 .f , +1 .f , 1 .f };
566
-
567
566
m_Rasterizer.setMT (m_MT);
568
567
569
568
int64_t occlusion_start = bx::getHPCounter ();
570
- uint32_t total_count = uint32_t (m_dim)*uint32_t (m_dim)*uint32_t (m_dim);
571
569
if (m_MT)
572
570
{
573
- m_PushTasks.setCount (total_count* 2 );
571
+ m_PushTasks.setCount (m_Objects. size () );
574
572
m_Scheduler.AddTaskSetToPipe (&m_PushTasks);
575
573
m_Scheduler.WaitforAll ();
576
574
}
577
575
else
578
576
{
579
- for (uint32_t i = 0 ; i < total_count; ++i )
580
- {
581
- m_Visibility[i] = 0 ;
582
- if (m_UseBox)
583
- {
584
- m_Rasterizer.push_box (MatrixSet (m_Transforms[i].data ()), &m_Visibility[i]);
585
- m_Rasterizer.push_box (MatrixSet (m_Transforms[i].data ()), nullptr );
586
- }
587
- else
588
- {
589
- m_Rasterizer.push_object (MatrixSet (m_Transforms[i].data ()),
590
- box_min, box_max,
591
- s_cubeIndices, sizeof (s_cubeIndices) / sizeof (s_cubeIndices[0 ]),
592
- s_cubeVerticesSIMD, sizeof (s_cubeVerticesSIMD) / sizeof (s_cubeVerticesSIMD[0 ]),
593
- &m_Visibility[i]);
594
- m_Rasterizer.push_object (MatrixSet (m_Transforms[i].data ()),
595
- box_min, box_max,
596
- s_cubeIndices, sizeof (s_cubeIndices) / sizeof (s_cubeIndices[0 ]),
597
- s_cubeVerticesSIMD, sizeof (s_cubeVerticesSIMD) / sizeof (s_cubeVerticesSIMD[0 ]),
598
- nullptr );
599
- }
600
- }
577
+ m_Rasterizer.push_objects (m_Objects.data (), m_Objects.size ());
601
578
}
602
579
int64_t occlusion_mid = bx::getHPCounter ();
603
580
occlusion_push_time = occlusion_mid - occlusion_start;
@@ -635,7 +612,7 @@ class ExampleOcclusionCulling : public entry::AppI
635
612
for ( int y = 0 ; y < Tile::g_tile_height; ++y )
636
613
for ( int x = 0 ; x < Tile::g_tile_width; ++x )
637
614
{
638
- __m128i buf = m_Rasterizer.get_framebuffer (j + i*Rasterizer::g_width)[y];
615
+ vec4i_t buf = m_Rasterizer.get_framebuffer (j + i*Rasterizer::g_width)[y];
639
616
unsigned int mask = ( (unsigned int *)( &buf ) )[ x >> 5 ];
640
617
int bit = mask & ( 1 << ( x & 31 ) );
641
618
data[j*Tile::g_tile_width + 127 - x + (y + i*Tile::g_tile_height)*Rasterizer::g_total_width] = bit ? 255 : 0 ;
@@ -674,8 +651,8 @@ class ExampleOcclusionCulling : public entry::AppI
674
651
675
652
float m_Spacing = 60 .f;
676
653
677
- stl::vector<stl::vector< float >> m_Transforms ;
678
- stl::vector<int > m_Visibility;
654
+ stl::vector<Rasterizer::Object> m_Objects ;
655
+ stl::vector<uint32_t > m_Visibility;
679
656
680
657
bool m_Wireframe = false ;
681
658
bool m_Occlusion = false ;
0 commit comments