Skip initializing timestamp resolve buffer when its full range is covered

The zero initialization of the timestamp resolve buffer can be skipped
before we call the internal compute shader to convert timestamps to
nanoseconds as in the internal shader we can ensure we won't read any
uninitialized data and the full range of the buffer will be filled with
valid data.

Bug: dawn:1250
Change-Id: Iddc9d59021e92e9340c0dcb14ebaa335b0967cdf
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/155341
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/dawn/native/CommandEncoder.cpp b/src/dawn/native/CommandEncoder.cpp
index bfff1e9..675920f 100644
--- a/src/dawn/native/CommandEncoder.cpp
+++ b/src/dawn/native/CommandEncoder.cpp
@@ -716,6 +716,13 @@
 
     DAWN_TRY(device->GetQueue()->WriteBuffer(paramsBuffer.Get(), 0, &params, sizeof(params)));
 
+    // In the internal shader to convert timestamps to nanoseconds, we can ensure no uninitialized
+    // data will be read and the full buffer range will be filled with valid data.
+    if (!destination->IsDataInitialized() &&
+        destination->IsFullBufferRange(firstQuery, sizeof(uint64_t) * queryCount)) {
+        destination->SetIsDataInitialized();
+    }
+
     return EncodeConvertTimestampsToNanoseconds(encoder, destination, availabilityBuffer.Get(),
                                                 paramsBuffer.Get());
 }