webgpuSnapshotRendering.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /** @internal */
  2. export class WebGPUSnapshotRendering {
  3. constructor(engine, renderingMode, bundleList) {
  4. this._record = false;
  5. this._play = false;
  6. this._playBundleListIndex = 0;
  7. this._allBundleLists = [];
  8. this._enabled = false;
  9. this._engine = engine;
  10. this._mode = renderingMode;
  11. this._bundleList = bundleList;
  12. }
  13. get enabled() {
  14. return this._enabled;
  15. }
  16. get play() {
  17. return this._play;
  18. }
  19. get record() {
  20. return this._record;
  21. }
  22. set enabled(activate) {
  23. this._allBundleLists.length = 0;
  24. this._record = this._enabled = activate;
  25. this._play = false;
  26. if (activate) {
  27. this._modeSaved = this._mode;
  28. this._mode = 0; // need to reset to standard for the recording pass to avoid some code being bypassed
  29. }
  30. }
  31. get mode() {
  32. return this._mode;
  33. }
  34. set mode(mode) {
  35. if (this._record) {
  36. this._modeSaved = mode;
  37. }
  38. else {
  39. this._mode = mode;
  40. }
  41. }
  42. endRenderPass(currentRenderPass) {
  43. if (!this._record && !this._play) {
  44. // Snapshot rendering mode is not enabled
  45. return false;
  46. }
  47. let bundleList;
  48. if (this._record) {
  49. bundleList = this._bundleList.clone();
  50. this._allBundleLists.push(bundleList);
  51. this._bundleList.reset();
  52. }
  53. else {
  54. // We are playing the snapshot
  55. if (this._playBundleListIndex >= this._allBundleLists.length) {
  56. throw new Error(`Invalid playBundleListIndex! Your snapshot is no longer valid for the current frame, you should recreate a new one. playBundleListIndex=${this._playBundleListIndex}, allBundleLists.length=${this._allBundleLists.length}}`);
  57. }
  58. bundleList = this._allBundleLists[this._playBundleListIndex++];
  59. }
  60. bundleList.run(currentRenderPass);
  61. if (this._mode === 1) {
  62. this._engine._reportDrawCall(bundleList.numDrawCalls);
  63. }
  64. return true;
  65. }
  66. endFrame() {
  67. if (this._record) {
  68. // We stop recording and switch to replay mode for the next frames
  69. this._record = false;
  70. this._play = true;
  71. this._mode = this._modeSaved;
  72. }
  73. this._playBundleListIndex = 0;
  74. }
  75. reset() {
  76. this.enabled = false;
  77. this.enabled = true;
  78. }
  79. }
  80. //# sourceMappingURL=webgpuSnapshotRendering.js.map