Adds new chained struct for device creation to specify cache options.

- Adds isolation key option, DawnNative support, and relevant unit tests.

Bug: dawn:549
Change-Id: I16344581c7956ce8576c0a4c14655fbdb4e15a54
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/81920
Reviewed-by: Shrek Shao <shrekshao@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Loko Kung <lokokung@google.com>
This commit is contained in:
Loko Kung 2022-03-01 22:59:40 +00:00 committed by Dawn LUCI CQ
parent a718456707
commit 44f039d3c2
5 changed files with 66 additions and 2 deletions

View File

@ -167,6 +167,14 @@
{"name": "force disabled toggles", "type": "char", "annotation": "const*const*", "length": "force disabled toggles count"}
]
},
"dawn cache device descriptor" : {
"tags": ["dawn", "native"],
"category": "structure",
"chained": "in",
"members": [
{"name": "isolation key", "type": "char", "annotation": "const*", "length": "strlen", "default": "\"\""}
]
},
"address mode": {
"category": "enum",
"values": [
@ -2401,7 +2409,8 @@
{"value": 1001, "name": "primitive depth clamping state", "tags": ["dawn", "emscripten"]},
{"value": 1002, "name": "dawn toggles device descriptor", "tags": ["dawn", "native"]},
{"value": 1003, "name": "dawn encoder internal usage descriptor", "tags": ["dawn"]},
{"value": 1004, "name": "dawn instance descriptor", "tags": ["dawn", "native"]}
{"value": 1004, "name": "dawn instance descriptor", "tags": ["dawn", "native"]},
{"value": 1005, "name": "dawn cache device descriptor", "tags": ["dawn", "native"]}
]
},
"texture": {

View File

@ -6,6 +6,8 @@ when the WebGPU implementation is `dawn_native`.
Additional functionality:
- `wgpu::DawnTogglesDeviceDescriptor` may be chained on `wgpu::DeviceDescriptor` on device creation to enable Dawn-specific toggles on the device.
- `wgpu::DawnCacheDeviceDescriptor` may be chained on `wgpu::DeviceDescriptor` on device creation to enable cache options such as isolation keys.
- Synchronous `adapter.CreateDevice(const wgpu::DeviceDescriptor*)` may be called.
Notes:

View File

@ -184,6 +184,12 @@ namespace dawn::native {
}
ApplyFeatures(descriptor);
const DawnCacheDeviceDescriptor* cacheDesc = nullptr;
FindInChain(descriptor->nextInChain, &cacheDesc);
if (cacheDesc != nullptr) {
mCacheIsolationKey = cacheDesc->isolationKey;
}
if (descriptor->requiredLimits != nullptr) {
mLimits.v1 = ReifyDefaultLimits(descriptor->requiredLimits->limits);
} else {
@ -1738,6 +1744,10 @@ namespace dawn::native {
return PipelineCompatibilityToken(mNextPipelineCompatibilityToken++);
}
const std::string& DeviceBase::GetCacheIsolationKey() const {
return mCacheIsolationKey;
}
const std::string& DeviceBase::GetLabel() const {
return mLabel;
}

View File

@ -366,6 +366,7 @@ namespace dawn::native {
PipelineCompatibilityToken GetNextPipelineCompatibilityToken();
const std::string& GetCacheIsolationKey() const;
const std::string& GetLabel() const;
void APISetLabel(const char* label);
void APIDestroy();
@ -540,6 +541,7 @@ namespace dawn::native {
std::unique_ptr<CallbackTaskManager> mCallbackTaskManager;
std::unique_ptr<dawn::platform::WorkerTaskPool> mWorkerTaskPool;
std::string mLabel;
std::string mCacheIsolationKey = "";
};
} // namespace dawn::native

View File

@ -14,6 +14,8 @@
#include "dawn/dawn_proc.h"
#include "dawn/native/DawnNative.h"
#include "dawn/native/Device.h"
#include "dawn/native/dawn_platform.h"
#include "dawn/tests/MockCallback.h"
#include "dawn/utils/SystemUtils.h"
#include "dawn/utils/WGPUHelpers.h"
@ -24,7 +26,7 @@ namespace {
using namespace testing;
class DeviceCreationTest : public testing::Test {
class DeviceCreationTest : public Test {
protected:
void SetUp() override {
dawnProcSetProcs(&dawn::native::GetProcs());
@ -83,6 +85,45 @@ namespace {
EXPECT_THAT(toggles, testing::Contains(testing::StrEq(toggle)));
}
TEST_F(DeviceCreationTest, CreateDeviceWithCacheSuccess) {
// Default device descriptor should have an empty cache isolation key.
{
wgpu::DeviceDescriptor desc = {};
wgpu::Device device = adapter.CreateDevice(&desc);
EXPECT_NE(device, nullptr);
EXPECT_THAT(dawn::native::FromAPI(device.Get())->GetCacheIsolationKey(),
testing::StrEq(""));
}
// Device descriptor with empty cache descriptor should have an empty cache isolation key.
{
wgpu::DeviceDescriptor desc = {};
wgpu::DawnCacheDeviceDescriptor cacheDesc = {};
desc.nextInChain = &cacheDesc;
wgpu::Device device = adapter.CreateDevice(&desc);
EXPECT_NE(device, nullptr);
EXPECT_THAT(dawn::native::FromAPI(device.Get())->GetCacheIsolationKey(),
testing::StrEq(""));
}
// Specified cache isolation key should be retained.
{
wgpu::DeviceDescriptor desc = {};
wgpu::DawnCacheDeviceDescriptor cacheDesc = {};
desc.nextInChain = &cacheDesc;
const char* isolationKey = "isolation key";
cacheDesc.isolationKey = isolationKey;
wgpu::Device device = adapter.CreateDevice(&desc);
EXPECT_NE(device, nullptr);
EXPECT_THAT(dawn::native::FromAPI(device.Get())->GetCacheIsolationKey(),
testing::StrEq(isolationKey));
}
}
// Test successful call to RequestDevice with descriptor
TEST_F(DeviceCreationTest, RequestDeviceSuccess) {
WGPUDevice cDevice;