Disallow timestamp query creation if disallow_unsafe_apis

Bug: chromium:1226078
Change-Id: I567522c5562d8cba616ef4315c91a0420d5146d6
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/59044
Reviewed-by: Hao Li <hao.x.li@intel.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
Austin Eng 2021-07-22 18:13:00 +00:00 committed by Dawn LUCI CQ
parent f844ff071c
commit 01ceccb1eb
3 changed files with 26 additions and 0 deletions

View File

@ -94,6 +94,12 @@ namespace dawn_native {
return DAWN_VALIDATION_ERROR("The timestamp query feature is not supported");
}
if (device->IsToggleEnabled(Toggle::DisallowUnsafeAPIs)) {
return DAWN_VALIDATION_ERROR(
"The timestamp query is disallowed because it may expose precise timing "
"information");
}
if (descriptor->pipelineStatisticsCount != 0) {
return DAWN_VALIDATION_ERROR(
"The pipeline statistics should not be set if query type is Timestamp");

View File

@ -227,6 +227,7 @@ class TimestampQueryValidationTest : public QuerySetValidationTest {
WGPUDevice CreateTestDevice() override {
dawn_native::DeviceDescriptor descriptor;
descriptor.requiredExtensions.push_back("timestamp_query");
descriptor.forceDisabledToggles.push_back("disallow_unsafe_apis");
return adapter.CreateDevice(&descriptor);
}
};

View File

@ -191,6 +191,7 @@ class UnsafeQueryAPIValidationTest : public ValidationTest {
WGPUDevice CreateTestDevice() override {
dawn_native::DeviceDescriptor descriptor;
descriptor.requiredExtensions.push_back("pipeline_statistics_query");
descriptor.requiredExtensions.push_back("timestamp_query");
descriptor.forceEnabledToggles.push_back("disallow_unsafe_apis");
return adapter.CreateDevice(&descriptor);
}
@ -217,3 +218,21 @@ TEST_F(UnsafeQueryAPIValidationTest, PipelineStatisticsDisallowed) {
ASSERT_DEVICE_ERROR(device.CreateQuerySet(&descriptor));
}
}
// Check timestamp queries are disallowed.
TEST_F(UnsafeQueryAPIValidationTest, TimestampQueryDisallowed) {
wgpu::QuerySetDescriptor descriptor;
descriptor.count = 1;
// Control case: occlusion query creation is allowed.
{
descriptor.type = wgpu::QueryType::Occlusion;
device.CreateQuerySet(&descriptor);
}
// Error case: timestamp query creation is disallowed.
{
descriptor.type = wgpu::QueryType::Timestamp;
ASSERT_DEVICE_ERROR(device.CreateQuerySet(&descriptor));
}
}