gpudrivenrendering.cpp 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146
  1. /*
  2. * Copyright 2018 Kostas Anagnostou. All rights reserved.
  3. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
  4. */
  5. /*
  6. * Reference(s):
  7. * - Experiments in GPU-based occlusion culling
  8. * https://web.archive.org/web/20180920045301/https://interplayoflight.wordpress.com/2017/11/15/experiments-in-gpu-based-occlusion-culling/
  9. * - Experiments in GPU-based occlusion culling part 2: MultiDrawIndirect and mesh lodding
  10. * https://web.archive.org/web/20180920045332/https://interplayoflight.wordpress.com/2018/01/15/experiments-in-gpu-based-occlusion-culling-part-2-multidrawindirect-and-mesh-lodding/
  11. */
  12. #include "common.h"
  13. #include "bgfx_utils.h"
  14. #include "imgui/imgui.h"
  15. namespace
  16. {
  17. #define RENDER_PASS_HIZ_ID 0
  18. #define RENDER_PASS_HIZ_DOWNSCALE_ID 1
  19. #define RENDER_PASS_OCCLUDE_PROPS_ID 2
  20. #define RENDER_PASS_COMPACT_STREAM_ID 3
  21. #define RENDER_PASS_MAIN_ID 4
  22. struct Camera
  23. {
  24. Camera()
  25. {
  26. reset();
  27. }
  28. void reset()
  29. {
  30. m_target.curr = { 0.0f, 0.0f, 0.0f };
  31. m_target.dest = { 0.0f, 0.0f, 0.0f };
  32. m_pos.curr = { 55.0f, 20.0f, 65.0f };
  33. m_pos.dest = { 55.0f, 20.0f, 65.0f };
  34. m_orbit[0] = 0.0f;
  35. m_orbit[1] = 0.0f;
  36. }
  37. void mtxLookAt(float* _outViewMtx)
  38. {
  39. bx::mtxLookAt(_outViewMtx, m_pos.curr, m_target.curr);
  40. }
  41. void orbit(float _dx, float _dy)
  42. {
  43. m_orbit[0] += _dx;
  44. m_orbit[1] += _dy;
  45. }
  46. void dolly(float _dz)
  47. {
  48. const float cnear = 1.0f;
  49. const float cfar = 100.0f;
  50. const bx::Vec3 toTarget = bx::sub(m_target.dest, m_pos.dest);
  51. const float toTargetLen = bx::length(toTarget);
  52. const float invToTargetLen = 1.0f / (toTargetLen + bx::kFloatMin);
  53. const bx::Vec3 toTargetNorm = bx::mul(toTarget, invToTargetLen);
  54. float delta = toTargetLen * _dz;
  55. float newLen = toTargetLen + delta;
  56. if ( (cnear < newLen || _dz < 0.0f)
  57. && (newLen < cfar || _dz > 0.0f) )
  58. {
  59. m_pos.dest = bx::mad(toTargetNorm, delta, m_pos.dest);
  60. }
  61. }
  62. void consumeOrbit(float _amount)
  63. {
  64. float consume[2];
  65. consume[0] = m_orbit[0] * _amount;
  66. consume[1] = m_orbit[1] * _amount;
  67. m_orbit[0] -= consume[0];
  68. m_orbit[1] -= consume[1];
  69. const bx::Vec3 toPos = bx::sub(m_pos.curr, m_target.curr);
  70. const float toPosLen = bx::length(toPos);
  71. const float invToPosLen = 1.0f / (toPosLen + bx::kFloatMin);
  72. const bx::Vec3 toPosNorm = bx::mul(toPos, invToPosLen);
  73. float ll[2];
  74. bx::toLatLong(&ll[0], &ll[1], toPosNorm);
  75. ll[0] += consume[0];
  76. ll[1] -= consume[1];
  77. ll[1] = bx::clamp(ll[1], 0.02f, 0.98f);
  78. const bx::Vec3 tmp = bx::fromLatLong(ll[0], ll[1]);
  79. const bx::Vec3 diff = bx::mul(bx::sub(tmp, toPosNorm), toPosLen);
  80. m_pos.curr = bx::add(m_pos.curr, diff);
  81. m_pos.dest = bx::add(m_pos.dest, diff);
  82. }
  83. void update(float _dt)
  84. {
  85. const float amount = bx::min(_dt / 0.12f, 1.0f);
  86. consumeOrbit(amount);
  87. m_target.curr = bx::lerp(m_target.curr, m_target.dest, amount);
  88. m_pos.curr = bx::lerp(m_pos.curr, m_pos.dest, amount);
  89. }
  90. void envViewMtx(float* _mtx)
  91. {
  92. const bx::Vec3 toTarget = bx::sub(m_target.curr, m_pos.curr);
  93. const float toTargetLen = bx::length(toTarget);
  94. const float invToTargetLen = 1.0f / (toTargetLen + bx::kFloatMin);
  95. const bx::Vec3 toTargetNorm = bx::mul(toTarget, invToTargetLen);
  96. const bx::Vec3 right = bx::normalize(bx::cross({ 0.0f, 1.0f, 0.0f }, toTargetNorm) );
  97. const bx::Vec3 up = bx::normalize(bx::cross(toTargetNorm, right) );
  98. _mtx[ 0] = right.x;
  99. _mtx[ 1] = right.y;
  100. _mtx[ 2] = right.z;
  101. _mtx[ 3] = 0.0f;
  102. _mtx[ 4] = up.x;
  103. _mtx[ 5] = up.y;
  104. _mtx[ 6] = up.z;
  105. _mtx[ 7] = 0.0f;
  106. _mtx[ 8] = toTargetNorm.x;
  107. _mtx[ 9] = toTargetNorm.y;
  108. _mtx[10] = toTargetNorm.z;
  109. _mtx[11] = 0.0f;
  110. _mtx[12] = 0.0f;
  111. _mtx[13] = 0.0f;
  112. _mtx[14] = 0.0f;
  113. _mtx[15] = 1.0f;
  114. }
  115. struct Interp3f
  116. {
  117. bx::Vec3 curr;
  118. bx::Vec3 dest;
  119. };
  120. Interp3f m_target;
  121. Interp3f m_pos;
  122. float m_orbit[2];
  123. };
  124. struct Mouse
  125. {
  126. Mouse()
  127. : m_dx(0.0f)
  128. , m_dy(0.0f)
  129. , m_prevMx(0.0f)
  130. , m_prevMy(0.0f)
  131. , m_scroll(0)
  132. , m_scrollPrev(0)
  133. {
  134. }
  135. void update(float _mx, float _my, int32_t _mz, uint32_t _width, uint32_t _height)
  136. {
  137. const float widthf = float(int32_t(_width));
  138. const float heightf = float(int32_t(_height));
  139. // Delta movement.
  140. m_dx = float(_mx - m_prevMx) / widthf;
  141. m_dy = float(_my - m_prevMy) / heightf;
  142. m_prevMx = _mx;
  143. m_prevMy = _my;
  144. // Scroll.
  145. m_scroll = _mz - m_scrollPrev;
  146. m_scrollPrev = _mz;
  147. }
  148. float m_dx; // Screen space.
  149. float m_dy;
  150. float m_prevMx;
  151. float m_prevMy;
  152. int32_t m_scroll;
  153. int32_t m_scrollPrev;
  154. };
  155. struct PosVertex
  156. {
  157. float m_x;
  158. float m_y;
  159. float m_z;
  160. static void init()
  161. {
  162. ms_layout
  163. .begin()
  164. .add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float)
  165. .end();
  166. };
  167. static bgfx::VertexLayout ms_layout;
  168. };
  169. bgfx::VertexLayout PosVertex::ms_layout;
  170. static PosVertex s_cubeVertices[8] =
  171. {
  172. {-0.5f, 0.5f, 0.5f},
  173. { 0.5f, 0.5f, 0.5f},
  174. {-0.5f, -0.5f, 0.5f},
  175. { 0.5f, -0.5f, 0.5f},
  176. {-0.5f, 0.5f, -0.5f},
  177. { 0.5f, 0.5f, -0.5f},
  178. {-0.5f, -0.5f, -0.5f},
  179. { 0.5f, -0.5f, -0.5f},
  180. };
  181. static const uint16_t s_cubeIndices[36] =
  182. {
  183. 0, 1, 2, // 0
  184. 1, 3, 2,
  185. 4, 6, 5, // 2
  186. 5, 6, 7,
  187. 0, 2, 4, // 4
  188. 4, 2, 6,
  189. 1, 5, 3, // 6
  190. 5, 7, 3,
  191. 0, 4, 1, // 8
  192. 4, 5, 1,
  193. 2, 3, 6, // 10
  194. 6, 3, 7,
  195. };
  196. struct RenderPass
  197. {
  198. enum Enum
  199. {
  200. Occlusion = 1 << 0,
  201. MainPass = 1 << 1,
  202. All = Occlusion | MainPass
  203. };
  204. };
  205. // All the per-instance data we store
  206. struct InstanceData
  207. {
  208. float m_world[16];
  209. float m_bboxMin[4];
  210. float m_bboxMax[4];
  211. };
  212. //A description of each prop
  213. struct Prop
  214. {
  215. PosVertex* m_vertices;
  216. uint16_t* m_indices;
  217. InstanceData* m_instances;
  218. bgfx::VertexBufferHandle m_vertexbufferHandle;
  219. bgfx::IndexBufferHandle m_indexbufferHandle;
  220. uint16_t m_noofVertices;
  221. uint16_t m_noofIndices;
  222. uint16_t m_noofInstances;
  223. uint16_t m_materialID;
  224. RenderPass::Enum m_renderPass;
  225. };
  226. //A simplistic material, comprised of a color only
  227. struct Material
  228. {
  229. float m_color[4];
  230. };
  231. inline void setVector4(float* dest, float x, float y, float z, float w)
  232. {
  233. dest[0] = x;
  234. dest[1] = y;
  235. dest[2] = z;
  236. dest[3] = w;
  237. }
  238. //Sets up a prop
  239. void createCubeMesh(Prop& prop)
  240. {
  241. prop.m_noofVertices = 8;
  242. prop.m_noofIndices = 36;
  243. prop.m_vertices = new PosVertex[prop.m_noofVertices];
  244. prop.m_indices = new uint16_t[prop.m_noofIndices];
  245. bx::memCopy(prop.m_vertices, s_cubeVertices, prop.m_noofVertices * PosVertex::ms_layout.getStride());
  246. bx::memCopy(prop.m_indices, s_cubeIndices, prop.m_noofIndices * sizeof(uint16_t));
  247. prop.m_vertexbufferHandle = bgfx::createVertexBuffer(
  248. bgfx::makeRef(prop.m_vertices, prop.m_noofVertices * PosVertex::ms_layout.getStride()),
  249. PosVertex::ms_layout);
  250. prop.m_indexbufferHandle = bgfx::createIndexBuffer(bgfx::makeRef(prop.m_indices, prop.m_noofIndices * sizeof(uint16_t)));
  251. }
  252. //returns a random number between 0 and 1
  253. float rand01()
  254. {
  255. return rand() / (float)RAND_MAX;
  256. }
  257. class GPUDrivenRendering : public entry::AppI
  258. {
  259. public:
  260. GPUDrivenRendering(const char* _name, const char* _description)
  261. : entry::AppI(_name, _description)
  262. {
  263. }
  264. void init(int32_t _argc, const char* const* _argv, uint32_t _width, uint32_t _height) override
  265. {
  266. Args args(_argc, _argv);
  267. m_width = _width;
  268. m_height = _height;
  269. //find largest pow of two dims less than backbuffer size
  270. m_hiZwidth = (uint32_t)bx::pow(2.0f, bx::floor(bx::log2(float(m_width ) ) ) );
  271. m_hiZheight = (uint32_t)bx::pow(2.0f, bx::floor(bx::log2(float(m_height) ) ) );
  272. m_debug = BGFX_DEBUG_TEXT;
  273. m_reset = BGFX_RESET_VSYNC;
  274. bgfx::Init init;
  275. init.type = args.m_type;
  276. init.vendorId = args.m_pciId;
  277. init.resolution.width = m_width;
  278. init.resolution.height = m_height;
  279. init.resolution.reset = m_reset;
  280. bgfx::init(init);
  281. // Enable debug text.
  282. bgfx::setDebug(m_debug);
  283. // Create uniforms and samplers.
  284. u_inputRTSize = bgfx::createUniform("u_inputRTSize", bgfx::UniformType::Vec4);
  285. u_cullingConfig = bgfx::createUniform("u_cullingConfig", bgfx::UniformType::Vec4);
  286. u_color = bgfx::createUniform("u_color", bgfx::UniformType::Vec4, 32);
  287. s_texOcclusionDepth = bgfx::createUniform("s_texOcclusionDepth", bgfx::UniformType::Sampler);
  288. //create props
  289. {
  290. m_totalInstancesCount = 0;
  291. // Create vertex stream declaration.
  292. PosVertex::init();
  293. m_noofProps = 0;
  294. m_props = new Prop[s_maxNoofProps];
  295. //first create space for some materials
  296. m_materials = new Material[s_maxNoofProps];
  297. m_noofMaterials = 0;
  298. //add a ground plane
  299. {
  300. Prop& prop = m_props[m_noofProps++];
  301. prop.m_renderPass = RenderPass::MainPass;
  302. createCubeMesh(prop);
  303. prop.m_noofInstances = 1;
  304. prop.m_instances = new InstanceData[prop.m_noofInstances];
  305. bx::mtxSRT(prop.m_instances->m_world
  306. , 100.0f, 0.1f, 100.0f
  307. , 0.0f, 0.0f, 0.0f
  308. , 0.0f, 0.0f, 0.0f
  309. );
  310. float temp[4];
  311. setVector4(temp, -0.5f, -0.5f, -0.5f, 1.0f);
  312. bx::vec4MulMtx(prop.m_instances->m_bboxMin, temp, prop.m_instances->m_world);
  313. setVector4(temp, 0.5f, 0.5f, 0.5f, 1.0f);
  314. bx::vec4MulMtx(prop.m_instances->m_bboxMax, temp, prop.m_instances->m_world);
  315. prop.m_materialID = m_noofMaterials;
  316. setVector4(m_materials[prop.m_materialID].m_color, 0.0f, 0.6f, 0.0f, 1.0f);
  317. m_noofMaterials++;
  318. m_totalInstancesCount += prop.m_noofInstances;
  319. }
  320. //add a few instances of the occluding mesh
  321. {
  322. Prop& prop = m_props[m_noofProps++];
  323. prop.m_renderPass = RenderPass::All;
  324. //create prop
  325. createCubeMesh(prop);
  326. //add a few instances of the wall mesh
  327. prop.m_noofInstances = 25;
  328. prop.m_instances = new InstanceData[prop.m_noofInstances];
  329. for (int i = 0; i < prop.m_noofInstances; i++)
  330. {
  331. //calculate world position
  332. bx::mtxSRT(prop.m_instances[i].m_world
  333. , 40.0f, 10.0f, 0.1f
  334. , 0.0f, ( rand01() * 120.0f - 60.0f) * 3.1459f / 180.0f, 0.0f
  335. , rand01() * 100.0f - 50.0f, 5.0f, rand01() * 100.0f - 50.0f
  336. );
  337. //calculate bounding box and transform to world space
  338. float temp[4];
  339. setVector4(temp, -0.5f, -0.5f, -0.5f, 1.0f);
  340. bx::vec4MulMtx(prop.m_instances[i].m_bboxMin, temp, prop.m_instances[i].m_world );
  341. setVector4(temp, 0.5f, 0.5f, 0.5f, 1.0f);
  342. bx::vec4MulMtx(prop.m_instances[i].m_bboxMax, temp, prop.m_instances[i].m_world );
  343. }
  344. //set the material ID. Will be used in the shader to select the material
  345. prop.m_materialID = m_noofMaterials;
  346. //add a "material" for this prop
  347. setVector4(m_materials[prop.m_materialID].m_color, 0.0f, 0.0f, 1.0f, 0.0f);
  348. m_noofMaterials++;
  349. m_totalInstancesCount += prop.m_noofInstances;
  350. }
  351. //add a few "regular" props
  352. {
  353. //add cubes
  354. {
  355. Prop& prop = m_props[m_noofProps++];
  356. prop.m_renderPass = RenderPass::MainPass;
  357. createCubeMesh(prop);
  358. prop.m_noofInstances = 200;
  359. prop.m_instances = new InstanceData[prop.m_noofInstances];
  360. for (int i = 0; i < prop.m_noofInstances; i++)
  361. {
  362. bx::mtxSRT(prop.m_instances[i].m_world
  363. , 2.0f, 2.0f, 2.0f
  364. , 0.0f, 0.0f, 0.0f
  365. , rand01() * 100.0f - 50.0f, 1.0f, rand01() * 100.0f - 50.0f
  366. );
  367. float temp[4];
  368. setVector4(temp, -0.5f, -0.5f, -0.5f, 1.0f);
  369. bx::vec4MulMtx(prop.m_instances[i].m_bboxMin, temp, prop.m_instances[i].m_world);
  370. setVector4(temp, 0.5f, 0.5f, 0.5f, 1.0f);
  371. bx::vec4MulMtx(prop.m_instances[i].m_bboxMax, temp, prop.m_instances[i].m_world);
  372. }
  373. prop.m_materialID = m_noofMaterials;
  374. setVector4(m_materials[prop.m_materialID].m_color, 1.0f, 1.0f, 0.0f, 1.0f);
  375. m_noofMaterials++;
  376. m_totalInstancesCount += prop.m_noofInstances;
  377. }
  378. //add some more cubes
  379. {
  380. Prop& prop = m_props[m_noofProps++];
  381. prop.m_renderPass = RenderPass::MainPass;
  382. createCubeMesh(prop);
  383. prop.m_noofInstances = 300;
  384. prop.m_instances = new InstanceData[prop.m_noofInstances];
  385. for (int i = 0; i < prop.m_noofInstances; i++)
  386. {
  387. bx::mtxSRT(prop.m_instances[i].m_world
  388. , 2.0f, 4.0f, 2.0f
  389. , 0.0f, 0.0f, 0.0f
  390. , rand01() * 100.0f - 50.0f, 2.0f, rand01() * 100.0f - 50.0f
  391. );
  392. float temp[4];
  393. setVector4(temp, -0.5f, -0.5f, -0.5f, 1.0f);
  394. bx::vec4MulMtx(prop.m_instances[i].m_bboxMin, temp, prop.m_instances[i].m_world );
  395. setVector4(temp, 0.5f, 0.5f, 0.5f, 1.0f);
  396. bx::vec4MulMtx(prop.m_instances[i].m_bboxMax, temp, prop.m_instances[i].m_world);
  397. }
  398. prop.m_materialID = m_noofMaterials;
  399. setVector4(m_materials[prop.m_materialID].m_color, 1.0f, 0.0f, 0.0f, 1.0f);
  400. m_noofMaterials++;
  401. m_totalInstancesCount += prop.m_noofInstances;
  402. }
  403. }
  404. }
  405. //Setup Occlusion pass
  406. {
  407. const uint64_t tsFlags = 0
  408. | BGFX_TEXTURE_RT
  409. | BGFX_SAMPLER_MIN_POINT
  410. | BGFX_SAMPLER_MAG_POINT
  411. | BGFX_SAMPLER_MIP_POINT
  412. | BGFX_SAMPLER_U_CLAMP
  413. | BGFX_SAMPLER_V_CLAMP
  414. ;
  415. // Create buffers for the HiZ pass
  416. m_hiZDepthBuffer = bgfx::createFrameBuffer(uint16_t(m_hiZwidth), uint16_t(m_hiZheight), bgfx::TextureFormat::D32, tsFlags);
  417. bgfx::TextureHandle buffer = bgfx::createTexture2D(uint16_t(m_hiZwidth), uint16_t(m_hiZheight), true, 1, bgfx::TextureFormat::R32F, BGFX_TEXTURE_COMPUTE_WRITE | tsFlags);
  418. m_hiZBuffer = bgfx::createFrameBuffer(1, &buffer, true);
  419. //how many mip will the Hi Z buffer have?
  420. m_noofHiZMips = (uint8_t)(1 + bx::floor(bx::log2(float(bx::max(m_hiZwidth, m_hiZheight) ) ) ) );
  421. // Setup compute shader buffers
  422. //The compute shader will write how many unoccluded instances per drawcall there are here
  423. m_drawcallInstanceCounts = bgfx::createDynamicIndexBuffer(s_maxNoofProps, BGFX_BUFFER_INDEX32 | BGFX_BUFFER_COMPUTE_READ_WRITE);
  424. //the compute shader will write the result of the occlusion test for each instance here
  425. m_instancePredicates = bgfx::createDynamicIndexBuffer(s_maxNoofInstances, BGFX_BUFFER_COMPUTE_READ_WRITE);
  426. //bounding box for each instance, will be fed to the compute shader to calculate occlusion
  427. {
  428. bgfx::VertexLayout computeVertexLayout;
  429. computeVertexLayout.begin()
  430. .add(bgfx::Attrib::TexCoord0, 4, bgfx::AttribType::Float)
  431. .end();
  432. //initialise the buffer with the bounding boxes of all instances
  433. const int sizeOfBuffer = 2 * 4 * m_totalInstancesCount;
  434. float* boundingBoxes = new float[sizeOfBuffer];
  435. float* data = boundingBoxes;
  436. for (uint16_t i = 0; i < m_noofProps; i++)
  437. {
  438. Prop& prop = m_props[i];
  439. const uint32_t numInstances = prop.m_noofInstances;
  440. for (uint32_t j = 0; j < numInstances; j++)
  441. {
  442. bx::memCopy(data, prop.m_instances[j].m_bboxMin, 3 * sizeof(float));
  443. data[3] = (float)i; // store the drawcall ID here to avoid creating a separate buffer
  444. data += 4;
  445. bx::memCopy(data, prop.m_instances[j].m_bboxMax, 3 * sizeof(float));
  446. data += 4;
  447. }
  448. }
  449. const bgfx::Memory* mem = bgfx::makeRef(boundingBoxes, sizeof(float) * sizeOfBuffer);
  450. m_instanceBoundingBoxes = bgfx::createDynamicVertexBuffer(mem, computeVertexLayout, BGFX_BUFFER_COMPUTE_READ);
  451. }
  452. //pre and post occlusion culling instance data buffers
  453. {
  454. bgfx::VertexLayout instanceBufferVertexLayout;
  455. instanceBufferVertexLayout.begin()
  456. .add(bgfx::Attrib::TexCoord0, 4, bgfx::AttribType::Float)
  457. .add(bgfx::Attrib::TexCoord1, 4, bgfx::AttribType::Float)
  458. .add(bgfx::Attrib::TexCoord2, 4, bgfx::AttribType::Float)
  459. .add(bgfx::Attrib::TexCoord3, 4, bgfx::AttribType::Float)
  460. .end();
  461. //initialise the buffer with data for all instances
  462. //Currently we only store a world matrix (16 floats)
  463. const int sizeOfBuffer = 16 * m_totalInstancesCount;
  464. float* instanceData = new float[sizeOfBuffer];
  465. float* data = instanceData;
  466. for (uint16_t ii = 0; ii < m_noofProps; ++ii)
  467. {
  468. Prop& prop = m_props[ii];
  469. const uint32_t numInstances = prop.m_noofInstances;
  470. for (uint32_t jj = 0; jj < numInstances; ++jj)
  471. {
  472. bx::memCopy(data, prop.m_instances[jj].m_world, 16 * sizeof(float) );
  473. data[3] = float(ii); // store the drawcall ID here to avoid creating a separate buffer
  474. data += 16;
  475. }
  476. }
  477. const bgfx::Memory* mem = bgfx::makeRef(instanceData, sizeof(float) * sizeOfBuffer);
  478. //pre occlusion buffer
  479. m_instanceBuffer = bgfx::createVertexBuffer(mem, instanceBufferVertexLayout, BGFX_BUFFER_COMPUTE_READ);
  480. //post occlusion buffer
  481. m_culledInstanceBuffer = bgfx::createDynamicVertexBuffer(4 * m_totalInstancesCount, instanceBufferVertexLayout, BGFX_BUFFER_COMPUTE_WRITE);
  482. }
  483. //we use one "drawcall" per prop to render all its instances
  484. m_indirectBuffer = bgfx::createIndirectBuffer(m_noofProps);
  485. // Create programs from shaders for occlusion pass.
  486. m_programOcclusionPass = loadProgram("vs_gdr_render_occlusion", NULL);
  487. m_programCopyZ = loadProgram("cs_gdr_copy_z", NULL);
  488. m_programDownscaleHiZ = loadProgram("cs_gdr_downscale_hi_z", NULL);
  489. m_programOccludeProps = loadProgram("cs_gdr_occlude_props", NULL);
  490. m_programStreamCompaction = loadProgram("cs_gdr_stream_compaction", NULL);
  491. // Set view RENDER_PASS_HIZ_ID clear state.
  492. bgfx::setViewClear(RENDER_PASS_HIZ_ID
  493. , BGFX_CLEAR_DEPTH
  494. , 0x0
  495. , 1.0f
  496. , 0
  497. );
  498. }
  499. // Setup Main pass
  500. {
  501. // Set view 0 clear state.
  502. bgfx::setViewClear(RENDER_PASS_MAIN_ID
  503. , BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH
  504. , 0x303030ff
  505. , 1.0f
  506. , 0
  507. );
  508. // Create program from shaders.
  509. m_programMainPass = loadProgram("vs_gdr_instanced_indirect_rendering", "fs_gdr_instanced_indirect_rendering");
  510. }
  511. // Create static vertex buffer for all props.
  512. // Calculate how many vertices/indices the master buffers will need.
  513. uint16_t totalNoofVertices = 0;
  514. uint16_t totalNoofIndices = 0;
  515. for (uint16_t i = 0; i < m_noofProps; i++)
  516. {
  517. Prop& prop = m_props[i];
  518. totalNoofVertices += prop.m_noofVertices;
  519. totalNoofIndices += prop.m_noofIndices;
  520. }
  521. // CPU data to fill the master buffers
  522. m_allPropVerticesDataCPU = new PosVertex[totalNoofVertices];
  523. m_allPropIndicesDataCPU = new uint16_t[totalNoofIndices];
  524. m_indirectBufferDataCPU = new uint32_t[m_noofProps * 3];
  525. // Copy data over to the master buffers
  526. PosVertex* propVerticesData = m_allPropVerticesDataCPU;
  527. uint16_t* propIndicesData = m_allPropIndicesDataCPU;
  528. uint16_t vertexBufferOffset = 0;
  529. uint16_t indexBufferOffset = 0;
  530. for (uint16_t i = 0; i < m_noofProps; i++)
  531. {
  532. Prop& prop = m_props[i];
  533. bx::memCopy(propVerticesData, prop.m_vertices, prop.m_noofVertices * sizeof(PosVertex));
  534. bx::memCopy(propIndicesData, prop.m_indices, prop.m_noofIndices * sizeof(uint16_t));
  535. propVerticesData += prop.m_noofVertices;
  536. propIndicesData += prop.m_noofIndices;
  537. m_indirectBufferDataCPU[ i * 3 ] = prop.m_noofIndices;
  538. m_indirectBufferDataCPU[ i * 3 + 1] = indexBufferOffset;
  539. m_indirectBufferDataCPU[ i * 3 + 2] = vertexBufferOffset;
  540. indexBufferOffset += prop.m_noofIndices;
  541. vertexBufferOffset += prop.m_noofVertices;
  542. }
  543. // Create master vertex buffer
  544. m_allPropsVertexbufferHandle = bgfx::createVertexBuffer(
  545. bgfx::makeRef(m_allPropVerticesDataCPU, totalNoofVertices * PosVertex::ms_layout.getStride())
  546. , PosVertex::ms_layout
  547. );
  548. // Create master index buffer.
  549. m_allPropsIndexbufferHandle = bgfx::createIndexBuffer(
  550. bgfx::makeRef(m_allPropIndicesDataCPU, totalNoofIndices * sizeof(uint16_t) )
  551. );
  552. // Create buffer with const drawcall data which will be copied to the indirect buffer later.
  553. m_indirectBufferData = bgfx::createIndexBuffer(
  554. bgfx::makeRef(m_indirectBufferDataCPU, m_noofProps * 3 * sizeof(uint32_t)),
  555. BGFX_BUFFER_COMPUTE_READ | BGFX_BUFFER_INDEX32
  556. );
  557. m_timeOffset = bx::getHPCounter();
  558. m_useIndirect = true;
  559. m_firstFrame = true;
  560. imguiCreate();
  561. }
  562. int shutdown() override
  563. {
  564. imguiDestroy();
  565. // Cleanup.
  566. bgfx::destroy(m_programMainPass);
  567. bgfx::destroy(m_programOcclusionPass);
  568. bgfx::destroy(m_programCopyZ);
  569. bgfx::destroy(m_programDownscaleHiZ);
  570. bgfx::destroy(m_programOccludeProps);
  571. bgfx::destroy(m_programStreamCompaction);
  572. for (uint16_t i = 0; i < m_noofProps; i++)
  573. {
  574. Prop& prop = m_props[i];
  575. bgfx::destroy(prop.m_indexbufferHandle);
  576. bgfx::destroy(prop.m_vertexbufferHandle);
  577. delete[] prop.m_indices;
  578. delete[] prop.m_vertices;
  579. delete[] prop.m_instances;
  580. }
  581. delete[] m_props;
  582. bgfx::destroy(m_hiZDepthBuffer);
  583. bgfx::destroy(m_hiZBuffer);
  584. bgfx::destroy(m_indirectBuffer);
  585. bgfx::destroy(m_indirectBufferData);
  586. bgfx::destroy(m_instanceBoundingBoxes);
  587. bgfx::destroy(m_drawcallInstanceCounts);
  588. bgfx::destroy(m_instancePredicates);
  589. bgfx::destroy(m_instanceBuffer);
  590. bgfx::destroy(m_culledInstanceBuffer);
  591. bgfx::destroy(m_allPropsVertexbufferHandle);
  592. bgfx::destroy(m_allPropsIndexbufferHandle);
  593. bgfx::destroy(s_texOcclusionDepth);
  594. bgfx::destroy(u_inputRTSize);
  595. bgfx::destroy(u_cullingConfig);
  596. bgfx::destroy(u_color);
  597. delete[] m_allPropVerticesDataCPU;
  598. delete[] m_allPropIndicesDataCPU;
  599. delete[] m_indirectBufferDataCPU;
  600. // Shutdown bgfx.
  601. bgfx::shutdown();
  602. return 0;
  603. }
  604. //renders the occluders to a depth buffer
  605. void renderOcclusionBufferPass()
  606. {
  607. // Setup the occlusion pass projection
  608. bx::mtxProj(m_occlusionProj, 60.0f, float(m_hiZwidth) / float(m_hiZheight), 0.1f, 500.0f, bgfx::getCaps()->homogeneousDepth);
  609. bgfx::setViewTransform(RENDER_PASS_HIZ_ID, m_mainView, m_occlusionProj);
  610. bgfx::setViewFrameBuffer(RENDER_PASS_HIZ_ID, m_hiZDepthBuffer);
  611. bgfx::setViewRect(RENDER_PASS_HIZ_ID, 0, 0, uint16_t(m_hiZwidth), uint16_t(m_hiZheight));
  612. const uint16_t instanceStride = sizeof(InstanceData);
  613. // render all instances of the occluder meshes
  614. for (uint16_t i = 0; i < m_noofProps; i++)
  615. {
  616. Prop& prop = m_props[i];
  617. if (prop.m_renderPass & RenderPass::Occlusion)
  618. {
  619. const uint32_t numInstances = prop.m_noofInstances;
  620. // render instances to the occlusion buffer
  621. if (numInstances == bgfx::getAvailInstanceDataBuffer(numInstances, instanceStride))
  622. {
  623. bgfx::InstanceDataBuffer instanceBuffer;
  624. bgfx::allocInstanceDataBuffer(&instanceBuffer, numInstances, instanceStride);
  625. InstanceData *data = (InstanceData *) instanceBuffer.data;
  626. for (uint32_t j = 0; j < numInstances; j++)
  627. {
  628. //we only need the world matrix for the occlusion pass
  629. bx::memCopy(data->m_world, prop.m_instances[j].m_world, sizeof(data->m_world));
  630. data++;
  631. }
  632. // Set vertex and index buffer.
  633. bgfx::setVertexBuffer(0, prop.m_vertexbufferHandle);
  634. bgfx::setIndexBuffer(prop.m_indexbufferHandle);
  635. // Set instance data buffer.
  636. bgfx::setInstanceDataBuffer(&instanceBuffer);
  637. // Set render states.
  638. bgfx::setState(BGFX_STATE_DEFAULT);
  639. // Submit primitive for rendering to view.
  640. bgfx::submit(RENDER_PASS_HIZ_ID, m_programOcclusionPass);
  641. }
  642. }
  643. }
  644. }
  645. // downscale the occluder depth buffer to create a mipmap chain
  646. void renderDownscalePass()
  647. {
  648. uint32_t width = m_hiZwidth;
  649. uint32_t height = m_hiZheight;
  650. // copy mip zero over to the hi Z buffer.
  651. // We can't currently use blit as it requires same format and CopyResource is not exposed.
  652. {
  653. float inputRendertargetSize[4] = { (float)width, (float)height, 0.0f, 0.0f };
  654. bgfx::setUniform(u_inputRTSize, inputRendertargetSize);
  655. bgfx::setTexture(0, s_texOcclusionDepth, getTexture(m_hiZDepthBuffer, 0));
  656. bgfx::setImage(1, getTexture(m_hiZBuffer, 0), 0, bgfx::Access::Write);
  657. bgfx::dispatch(RENDER_PASS_HIZ_DOWNSCALE_ID, m_programCopyZ, width/16, height/16);
  658. }
  659. for (uint8_t lod = 1; lod < m_noofHiZMips; ++lod)
  660. {
  661. float inputRendertargetSize[4] = { (float)width, (float)height, 2.0f, 2.0f };
  662. bgfx::setUniform(u_inputRTSize, inputRendertargetSize);
  663. // down scale mip 1 onwards
  664. width /= 2;
  665. height /= 2;
  666. bgfx::setImage(0, getTexture(m_hiZBuffer, 0), lod - 1, bgfx::Access::Read);
  667. bgfx::setImage(1, getTexture(m_hiZBuffer, 0), lod, bgfx::Access::Write);
  668. bgfx::dispatch(RENDER_PASS_HIZ_DOWNSCALE_ID, m_programDownscaleHiZ, width/16, height/16);
  669. }
  670. }
  671. // perform the occlusion using the mip chain
  672. void renderOccludePropsPass()
  673. {
  674. // run the computer shader to determine visibility of each instance
  675. bgfx::setTexture(0, s_texOcclusionDepth, bgfx::getTexture(m_hiZBuffer, 0) );
  676. bgfx::setBuffer(1, m_instanceBoundingBoxes, bgfx::Access::Read);
  677. bgfx::setBuffer(2, m_drawcallInstanceCounts, bgfx::Access::ReadWrite);
  678. bgfx::setBuffer(3, m_instancePredicates, bgfx::Access::Write);
  679. float inputRendertargetSize[4] = { (float)m_hiZwidth, (float)m_hiZheight, 1.0f/ m_hiZwidth, 1.0f/ m_hiZheight };
  680. bgfx::setUniform(u_inputRTSize, inputRendertargetSize);
  681. // store a rounded-up, power of two instance count for the stream compaction step
  682. float noofInstancesPowOf2 = bx::pow(2.0f, bx::floor(bx::log(m_totalInstancesCount) / bx::log(2.0f) ) + 1.0f);
  683. float cullingConfig[4] =
  684. {
  685. (float)m_totalInstancesCount,
  686. noofInstancesPowOf2,
  687. (float)m_noofHiZMips,
  688. (float)m_noofProps
  689. };
  690. bgfx::setUniform(u_cullingConfig, cullingConfig);
  691. //set the view/projection transforms so that the compute shader can receive the viewProjection matrix automagically
  692. bgfx::setViewTransform(RENDER_PASS_OCCLUDE_PROPS_ID, m_mainView, m_occlusionProj);
  693. uint16_t groupX = bx::max<uint16_t>(m_totalInstancesCount / 64 + 1, 1);
  694. bgfx::dispatch(RENDER_PASS_OCCLUDE_PROPS_ID, m_programOccludeProps, groupX, 1, 1);
  695. // perform stream compaction to remove occluded instances
  696. // the per drawcall data that is constant (noof indices/vertices and offsets to vertex/index buffers)
  697. bgfx::setBuffer(0, m_indirectBufferData, bgfx::Access::Read);
  698. // instance data for all instances (pre culling)
  699. bgfx::setBuffer(1, m_instanceBuffer, bgfx::Access::Read);
  700. // per instance visibility (output of culling pass)
  701. bgfx::setBuffer(2, m_instancePredicates, bgfx::Access::Read);
  702. // how many instances per drawcall
  703. bgfx::setBuffer(3, m_drawcallInstanceCounts, bgfx::Access::ReadWrite);
  704. // drawcall data that will drive drawIndirect
  705. bgfx::setBuffer(4, m_indirectBuffer, bgfx::Access::ReadWrite);
  706. // culled instance data
  707. bgfx::setBuffer(5, m_culledInstanceBuffer, bgfx::Access::Write);
  708. bgfx::setUniform(u_cullingConfig, cullingConfig);
  709. bgfx::dispatch(RENDER_PASS_COMPACT_STREAM_ID, m_programStreamCompaction, 1, 1, 1);
  710. }
  711. // render the unoccluded props to the screen
  712. void renderMainPass()
  713. {
  714. // Set view and projection matrix for view 0.
  715. {
  716. bgfx::setViewTransform(RENDER_PASS_MAIN_ID, m_mainView, m_mainProj);
  717. // Set view 0 default viewport.
  718. bgfx::setViewRect(RENDER_PASS_MAIN_ID, 0, 0, uint16_t(m_width), uint16_t(m_height));
  719. }
  720. // Set render states.
  721. bgfx::setState(BGFX_STATE_DEFAULT);
  722. const uint16_t instanceStride = sizeof(InstanceData);
  723. // Set "material" data (currently a color only)
  724. bgfx::setUniform(u_color, &m_materials[0].m_color, m_noofMaterials);
  725. // We can't use indirect drawing for the first frame because the content of m_drawcallInstanceCounts
  726. // is initially undefined.
  727. if (m_useIndirect && !m_firstFrame)
  728. {
  729. // Set vertex and index buffer.
  730. bgfx::setVertexBuffer(0, m_allPropsVertexbufferHandle);
  731. bgfx::setIndexBuffer( m_allPropsIndexbufferHandle);
  732. // Set instance data buffer.
  733. bgfx::setInstanceDataBuffer(m_culledInstanceBuffer, 0, m_totalInstancesCount );
  734. bgfx::submit(RENDER_PASS_MAIN_ID, m_programMainPass, m_indirectBuffer, 0, m_noofProps);
  735. }
  736. else
  737. {
  738. // render all props using regular instancing
  739. for (uint16_t ii = 0; ii < m_noofProps; ++ii)
  740. {
  741. Prop& prop = m_props[ii];
  742. if (prop.m_renderPass & RenderPass::MainPass)
  743. {
  744. const uint32_t numInstances = prop.m_noofInstances;
  745. if (numInstances == bgfx::getAvailInstanceDataBuffer(numInstances, instanceStride))
  746. {
  747. bgfx::InstanceDataBuffer instanceBuffer;
  748. bgfx::allocInstanceDataBuffer(&instanceBuffer, numInstances, instanceStride);
  749. InstanceData *data = (InstanceData *)instanceBuffer.data;
  750. for (uint32_t jj = 0; jj < numInstances; ++jj)
  751. {
  752. //copy world matrix
  753. bx::memCopy(data->m_world, prop.m_instances[jj].m_world, sizeof(data->m_world) );
  754. //pack the material ID into the world transform
  755. data->m_world[3] = float(prop.m_materialID);
  756. data++;
  757. }
  758. // Set vertex and index buffer.
  759. bgfx::setVertexBuffer(0, prop.m_vertexbufferHandle);
  760. bgfx::setIndexBuffer(prop.m_indexbufferHandle);
  761. // Set instance data buffer.
  762. bgfx::setInstanceDataBuffer(&instanceBuffer);
  763. bgfx::submit(RENDER_PASS_MAIN_ID, m_programMainPass);
  764. }
  765. }
  766. }
  767. }
  768. m_firstFrame = false;
  769. }
  770. bool update() override
  771. {
  772. if (!entry::processEvents(m_width, m_height, m_debug, m_reset, &m_mouseState) )
  773. {
  774. imguiBeginFrame(m_mouseState.m_mx
  775. , m_mouseState.m_my
  776. , (m_mouseState.m_buttons[entry::MouseButton::Left ] ? IMGUI_MBUT_LEFT : 0)
  777. | (m_mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0)
  778. | (m_mouseState.m_buttons[entry::MouseButton::Middle] ? IMGUI_MBUT_MIDDLE : 0)
  779. , m_mouseState.m_mz
  780. , uint16_t(m_width)
  781. , uint16_t(m_height)
  782. );
  783. showExampleDialog(this);
  784. ImGui::SetNextWindowPos(
  785. ImVec2(m_width - m_width / 5.0f - 10.0f, 10.0f)
  786. , ImGuiCond_FirstUseEver
  787. );
  788. ImGui::SetNextWindowSize(
  789. ImVec2(m_width / 5.0f, m_height / 6.0f)
  790. , ImGuiCond_FirstUseEver
  791. );
  792. ImGui::Begin("Settings"
  793. , NULL
  794. , 0
  795. );
  796. ImGui::Checkbox("Use Draw Indirect", &m_useIndirect);
  797. ImGui::End();
  798. imguiEndFrame();
  799. // This dummy draw call is here to make sure that view 0 is cleared
  800. // if no other draw calls are submitted to view 0.
  801. bgfx::touch(0);
  802. int64_t now = bx::getHPCounter();
  803. static int64_t last = now;
  804. const int64_t frameTime = now - last;
  805. last = now;
  806. const double freq = double(bx::getHPFrequency());
  807. const float deltaTimeSec = float(double(frameTime) / freq);
  808. // Camera.
  809. const bool mouseOverGui = ImGui::MouseOverArea();
  810. m_mouse.update(float(m_mouseState.m_mx), float(m_mouseState.m_my), m_mouseState.m_mz, m_width, m_height);
  811. if (!mouseOverGui)
  812. {
  813. if (m_mouseState.m_buttons[entry::MouseButton::Left])
  814. {
  815. m_camera.orbit(m_mouse.m_dx, m_mouse.m_dy);
  816. }
  817. else if (m_mouseState.m_buttons[entry::MouseButton::Right])
  818. {
  819. m_camera.dolly(m_mouse.m_dx + m_mouse.m_dy);
  820. }
  821. else if (0 != m_mouse.m_scroll)
  822. {
  823. m_camera.dolly(float(m_mouse.m_scroll)*0.05f);
  824. }
  825. }
  826. m_camera.update(deltaTimeSec);
  827. // Get renderer capabilities info.
  828. const bgfx::Caps* caps = bgfx::getCaps();
  829. // Check if instancing is supported.
  830. if (0 == (BGFX_CAPS_INSTANCING & caps->supported) )
  831. {
  832. // When instancing is not supported by GPU, implement alternative
  833. // code path that doesn't use instancing.
  834. float time = (float)((bx::getHPCounter() - m_timeOffset) / double(bx::getHPFrequency()));
  835. bool blink = uint32_t(time*3.0f)&1;
  836. bgfx::dbgTextPrintf(0, 0, blink ? 0x1f : 0x01, " Instancing is not supported by GPU. ");
  837. }
  838. else
  839. {
  840. // calculate main view and project matrices as they are typically reused between passes.
  841. m_camera.mtxLookAt(m_mainView);
  842. bx::mtxProj(m_mainProj, 60.0f, float(m_width) / float(m_height), 0.1f, 500.0f, bgfx::getCaps()->homogeneousDepth);
  843. //submit drawcalls for all passes
  844. renderOcclusionBufferPass();
  845. renderDownscalePass();
  846. renderOccludePropsPass();
  847. renderMainPass();
  848. }
  849. // Advance to next frame. Rendering thread will be kicked to
  850. // process submitted rendering primitives.
  851. bgfx::frame();
  852. return true;
  853. }
  854. return false;
  855. }
  856. entry::MouseState m_mouseState;
  857. uint32_t m_width;
  858. uint32_t m_height;
  859. uint32_t m_hiZwidth;
  860. uint32_t m_hiZheight;
  861. uint32_t m_debug;
  862. uint32_t m_reset;
  863. float m_mainView[16];
  864. float m_mainProj[16];
  865. float m_occlusionProj[16];
  866. bgfx::ProgramHandle m_programMainPass;
  867. bgfx::ProgramHandle m_programOcclusionPass;
  868. bgfx::ProgramHandle m_programCopyZ;
  869. bgfx::ProgramHandle m_programDownscaleHiZ;
  870. bgfx::ProgramHandle m_programOccludeProps;
  871. bgfx::ProgramHandle m_programStreamCompaction;
  872. bgfx::FrameBufferHandle m_hiZDepthBuffer;
  873. bgfx::FrameBufferHandle m_hiZBuffer;
  874. bgfx::IndirectBufferHandle m_indirectBuffer;
  875. bgfx::VertexBufferHandle m_allPropsVertexbufferHandle;
  876. bgfx::IndexBufferHandle m_allPropsIndexbufferHandle;
  877. bgfx::IndexBufferHandle m_indirectBufferData;
  878. PosVertex* m_allPropVerticesDataCPU;
  879. uint16_t* m_allPropIndicesDataCPU;
  880. uint32_t* m_indirectBufferDataCPU;
  881. bgfx::DynamicVertexBufferHandle m_instanceBoundingBoxes;
  882. bgfx::DynamicIndexBufferHandle m_drawcallInstanceCounts;
  883. bgfx::DynamicIndexBufferHandle m_instancePredicates;
  884. bgfx::VertexBufferHandle m_instanceBuffer;
  885. bgfx::DynamicVertexBufferHandle m_culledInstanceBuffer;
  886. bgfx::UniformHandle s_texOcclusionDepth;
  887. bgfx::UniformHandle u_inputRTSize;
  888. bgfx::UniformHandle u_cullingConfig;
  889. bgfx::UniformHandle u_color;
  890. Prop* m_props;
  891. Material* m_materials;
  892. uint16_t m_noofProps;
  893. uint16_t m_noofMaterials;
  894. uint16_t m_totalInstancesCount;
  895. static const uint16_t s_maxNoofProps = 10;
  896. static const uint16_t s_maxNoofInstances = 2048;
  897. int64_t m_timeOffset;
  898. uint8_t m_noofHiZMips;
  899. bool m_useIndirect;
  900. bool m_firstFrame;
  901. Camera m_camera;
  902. Mouse m_mouse;
  903. };
  904. } // namespace
  905. ENTRY_IMPLEMENT_MAIN(GPUDrivenRendering, "37-gpudrivenrendering", "GPU-Driven Rendering.");