@@ -17,6 +17,36 @@ using namespace nbl::core;
17
17
using namespace nbl ::asset;
18
18
using namespace nbl ::video;
19
19
20
+ bool freezeCulling = false ;
21
+
22
+ class MyEventReceiver : public QToQuitEventReceiver
23
+ {
24
+ public:
25
+
26
+ MyEventReceiver ()
27
+ {
28
+ }
29
+
30
+ bool OnEvent (const SEvent& event)
31
+ {
32
+ if (event.EventType == nbl::EET_KEY_INPUT_EVENT && !event.KeyInput .PressedDown )
33
+ {
34
+ switch (event.KeyInput .Key )
35
+ {
36
+ case nbl::KEY_KEY_Q: // so we can quit
37
+ return QToQuitEventReceiver::OnEvent (event);
38
+ case nbl::KEY_KEY_C: // freeze culling
39
+ freezeCulling = !freezeCulling; // Not enabled/necessary yet
40
+ return true ;
41
+ default :
42
+ break ;
43
+ }
44
+ }
45
+
46
+ return false ;
47
+ }
48
+ };
49
+
20
50
#include " common.h"
21
51
#include " rasterizationCommon.h"
22
52
@@ -164,6 +194,7 @@ struct CullShaderData
164
194
{
165
195
core::smart_refctd_ptr<IGPUBuffer> perBatchCull;
166
196
core::smart_refctd_ptr<IGPUBuffer> commandBuffer;
197
+ core::smart_refctd_ptr<IGPUBuffer> mvpBuffer;
167
198
168
199
core::smart_refctd_ptr<IGPUComputePipeline> cullPipeline;
169
200
core::smart_refctd_ptr<IGPUDescriptorSetLayout> cullDSLayout;
@@ -221,7 +252,7 @@ int main()
221
252
222
253
// ! Since our cursor will be enslaved, there will be no way to close the window
223
254
// ! So we listen for the "Q" key being pressed and exit the application
224
- QToQuitEventReceiver receiver;
255
+ MyEventReceiver receiver;
225
256
device->setEventReceiver (&receiver);
226
257
227
258
auto * driver = device->getVideoDriver ();
@@ -566,7 +597,7 @@ int main()
566
597
567
598
batchCullDataEnd->drawCommandGUID = packedMeshBufferData.mdiParameterOffset + i;
568
599
569
- draw3DLine->enqueueBox (dbgLines, aabbs[aabbIdx], 1 .0f , 0 .0f , 0 .0f , 1 .0f , core::matrix3x4SIMD ());
600
+ draw3DLine->enqueueBox (dbgLines, aabbs[aabbIdx], 0 .0f , 0 .0f , 0 .0f , 1 .0f , core::matrix3x4SIMD ());
570
601
571
602
batchCullDataEnd++;
572
603
aabbIdx++;
@@ -608,7 +639,8 @@ int main()
608
639
609
640
cullShaderData.commandBuffer = gpump->getPackerDataStore ().MDIDataBuffer ;
610
641
cullShaderData.maxBatchCount = std::distance (batchCullData.begin (), batchCullDataEnd);
611
- cullShaderData.perBatchCull = driver->createFilledDeviceLocalGPUBufferOnDedMem (cullShaderData.maxBatchCount , batchCullData.data ());
642
+ cullShaderData.perBatchCull = driver->createFilledDeviceLocalGPUBufferOnDedMem (cullShaderData.maxBatchCount * sizeof (CullData_t), batchCullData.data ());
643
+ cullShaderData.mvpBuffer = driver->createDeviceLocalGPUBufferOnDedMem (cullShaderData.maxBatchCount * sizeof (core::matrix4SIMD));
612
644
}
613
645
mesh_raw->convertToDummyObject (~0u );
614
646
@@ -789,11 +821,12 @@ int main()
789
821
}
790
822
}
791
823
824
+ // cull shader ds
792
825
{
793
826
SPushConstantRange range{ ISpecializedShader::ESS_COMPUTE,0u ,sizeof (CullShaderData_t) };
794
827
795
828
{
796
- IGPUDescriptorSetLayout::SBinding bindings[2 ];
829
+ IGPUDescriptorSetLayout::SBinding bindings[3 ];
797
830
bindings[0 ].binding = 0u ;
798
831
bindings[0 ].count = 1u ;
799
832
bindings[0 ].samplers = nullptr ;
@@ -805,12 +838,18 @@ int main()
805
838
bindings[1 ].samplers = nullptr ;
806
839
bindings[1 ].stageFlags = ISpecializedShader::ESS_COMPUTE;
807
840
bindings[1 ].type = EDT_STORAGE_BUFFER;
808
-
841
+
842
+ bindings[2 ].binding = 2u ;
843
+ bindings[2 ].count = 1u ;
844
+ bindings[2 ].samplers = nullptr ;
845
+ bindings[2 ].stageFlags = ISpecializedShader::ESS_COMPUTE;
846
+ bindings[2 ].type = EDT_STORAGE_BUFFER;
847
+
809
848
cullShaderData.cullDSLayout = driver->createGPUDescriptorSetLayout (bindings, bindings + sizeof (bindings) / sizeof (IGPUDescriptorSetLayout::SBinding));
810
849
}
811
850
812
851
{
813
- IGPUDescriptorSet::SDescriptorInfo infos[2 ];
852
+ IGPUDescriptorSet::SDescriptorInfo infos[3 ];
814
853
815
854
infos[0 ].desc = core::smart_refctd_ptr (cullShaderData.perBatchCull );
816
855
infos[0 ].buffer .offset = 0u ;
@@ -819,12 +858,16 @@ int main()
819
858
infos[1 ].desc = core::smart_refctd_ptr (cullShaderData.commandBuffer );
820
859
infos[1 ].buffer .offset = 0u ;
821
860
infos[1 ].buffer .size = cullShaderData.commandBuffer ->getSize ();
822
-
861
+
862
+ infos[2 ].desc = core::smart_refctd_ptr (cullShaderData.mvpBuffer );
863
+ infos[2 ].buffer .offset = 0u ;
864
+ infos[2 ].buffer .size = cullShaderData.mvpBuffer ->getSize ();
865
+
823
866
cullShaderData.cullDS = driver->createGPUDescriptorSet (smart_refctd_ptr (cullShaderData.cullDSLayout ));
824
867
825
- IGPUDescriptorSet::SWriteDescriptorSet writes[2 ];
868
+ IGPUDescriptorSet::SWriteDescriptorSet writes[3 ];
826
869
827
- for (uint32_t i = 0u ; i < 2 ; i++)
870
+ for (uint32_t i = 0u ; i < 3 ; i++)
828
871
{
829
872
writes[i].dstSet = cullShaderData.cullDS .get ();
830
873
writes[i].binding = i;
@@ -849,15 +892,15 @@ int main()
849
892
cullShaderData.cullPipeline = driver->createGPUComputePipeline (nullptr , std::move (cullPipelineLayout), std::move (gpuCullShader));
850
893
}
851
894
852
- auto cullBatches = [&driver, &cullShaderData](const core::matrix4SIMD& vp)
895
+ auto cullBatches = [&driver, &cullShaderData](const core::matrix4SIMD& vp, bool freezeCulling )
853
896
{
854
897
driver->bindDescriptorSets (EPBP_COMPUTE, cullShaderData.cullPipeline ->getLayout (), 0u , 1u , &cullShaderData.cullDS .get (), nullptr );
855
898
driver->bindComputePipeline (cullShaderData.cullPipeline .get ());
856
899
857
900
CullShaderData_t cullPushConstants;
858
901
cullPushConstants.viewProjMatrix = vp;
859
- cullPushConstants.viewProjDeterminant = core::determinant (vp) ;
860
- cullPushConstants.maxBatchCount = cullShaderData. maxBatchCount ; // TODO: this should be uniform, and set only once
902
+ cullPushConstants.maxBatchCount = cullShaderData. maxBatchCount ;
903
+ cullPushConstants.freezeCulling = static_cast < uint32_t >(freezeCulling);
861
904
862
905
driver->pushConstants (cullShaderData.cullPipeline ->getLayout (), ISpecializedShader::ESS_COMPUTE, 0u , sizeof (CullShaderData_t), &cullPushConstants);
863
906
@@ -875,10 +918,8 @@ int main()
875
918
camera->setFarValue (5000 .0f );
876
919
877
920
smgr->setActiveCamera (camera);
878
-
879
- // tmp shit
880
- core::matrix4SIMD vpFromFirstFrame;
881
921
922
+ bool asdf = true ;
882
923
uint64_t lastFPSTime = 0 ;
883
924
while (device->run () && receiver.keepOpen ())
884
925
{
@@ -888,17 +929,14 @@ int main()
888
929
camera->OnAnimate (std::chrono::duration_cast<std::chrono::milliseconds>(device->getTimer ()->getTime ()).count ());
889
930
camera->render ();
890
931
891
- if (lastFPSTime == 0 )
892
- vpFromFirstFrame = camera->getConcatenatedMatrix ();
893
-
894
932
SBasicViewParameters uboData;
895
933
memcpy (uboData.MVP , camera->getConcatenatedMatrix ().pointer (), sizeof (core::matrix4SIMD));
896
934
memcpy (uboData.MV , camera->getViewMatrix ().pointer (), sizeof (core::matrix3x4SIMD));
897
935
memcpy (uboData.NormalMat , camera->getViewMatrix ().pointer (), sizeof (core::matrix3x4SIMD));
898
936
driver->updateBufferRangeViaStagingBuffer (sceneData.ubo .get (), 0u , sizeof (SBasicViewParameters), &uboData);
899
937
900
938
// cull MDIs
901
- cullBatches (vpFromFirstFrame );
939
+ cullBatches (camera-> getConcatenatedMatrix (), freezeCulling );
902
940
COpenGLExtensionHandler::pGlMemoryBarrier (GL_COMMAND_BARRIER_BIT | GL_SHADER_STORAGE_BARRIER_BIT);
903
941
904
942
driver->setRenderTarget (visBuffer);
0 commit comments