Fix query index of availability in timestamp shader

Currently we use offset to calculate the index of the queries in
timestamp compute shader, which is incorrect. The offset is the buffer
offset where we start to write the query results, and has nothing to
do with query index. In the query availability detection, the query
index should be based on the parameter firstQuery.

Add new test for resolving a timestamp query twice to the same
destination buffer with potentially overlapping ranges.

Bug: dawn:434
Change-Id: I2b5c5b192cf5d987ac48187e8240a25937957f51
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/50760
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Hao Li <hao.x.li@intel.com>
This commit is contained in:
Hao Li
2021-05-18 01:13:08 +00:00
committed by Commit Bot service account
parent 21ce5d2965
commit 880a3d6311
5 changed files with 82 additions and 20 deletions

View File

@@ -424,6 +424,7 @@ namespace dawn_native {
MaybeError EncodeTimestampsToNanosecondsConversion(CommandEncoder* encoder,
QuerySetBase* querySet,
uint32_t firstQuery,
uint32_t queryCount,
BufferBase* destination,
uint64_t destinationOffset) {
@@ -447,7 +448,8 @@ namespace dawn_native {
availability.size() * sizeof(uint32_t)));
// Timestamp params uniform buffer
TimestampParams params = {queryCount, static_cast<uint32_t>(destinationOffset),
TimestampParams params = {firstQuery, queryCount,
static_cast<uint32_t>(destinationOffset),
device->GetTimestampPeriodInNS()};
BufferDescriptor parmsDesc = {};
@@ -882,8 +884,8 @@ namespace dawn_native {
// Encode internal compute pipeline for timestamp query
if (querySet->GetQueryType() == wgpu::QueryType::Timestamp) {
DAWN_TRY(EncodeTimestampsToNanosecondsConversion(this, querySet, queryCount, destination,
destinationOffset));
DAWN_TRY(EncodeTimestampsToNanosecondsConversion(
this, querySet, firstQuery, queryCount, destination, destinationOffset));
}
return {};

View File

@@ -28,9 +28,10 @@ namespace dawn_native {
namespace {
// Assert the offsets in dawn_native::TimestampParams are same with the ones in the shader
static_assert(offsetof(dawn_native::TimestampParams, count) == 0, "");
static_assert(offsetof(dawn_native::TimestampParams, offset) == 4, "");
static_assert(offsetof(dawn_native::TimestampParams, period) == 8, "");
static_assert(offsetof(dawn_native::TimestampParams, first) == 0, "");
static_assert(offsetof(dawn_native::TimestampParams, count) == 4, "");
static_assert(offsetof(dawn_native::TimestampParams, offset) == 8, "");
static_assert(offsetof(dawn_native::TimestampParams, period) == 12, "");
static const char sConvertTimestampsToNanoseconds[] = R"(
struct Timestamp {
@@ -47,6 +48,7 @@ namespace dawn_native {
};
[[block]] struct TimestampParams {
first : u32;
count : u32;
offset : u32;
period : f32;
@@ -70,7 +72,7 @@ namespace dawn_native {
var timestamp : Timestamp = timestamps.t[index];
// Return 0 for the unavailable value.
if (availability.v[index] == 0u) {
if (availability.v[GlobalInvocationID.x + params.first] == 0u) {
timestamps.t[index].low = 0u;
timestamps.t[index].high = 0u;
return;

View File

@@ -24,6 +24,7 @@ namespace dawn_native {
class CommandEncoder;
struct TimestampParams {
uint32_t first;
uint32_t count;
uint32_t offset;
float period;