@@ -292,7 +292,22 @@ void WebGPUDriver::endFrame(uint32_t frameId) {
292
292
void WebGPUDriver::flush (int ) {
293
293
}
294
294
295
- void WebGPUDriver::finish (int ) {
295
+ void WebGPUDriver::finish (int /* dummy */ ) {
296
+ if (mCommandEncoder != nullptr ) {
297
+ // submit the command buffer thus far...
298
+ assert_invariant (mRenderPassEncoder == nullptr );
299
+ wgpu::CommandBufferDescriptor commandBufferDescriptor{
300
+ .label = " command_buffer" ,
301
+ };
302
+ mCommandBuffer = mCommandEncoder .Finish (&commandBufferDescriptor);
303
+ assert_invariant (mCommandBuffer );
304
+ mQueue .Submit (1 , &mCommandBuffer );
305
+ mCommandBuffer = nullptr ;
306
+ // create a new command buffer encoder to continue recording the next command for frame...
307
+ wgpu::CommandEncoderDescriptor commandEncoderDescriptor = { .label = " command_encoder" };
308
+ mCommandEncoder = mDevice .CreateCommandEncoder (&commandEncoderDescriptor);
309
+ assert_invariant (mCommandEncoder );
310
+ }
296
311
}
297
312
298
313
void WebGPUDriver::destroyRenderPrimitive (Handle<HwRenderPrimitive> rph) {
@@ -746,12 +761,7 @@ void WebGPUDriver::compilePrograms(CompilerPriorityQueue priority,
746
761
}
747
762
748
763
void WebGPUDriver::beginRenderPass (Handle<HwRenderTarget> rth, const RenderPassParams& params) {
749
- wgpu::CommandEncoderDescriptor commandEncoderDescriptor = {
750
- .label = " command_encoder"
751
- };
752
- mCommandEncoder = mDevice .CreateCommandEncoder (&commandEncoderDescriptor);
753
764
assert_invariant (mCommandEncoder );
754
-
755
765
// TODO: Remove this code once WebGPU pipeline is implemented
756
766
static float red = 1 .0f ;
757
767
if (red - 0.01 > 0 ) {
@@ -781,14 +791,9 @@ void WebGPUDriver::beginRenderPass(Handle<HwRenderTarget> rth, const RenderPassP
781
791
params.viewport .width , params.viewport .height , params.depthRange .near , params.depthRange .far );
782
792
}
783
793
784
- void WebGPUDriver::endRenderPass (int ) {
794
+ void WebGPUDriver::endRenderPass (int /* dummy */ ) {
785
795
mRenderPassEncoder .End ();
786
796
mRenderPassEncoder = nullptr ;
787
- wgpu::CommandBufferDescriptor commandBufferDescriptor {
788
- .label = " command_buffer" ,
789
- };
790
- mCommandBuffer = mCommandEncoder .Finish (&commandBufferDescriptor);
791
- assert_invariant (mCommandBuffer );
792
797
}
793
798
794
799
void WebGPUDriver::nextSubpass (int ) {
@@ -803,9 +808,19 @@ void WebGPUDriver::makeCurrent(Handle<HwSwapChain> drawSch, Handle<HwSwapChain>
803
808
wgpu::Extent2D surfaceSize = mPlatform .getSurfaceExtent (mNativeWindow );
804
809
mTextureView = mSwapChain ->getCurrentSurfaceTextureView (surfaceSize);
805
810
assert_invariant (mTextureView );
811
+ wgpu::CommandEncoderDescriptor commandEncoderDescriptor = {
812
+ .label = " command_encoder"
813
+ };
814
+ mCommandEncoder = mDevice .CreateCommandEncoder (&commandEncoderDescriptor);
815
+ assert_invariant (mCommandEncoder );
806
816
}
807
817
808
818
void WebGPUDriver::commit (Handle<HwSwapChain> sch) {
819
+ wgpu::CommandBufferDescriptor commandBufferDescriptor{
820
+ .label = " command_buffer" ,
821
+ };
822
+ mCommandBuffer = mCommandEncoder .Finish (&commandBufferDescriptor);
823
+ assert_invariant (mCommandBuffer );
809
824
mCommandEncoder = nullptr ;
810
825
mQueue .Submit (1 , &mCommandBuffer );
811
826
mCommandBuffer = nullptr ;
0 commit comments