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:
parent
a718456707
commit
44f039d3c2
11
dawn.json
11
dawn.json
|
@ -167,6 +167,14 @@
|
||||||
{"name": "force disabled toggles", "type": "char", "annotation": "const*const*", "length": "force disabled toggles count"}
|
{"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": {
|
"address mode": {
|
||||||
"category": "enum",
|
"category": "enum",
|
||||||
"values": [
|
"values": [
|
||||||
|
@ -2401,7 +2409,8 @@
|
||||||
{"value": 1001, "name": "primitive depth clamping state", "tags": ["dawn", "emscripten"]},
|
{"value": 1001, "name": "primitive depth clamping state", "tags": ["dawn", "emscripten"]},
|
||||||
{"value": 1002, "name": "dawn toggles device descriptor", "tags": ["dawn", "native"]},
|
{"value": 1002, "name": "dawn toggles device descriptor", "tags": ["dawn", "native"]},
|
||||||
{"value": 1003, "name": "dawn encoder internal usage descriptor", "tags": ["dawn"]},
|
{"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": {
|
"texture": {
|
||||||
|
|
|
@ -6,6 +6,8 @@ when the WebGPU implementation is `dawn_native`.
|
||||||
Additional functionality:
|
Additional functionality:
|
||||||
- `wgpu::DawnTogglesDeviceDescriptor` may be chained on `wgpu::DeviceDescriptor` on device creation to enable Dawn-specific toggles on the device.
|
- `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.
|
- Synchronous `adapter.CreateDevice(const wgpu::DeviceDescriptor*)` may be called.
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
|
|
|
@ -184,6 +184,12 @@ namespace dawn::native {
|
||||||
}
|
}
|
||||||
ApplyFeatures(descriptor);
|
ApplyFeatures(descriptor);
|
||||||
|
|
||||||
|
const DawnCacheDeviceDescriptor* cacheDesc = nullptr;
|
||||||
|
FindInChain(descriptor->nextInChain, &cacheDesc);
|
||||||
|
if (cacheDesc != nullptr) {
|
||||||
|
mCacheIsolationKey = cacheDesc->isolationKey;
|
||||||
|
}
|
||||||
|
|
||||||
if (descriptor->requiredLimits != nullptr) {
|
if (descriptor->requiredLimits != nullptr) {
|
||||||
mLimits.v1 = ReifyDefaultLimits(descriptor->requiredLimits->limits);
|
mLimits.v1 = ReifyDefaultLimits(descriptor->requiredLimits->limits);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1738,6 +1744,10 @@ namespace dawn::native {
|
||||||
return PipelineCompatibilityToken(mNextPipelineCompatibilityToken++);
|
return PipelineCompatibilityToken(mNextPipelineCompatibilityToken++);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string& DeviceBase::GetCacheIsolationKey() const {
|
||||||
|
return mCacheIsolationKey;
|
||||||
|
}
|
||||||
|
|
||||||
const std::string& DeviceBase::GetLabel() const {
|
const std::string& DeviceBase::GetLabel() const {
|
||||||
return mLabel;
|
return mLabel;
|
||||||
}
|
}
|
||||||
|
|
|
@ -366,6 +366,7 @@ namespace dawn::native {
|
||||||
|
|
||||||
PipelineCompatibilityToken GetNextPipelineCompatibilityToken();
|
PipelineCompatibilityToken GetNextPipelineCompatibilityToken();
|
||||||
|
|
||||||
|
const std::string& GetCacheIsolationKey() const;
|
||||||
const std::string& GetLabel() const;
|
const std::string& GetLabel() const;
|
||||||
void APISetLabel(const char* label);
|
void APISetLabel(const char* label);
|
||||||
void APIDestroy();
|
void APIDestroy();
|
||||||
|
@ -540,6 +541,7 @@ namespace dawn::native {
|
||||||
std::unique_ptr<CallbackTaskManager> mCallbackTaskManager;
|
std::unique_ptr<CallbackTaskManager> mCallbackTaskManager;
|
||||||
std::unique_ptr<dawn::platform::WorkerTaskPool> mWorkerTaskPool;
|
std::unique_ptr<dawn::platform::WorkerTaskPool> mWorkerTaskPool;
|
||||||
std::string mLabel;
|
std::string mLabel;
|
||||||
|
std::string mCacheIsolationKey = "";
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dawn::native
|
} // namespace dawn::native
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
|
|
||||||
#include "dawn/dawn_proc.h"
|
#include "dawn/dawn_proc.h"
|
||||||
#include "dawn/native/DawnNative.h"
|
#include "dawn/native/DawnNative.h"
|
||||||
|
#include "dawn/native/Device.h"
|
||||||
|
#include "dawn/native/dawn_platform.h"
|
||||||
#include "dawn/tests/MockCallback.h"
|
#include "dawn/tests/MockCallback.h"
|
||||||
#include "dawn/utils/SystemUtils.h"
|
#include "dawn/utils/SystemUtils.h"
|
||||||
#include "dawn/utils/WGPUHelpers.h"
|
#include "dawn/utils/WGPUHelpers.h"
|
||||||
|
@ -24,7 +26,7 @@ namespace {
|
||||||
|
|
||||||
using namespace testing;
|
using namespace testing;
|
||||||
|
|
||||||
class DeviceCreationTest : public testing::Test {
|
class DeviceCreationTest : public Test {
|
||||||
protected:
|
protected:
|
||||||
void SetUp() override {
|
void SetUp() override {
|
||||||
dawnProcSetProcs(&dawn::native::GetProcs());
|
dawnProcSetProcs(&dawn::native::GetProcs());
|
||||||
|
@ -83,6 +85,45 @@ namespace {
|
||||||
EXPECT_THAT(toggles, testing::Contains(testing::StrEq(toggle)));
|
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 successful call to RequestDevice with descriptor
|
||||||
TEST_F(DeviceCreationTest, RequestDeviceSuccess) {
|
TEST_F(DeviceCreationTest, RequestDeviceSuccess) {
|
||||||
WGPUDevice cDevice;
|
WGPUDevice cDevice;
|
||||||
|
|
Loading…
Reference in New Issue